http://mirrors.163.com/centos/7.8.2003/
[root@k8s-m ~]# sed -i 's/enforcing/disabled/' /etc/selinux/config [root@k8s-m ~]# setenforce 0
[root@k8s-m ~]# swapoff -a [root@k8s-m ~]# vim /etc/fstab
[root@k8s-m ~]# iptables -F [root@k8s-m ~]# iptables -Z [root@k8s-m ~]# iptables -X [root@k8s-m ~]# iptables-save [root@k8s-m ~]# systemctl stop firewalld [root@k8s-m ~]# systemctl disable firewalld
[root@k8s-m ~]# cat > /etc/sysctl.d/k8s.conf << EOF net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF [root@k8s-m ~]# sysctl --system
[root@k8s-m ~]# hostnamectl set-hostname k8s-master [root@k8s-m ~]# cat >> /etc/hosts << EOF 192.168.X.61 k8s-master 192.168.X.62 k8s-node1 192.168.X.63 k8s-node2 EOF
[root@k8s-m ~]# yum install ntpdate -y [root@k8s-m ~]# ntpdate time.windows.com
(1)下載Docker的REPO文件並安裝、設置、校驗node
~]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo ~]# yum -y install docker-ce-18.06.1.ce-3.el7 ~]# systemctl enable docker && systemctl start docker ~]# docker --version
(2)添加阿里雲的鏡像文件實現加速(需重啓Docker服務)linux
~]# cat > /etc/docker/daemon.json << EOF { "registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"] } EOF ~]# systemctl restart docker
(3)下載kubernetes的REPO文件並安裝組件git
~]# cat > /etc/yum.repos.d/kubernetes.repo << EOF [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF
(4)安裝k8s組件github
~]# yum install -y kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0 ~]# systemctl enable kubelet
[root@k8s-m ~] kubeadm init \ --apiserver-advertise-address=192.168.X.61 \ --image-repository registry.aliyuncs.com/google_containers \ --kubernetes-version v1.18.0 \ --service-cidr=10.96.0.0/12 \ --pod-network-cidr=10.244.0.0/16 \ --ignore-preflight-errors=all
[root@k8s-m ~] mkdir -p $HOME/.kube [root@k8s-m ~] sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config [root@k8s-m ~] sudo chown $(id -u):$(id -g) $HOME/.kube/config [root@k8s-m ~] kubectl get nodes
[root@k8s-node ~] kubeadm join 192.168.X.61:6443 --token esce21.q6hetwm8si29qxwn \ --discovery-token-ca-cert-hash sha256:00603a05805807501d7181c3d60b478788408cfe6cedefedb1f97569708be9c5
默認token有效期爲24小時,當過時以後,該token就不可用了。這時就須要從新建立token,操做以下docker
[root@k8s-m ~] kubeadm token create [root@k8s-m ~] kubeadm token list [root@k8s-m ~] openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //' 63bca849e0e01691ae14eab449570284f0c3ddeea590f8da988c07fe2729e924 [root@k8s-m ~] kubeadm join 192.168.31.61:6443 --token nuja6n.o3jrhsffiqs9swnu --discovery-token-ca-cert-hash sha256:63bca849e0e01691ae14eab449570284f0c3ddeea590f8da988c07fe2729e924
或者用如下命令json
kubeadm token create --print-join-command
注意:只須要部署下面其中一個,推薦Calicovim
Calico是一個純三層的數據中心網絡方案,Calico支持普遍的平臺,包括Kubernetes、OpenStack等。Calico 在每個計算節點利用 Linux Kernel 實現了一個高效的虛擬路由器( vRouter) 來負責數據轉發,而每一個 vRouter 經過 BGP 協議負責把本身上運行的 workload 的路由信息向整個 Calico 網絡內傳播。此外,Calico 項目還實現了 Kubernetes 網絡策略,提供ACL功能。windows
wget https://docs.projectcalico.org/manifests/calico.yaml
下載完後還須要修改裏面配置項:centos
修改完後應用清單:api
[root@k8s-m ~] kubectl apply -f calico.yaml [root@k8s-m ~] kubectl get pods -n kube-system
Flannel是CoreOS維護的一個網絡組件,Flannel爲每一個Pod提供全局惟一的IP,Flannel使用ETCD來存儲Pod子網與Node IP之間的關係。flanneld守護進程在每臺主機上運行,並負責維護ETCD信息和路由數據包。
[root@k8s-m ~] wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml [root@k8s-m ~] sed -i -r "s#quay.io/coreos/flannel:.*-amd64#81286980/flannel:v0.11.0-amd64#g" kube-flannel.yml
臨時啓動一個Pod驗證 [root@k8s-m ~] kubectl run dns-test -it --rm --image=busybox:1.28.4 -- sh
[root@k8s-m ~] wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.3/aio/deploy/recommended.yaml
默認Dashboard只能集羣內部訪問,修改Service爲NodePort類型,暴露到外部:
kind: Service apiVersion: v1 metadata: labels: k8s-app: kubernetes-dashboard name: kubernetes-dashboard namespace: kubernetes-dashboard spec: ports: - port: 443 targetPort: 8443 nodePort: 30001 selector: k8s-app: kubernetes-dashboard type: NodePort
訪問地址:https://NodeIP:30001
建立service account並綁定默認cluster-admin管理員集羣角色:
[root@k8s-m ~] kubectl create serviceaccount dashboard-admin -n kube-system [root@k8s-m ~] kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin [root@k8s-m ~] kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')
使用輸出的token登陸Dashboard