翼度科技»论坛 云主机 LINUX 查看内容

k8s-新增master节点

7

主题

7

帖子

21

积分

新手上路

Rank: 1

积分
21
在当前唯一的master节点上运行如下命令第一步:
  1. kubeadm init phase upload-certs --upload-certs
复制代码
执行结果如下:
  1. 1 # kubeadm init phase upload-certs --upload-certs
  2. 2 I1109 14:34:00.836965    5988 version.go:255] remote version is much newer: v1.25.3; falling back to: stable-1.22
  3. 3 [upload-certs] Storing the certificates in Secret "kubeadm-certs" in the "kube-system" Namespace
  4. 4 [upload-certs] Using certificate key:
  5. 5 ecf2abbfdf3a7bc45ddb2de75152ec12889971098d69939b98e4451b53aa3033
复制代码
第二步:
  1. kubeadm token create --print-join-command
复制代码
执行结果如下
  1. [root@k8s-master ~]# kubeadm token create --print-join-command
  2. kubeadm join 172.16.0.1:6443 --token xxxxxx --discovery-token-ca-cert-hash sha256:xxxxxxx
复制代码
第三步:将得到的token和key进行拼接,得到如下命令:
  1. kubeadm join 172.16.0.1:6443 --token q466v0.hbk3qjreznjsf8ew --discovery-token-ca-cert-hash xxxxxxx --control-plane --certificate-key xxxxxxx
复制代码
注意事项:

  • 不要使用 --experimental-control-plane,会报错
  • 要加上--control-plane --certificate-key ,不然就会添加为node节点而不是master
  • join的时候节点上不要部署,如果部署了kubeadm reset后再join
 第四步:join之后在原先唯一的master节点上成功后,显示如下消息:
  1. This node has joined the cluster and a new control plane instance was created:
  2. * Certificate signing request was sent to apiserver and approval was received.
  3. * The Kubelet was informed of the new secure connection details.
  4. * Control plane (master) label and taint were applied to the new node.
  5. * The Kubernetes control plane instances scaled up.
  6. * A new etcd member was added to the local/stacked etcd cluster.
  7. To start administering your cluster from this node, you need to run the following as a regular user:
  8.     mkdir -p $HOME/.kube
  9.     sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  10.     sudo chown $(id -u):$(id -g) $HOME/.kube/config
  11. Run 'kubectl get nodes' to see this node join the cluster.
复制代码
这样,我们在任何一个master节点上使用命令
  1. kubectl get nodes
复制代码
都能看到现在是全部的节点:
  1. # kubectl get nodes
  2. NAME          STATUS   ROLES    AGE   VERSION
  3. k8s-master    Ready    master   57m   v1.18.0
  4. k8s-master1   Ready    master   21m   v1.18.0
  5. k8s-master2   Ready    master   21m   v1.18.0
  6. k8s-node1     Ready    <none>   56m   v1.18.0
  7. k8s-node2     Ready    <none>   56m   v1.18.0
  8. k8s-node3     Ready    <none>   56m   v1.18.0
  9. k8s-node4     Ready    <none>   56m   v1.18.0
  10. k8s-node5     Ready    <none>   56m   v1.18.0
复制代码
报错:1. 第一次加入集群的时候会有以下报错:
  1. 1 [preflight] Running pre-flight checks
  2. 2 [preflight] Reading configuration from the cluster...
  3. 3 [preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
  4. 4 error execution phase preflight:
  5. 5 One or more conditions for hosting a new control plane instance is not satisfied.
  6. 6
  7. 7 unable to add a new control plane instance a cluster that doesn't have a stable controlPlaneEndpoint address
  8. 8
  9. 9 Please ensure that:
  10. 10 * The cluster has a stable controlPlaneEndpoint address.
  11. 11 * The certificates that must be shared among control plane instances are provided.
  12. 12
  13. 13
  14. 14 To see the stack trace of this error execute with --v=5 or higher
复制代码
解决办法如下:
  1. 查看kubeadm-config.yaml
  2. kubectl -n kube-system get cm kubeadm-config -oyaml
  3. 发现没有controlPlaneEndpoint
  4. 添加controlPlaneEndpoint
  5. kubectl -n kube-system edit cm kubeadm-config
  6. 大概在这么个位置:
  7. kind: ClusterConfiguration
  8. kubernetesVersion: v1.18.0
  9. controlPlaneEndpoint: 172.16.0.56:6443
  10. 然后再在准备添加为master的节点上执行kubeadm join的命令
复制代码
  

来源:https://www.cnblogs.com/qianyuliang/p/17044626.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

举报 回复 使用道具