CentOS搭建k8s集群(4)—添加工作节点

1、在node1和node2执行
kubeadm join 192.168.101.1:6443 --token mu949z.xkhkw4tq7t79z4v6 \
--discovery-token-ca-cert-hash sha256:0a381d7f750bda8d639b7132bf4db942710d2042b2cef0c6ffe6aa49a4603f5d \
--ignore-preflight-errors=Swap

2、返回
W0713 04:55:55.810886 12707 join.go:346] [preflight] WARNING: JoinControlPane.controlPlane settings will be ignored when control-plane flag is not set.
[preflight] Running pre-flight checks
[WARNING Swap]: running with swap on is not supported. Please disable swap
error execution phase preflight: couldn't validate the identity of the API Server: could not find a JWS signature in the cluster-info ConfigMap for token ID "mu949z"
To see the stack trace of this error execute with --v=5 or higher

3、时间太长token过期了,重新生成
在master机器上执行
1)生成新令牌
kubeadm token create
W0713 05:06:02.368758 24478 configset.go:202] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
hr01p2.0ktwulhh71vgzhmv

2)生成签名(和之前一样)
openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
0a381d7f750bda8d639b7132bf4db942710d2042b2cef0c6ffe6aa49a4603f5d

4、重新执行加入命令
kubeadm join 192.168.101.1:6443 --token hr01p2.0ktwulhh71vgzhmv \
--discovery-token-ca-cert-hash sha256:0a381d7f750bda8d639b7132bf4db942710d2042b2cef0c6ffe6aa49a4603f5d \
--ignore-preflight-errors=Swap
W0713 05:25:28.174555 12962 join.go:346] [preflight] WARNING: JoinControlPane.controlPlane settings will be ignored when control-plane flag is not set.
[preflight] Running pre-flight checks
[WARNING Swap]: running with swap on is not supported. Please disable swap
[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.18" 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] Starting the kubelet
[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.

5、在master机器执行
kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 3d v1.18.5
k8s-node1 Ready 2m40s v1.18.5
k8s-node2 Ready 113s v1.18.5

6、在master机器查看pod详细信息
kubectl get pods -n kube-system -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
coredns-66bff467f8-hlzmv 1/1 Running 0 3d 10.122.0.2 k8s-master <none> <none>
coredns-66bff467f8-tmf2p 1/1 Running 0 3d 10.122.0.3 k8s-master <none> <none>
etcd-k8s-master 1/1 Running 0 3d 192.168.101.1 k8s-master <none> <none>
kube-apiserver-k8s-master 1/1 Running 0 3d 192.168.101.1 k8s-master <none> <none>
kube-controller-manager-k8s-master 1/1 Running 0 3d 192.168.101.1 k8s-master <none> <none>
kube-flannel-ds-amd64-dd8s5 1/1 Running 0 6m16s 192.168.101.3 k8s-node2 <none> <none>
kube-flannel-ds-amd64-lxbw2 1/1 Running 0 7m4s 192.168.101.2 k8s-node1 <none> <none>
kube-flannel-ds-amd64-srzn2 1/1 Running 0 179m 192.168.101.1 k8s-master <none> <none>
kube-proxy-6vl9f 1/1 Running 0 3d 192.168.101.1 k8s-master <none> <none>
kube-proxy-rsmff 1/1 Running 0 7m4s 192.168.101.2 k8s-node1 <none> <none>
kube-proxy-swrrh 1/1 Running 0 6m16s 192.168.101.3 k8s-node2 <none> <none>
kube-scheduler-k8s-master 1/1 Running 0 3d 192.168.101.1 k8s-master <none> <none>