686 字
3 分钟
安装 network pod: flannel
安装 network pod: flannel
网络组件用以在 pod 间进行通信,再此之前,我们会发现 coredns 组件处于 Pending 状态。我们使用网络组件 flannel 来确保 coredns 的正常运行。
$ kubectl get pods --all-namespacesNAMESPACE NAME READY STATUS RESTARTS AGEkube-system coredns-5644d7b6d9-8l2gv 0/1 Pending 0 56mkube-system coredns-5644d7b6d9-l8zv5 0/1 Pending 0 56mkube-system etcd-shanyue 1/1 Running 0 55mkube-system kube-apiserver-shanyue 1/1 Running 0 55mkube-system kube-controller-manager-shanyue 1/1 Running 0 55mkube-system kube-proxy-5drlg 1/1 Running 0 56mkube-system kube-scheduler-shanyue 1/1 Running 0 55m在安装网络组件要确保路是通的,使用 sysctl 设置内核变量 net.bridge.bridge-nf-call-iptables 为1
$ sysctl net.bridge.bridge-nf-call-iptables=1
$ kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/2140ac876ef134e0ed5af15c65e414cf26827915/Documentation/kube-flannel.ymlpodsecuritypolicy.policy/psp.flannel.unprivileged createdclusterrole.rbac.authorization.k8s.io/flannel createdclusterrolebinding.rbac.authorization.k8s.io/flannel createdserviceaccount/flannel createdconfigmap/kube-flannel-cfg createddaemonset.apps/kube-flannel-ds-amd64 createddaemonset.apps/kube-flannel-ds-arm64 createddaemonset.apps/kube-flannel-ds-arm createddaemonset.apps/kube-flannel-ds-ppc64le createddaemonset.apps/kube-flannel-ds-s390x created此时,再次查看集群中所有的 pod 状态,此时 coredn 变为正常状态,且多了 kube-flannel-ds-amd64 这个 pod。
$ kubectl get pods --all-namespacesNAMESPACE NAME READY STATUS RESTARTS AGEkube-system coredns-5644d7b6d9-8l2gv 1/1 Running 0 136mkube-system coredns-5644d7b6d9-l8zv5 1/1 Running 0 136mkube-system etcd-shanyue 1/1 Running 0 136mkube-system kube-apiserver-shanyue 1/1 Running 0 135mkube-system kube-controller-manager-shanyue 1/1 Running 0 136mkube-system kube-flannel-ds-amd64-pmlnw 1/1 Running 0 9m23skube-system kube-proxy-5drlg 1/1 Running 0 136mkube-system kube-scheduler-shanyue 1/1 Running 0 136m添加 worker node
在添加 worker node 时,需要在子节点也进行 docker 以及 kubeadm 的安装,按照以上章节步骤进行安装。
安装之后根据以上关于搭建主节点章节的输出指示,使用 kubeadm join 加入集群之中:
$ kubeadm join 172.17.68.39:6443 --token qq8hbl.4utma949mu0p47v4 \ --discovery-token-ca-cert-hash sha256:cce6cd7ec86cf4cd65215bea554f98c786783720b19262533cd98656ac6eb15e[preflight] Running pre-flight checks [WARNING Service-Docker]: docker service is not enabled, please run 'systemctl enable docker.service' [WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'[preflight] Reading configuration from the cluster...[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'[kubelet-start] Downloading configuration for the kubelet from the "kubelet-config-1.16" ConfigMap in the kube-system namespace[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"[kubelet-start] Activating the kubelet service[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...
This node has joined the cluster:* Certificate signing request was sent to apiserver and a response was received.* The Kubelet was informed of the new secure connection details.
Run 'kubectl get nodes' on the control-plane to see this node join the cluster.kubeadm join 有两个关键的参数: token 与 hash。如果你已经丢失了新建 master node 时的输出 kubeadm join 信息怎么办?此时可以通过以下命令来获取
# 以下操作在 master node# kubeadm join <control-plane-host>:<control-plane-port> --token <token> --discovery-token-ca-cert-hash sha256:<hash>
# 获取 token$ kubectl token list
# 获取 hash$ openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'安装完之后,再次打印节点信息
$ kubectl get nodesNAME STATUS ROLES AGE VERSIONshanyue Ready master 17m v1.16.0shuifeng Ready <none> 15m v1.16.0
$ kubectl get pods --all-namespacesNAMESPACE NAME READY STATUS RESTARTS AGEkube-system coredns-5644d7b6d9-845lr 1/1 Running 0 24mkube-system coredns-5644d7b6d9-k6dqm 1/1 Running 0 24mkube-system etcd-shanyue 1/1 Running 0 23mkube-system kube-apiserver-shanyue 1/1 Running 0 23mkube-system kube-controller-manager-shanyue 1/1 Running 0 23mkube-system kube-flannel-ds-amd64-tdvbs 1/1 Running 0 21mkube-system kube-flannel-ds-amd64-vtrnh 1/1 Running 0 21mkube-system kube-proxy-k46l2 1/1 Running 0 24mkube-system kube-proxy-rhrrg 1/1 Running 0 22mkube-system kube-scheduler-shanyue 1/1 Running 0 23m至此,一个拥有 master node 与 worker node 的 kubernetes 集群就搭建完成了。
安装 network pod: flannel
https://blog.zhequtao.com/posts/k8s/install-worker-node/