开始安装

  1. yum install kubelet kubeadm kubectl -y
  2. systemctl enable kubelet

部署master

  1. kubeadm init \
  2. --image-repository registry.aliyuncs.com/google_containers \
  3. --kubernetes-version v1.20.2 \
  4. --service-cidr 10.96.0.0/12 --apiserver-advertise-address 192.168.0.107 \
  5. --pod-network-cidr=10.244.0.0/16

按要求设置

  1. mkdir -p $HOME/.kube
  2. sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  3. sudo chown $(id -u):$(id -g) $HOME/.kube/config

部署 node 节点

  1. kubeadm join 192.168.0.107:6443 --token 2blkrw.m4z0v4uugtog0kta \
  2. --discovery-token-ca-cert-hash sha256:5909278590754fbef586e8e85b470222f1c23253de8ba968dcf03da9d0bc24e3

token 的有效时间为 24 小时,因此下次得重新获取

  1. kubeadm token create --print-join-command

配置 CNI 网络组件

  1. wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
  2. kubectl apply -f kube-flannel.yml

测试查看

  1. kubectl get pods -n kube-system
  2. kubectl get nodes

测试集群

  1. kubectl create deployment nginx --image=nginx
  2. kubectl get pod
  3. kubectl expose deployment nginx --port=80 --type=NodePort
  4. # 成功运行
  5. kubectl get pod, svc