kubeadm join 使用 token 过期之后(24小时过期),重新生成token
一、重启生成新token
# 创建新token
kubeadm token create
# 查看是否存在有效的 token 值
kubeadm token list
二、获取CA证书 sha256 编码 hash 值
openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
三、新节点加入集群
kubeadm join 192.168.0.211:6443 --token ai3o14.d555o4992nyl3zgd --discovery-token-ca-cert-hash sha256:e4435c11751a06472a4971a2a5811a2e6b7f2ce0689e78201a58082fc3dfc3c7
### token使用上面新生成的token
四、快捷方式、一步到位(可以直接在master节点使用步骤四)
[root@k8s-master package]# kubeadm token create --print-join-command
W0701 13:21:47.900325 85831 configset.go:348] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
kubeadm join 192.168.130.136:6443 --token gs9y86.lhmu23t9kqfax09z --discovery-token-ca-cert-hash sha256:87408a5d81bd21c845d94630f4ff8fc9a2e206e9f88396d2d2966cec083d7f20
五、新节点加入到集群
在新加入节点执行如下命令:
kubeadm join 192.168.130.136:6443 --token gs9y86.lhmu23t9kqfax09z --discovery-token-ca-cert-hash sha256:87408a5d81bd21c845d94630f4ff8fc9a2e206e9f88396d2d2966cec083d7f20
如果环境没有问题执行完此条命令就能成功加入到集群。
遇到问题:
由于master节点到新节点的TCP 22端口不通,并且新节点不能连外网所以纳入过程中遇到了很多问题。
1、首先解决两个Waring。
1)、修改docker driver(这个可以不调整)
解决方法:
调整docker配置文件,添加以下内容
"exec-opts": ["native.cgroupdriver=systemd"]
2)、由于master节点到新节点的TCP 22端口不通,许多文件需要手扶。
vim /etc/systemd/system/kubelet.service
[Unit]
Description=kubelet: The Kubernetes Node Agent
Documentation=http://kubernetes.io/docs/
[Service]
ExecStart=/usr/local/bin/kubelet
Restart=always
StartLimitInterval=0
RestartSec=10
[Install]
WantedBy=multi-user.targetx
2、修改完上面2个Warning后就能成功启动kubelet后台服务了,查看kubelet日志看到报如下错误
解决方案:
1)、同样需要手扶文件,将master节点/opt/cni/bin目录下的所有文件拷贝到新节点的/opt/cni/bin目录下
2)、vim /etc/cni/net.d/10-flannel.conflist
{
"name": "cbr0",
"cniVersion": "0.3.1",
"plugins": [
{
"type": "flannel",
"delegate": {
"hairpinMode": true,
"isDefaultGateway": true
}
},
{
"type": "portmap",
"capabilities": {
"portMappings": true
}
}
]
}
3)、另外生成manifests目录,此目录下没有文件,mkdir /etc/kubernetes/manifests/ 即可。
3、如果过程中还有[kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get http://localhost:10248/healthz: dial tcp [::1]:10248: connect: connection refused.这个错误,调整kubelet配置文件,加入如下配置即可。
root@test2 ~]# vim /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
...
Environment="KUBELET_SYSTEM_PODS_ARGS=--pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true --fail-swap-on=false"
[root@test2 ~]# systemctl daemon-reload
[root@test2 ~]# systemctl restart kubelet