在當前唯一的master節點上運行如下命令 第一步: kubeadm init phase upload-certs --upload-certs 執行結果如下: 1 # kubeadm init phase upload-certs --upload-certs 2 I1109 14:34:00. ...
在當前唯一的master節點上運行如下命令 第一步:
kubeadm init phase upload-certs --upload-certs執行結果如下:
1 # kubeadm init phase upload-certs --upload-certs 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 [upload-certs] Storing the certificates in Secret "kubeadm-certs" in the "kube-system" Namespace 4 [upload-certs] Using certificate key: 5 ecf2abbfdf3a7bc45ddb2de75152ec12889971098d69939b98e4451b53aa3033
第二步:
kubeadm token create --print-join-command執行結果如下
[root@k8s-master ~]# kubeadm token create --print-join-command kubeadm join 172.16.0.1:6443 --token xxxxxx --discovery-token-ca-cert-hash sha256:xxxxxxx第三步: 將得到的token和key進行拼接,得到如下命令:
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
This node has joined the cluster and a new control plane instance was created: * Certificate signing request was sent to apiserver and approval was received. * The Kubelet was informed of the new secure connection details. * Control plane (master) label and taint were applied to the new node. * The Kubernetes control plane instances scaled up. * A new etcd member was added to the local/stacked etcd cluster. To start administering your cluster from this node, you need to run the following as a regular user: mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config Run 'kubectl get nodes' to see this node join the cluster.
這樣,我們在任何一個master節點上使用命令
kubectl get nodes都能看到現在是全部的節點:
# kubectl get nodes NAME STATUS ROLES AGE VERSION k8s-master Ready master 57m v1.18.0 k8s-master1 Ready master 21m v1.18.0 k8s-master2 Ready master 21m v1.18.0 k8s-node1 Ready <none> 56m v1.18.0 k8s-node2 Ready <none> 56m v1.18.0 k8s-node3 Ready <none> 56m v1.18.0 k8s-node4 Ready <none> 56m v1.18.0 k8s-node5 Ready <none> 56m v1.18.0報錯: 1. 第一次加入集群的時候會有以下報錯:
1 [preflight] Running pre-flight checks 2 [preflight] Reading configuration from the cluster... 3 [preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml' 4 error execution phase preflight: 5 One or more conditions for hosting a new control plane instance is not satisfied. 6 7 unable to add a new control plane instance a cluster that doesn't have a stable controlPlaneEndpoint address 8 9 Please ensure that: 10 * The cluster has a stable controlPlaneEndpoint address. 11 * The certificates that must be shared among control plane instances are provided. 12 13 14 To see the stack trace of this error execute with --v=5 or higher解決辦法如下:
查看kubeadm-config.yaml kubectl -n kube-system get cm kubeadm-config -oyaml 發現沒有controlPlaneEndpoint 添加controlPlaneEndpoint kubectl -n kube-system edit cm kubeadm-config 大概在這麼個位置: kind: ClusterConfiguration kubernetesVersion: v1.18.0 controlPlaneEndpoint: 172.16.0.56:6443 然後再在準備添加為master的節點上執行kubeadm join的命令
每天記錄一點,就能多學一點,充實一點