Centos服务器相关

k8s中子节点的加入

2021-08-10 485 0

简介

systemctl status  docker.service

systemctl status kubelet.service


kubeadm join 192.168.137.130:6443 --token h62ug9.4c78tdc6otkiment  --discovery-token-ca-cert-hash sha256:3f6e903d3d9dbbfc0ea5c38ef4b5928c8dc13268213e5088ae7e951c685e23f5






3. 加入集群

以下操作master上执行

3.1 查看令牌

kubeadm token list

3.2 生成新的令牌

kubeadm token create

3.3 生成新的加密串

openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | \

   openssl dgst -sha256 -hex | sed 's/^.* //'

node节点加入集群

在node节点上分别执行如下操作:


[root@node01 ~]# kubeadm join 172.27.9.131:6443 --toke




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 "im1s4j"

To see the stack trace of this error execute with --v=5 or higher



这个问题是在kube-public下的 configmap 的 cluster-info 中没有JWS签名, 本质上是 token 过期.


可以通过 kube config 命令查看 cluster-info 的内容:


kubectl get configmap cluster-info --namespace=kube-public -o yaml



2.1 生成token

首先我们通过以下命令生成一个新的 token:

kubeadm token create --ttl 0


h62ug9.4c78tdc6otkiment

也可以通过以下命令查看生成的token:


2.2 生成证书摘要

然后再重新生成证书签名摘要(或者说hash), 当然这个值(只要证书不变)是不变的, 跟我们在首次安装 kubeadm init 的时候生成的 hash 是一样的:



2.3 合二为一

以上生成 token 和 hash 可以在生成token的时候加上 --print-join-command 直接打印出来. 毕竟生成 token 就是用来添加节点用的.


# 在 master 节点执行

kubeadm token create --print-join-command --ttl=0




[root@node1 ~]# kubeadm join 192.168.137.130:6443 --token h62ug9.4c78tdc6otkiment  --discovery-token-ca-cert-hash sha256:3f6e903d3d9dbbfc0ea5c38ef4b5928c8dc13268213e5088ae7e951c685e23f5

[preflight] Running pre-flight checks

[preflight] Reading configuration from the cluster...

[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'

[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.

加入成功


执行查看k8s集群运行状态命令:

  • sudo kubectl get nodes

NAME              STATUS     ROLES    AGE   VERSION
192.168.159.133   Ready      master   61m   v1.17.3
worktwo           NotReady   <none>   58m   v1.17.3

发现master已经Ready了 但是工作node没有起来,状态是NotReady

下面去配置工作node虚拟机上的flannel配置

192.168.159.135 是我的工作node

运行命令把master节点的配置copy到工作节点

  • scp -r 192.168.159.133:/etc/cni /etc/cni

重启启动 kubelet

  • systemctl restart kubelet

回到master节点查看

执行查看k8s集群运行状态命令:

  • sudo kubectl get nodes

[root@workone ~]# sudo kubectl get nodes
NAME              STATUS   ROLES    AGE   VERSION
192.168.159.133   Ready    master   66m   v1.17.3
worktwo           Ready    <none>   64m   v1.17.3


点赞 0

我的名片

网名:梦宇信息技术

职业:软件开发、Mes系统工程师

现居:福建省-福州市

QQ:703159

站点信息

  • 联系QQ:703159
  • 文章统计97篇文章
  • 标签总数6
  • 加我微信:扫码,加我微信