其他分享
首页 > 其他分享> > kubeadm部署的测试环境k8s集群更改matser节点的名字

kubeadm部署的测试环境k8s集群更改matser节点的名字

作者:互联网

忘记改hostname了,导致master节点name显示不正常

[root@master01 ~]# kubectl get node
NAME                    STATUS     ROLES    AGE   VERSION
localhost.localdomain   NotReady   master   44h   v1.19.3
node01                  Ready      <none>   44h   v1.19.3
node02                  Ready      <none>   44h   v1.19.3

一、查看flannel状态

[root@master01 ~]# kubectl get po -n kube-system   kube-flannel-ds-w4mwc -owide
NAME                    READY   STATUS    RESTARTS   AGE    IP       NODE                    NOMINATED NODE   READINESS GATES
kube-flannel-ds-w4mwc   0/1     Pending   0          102s   <none>   localhost.localdomain   <none>           <none>
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  3m7s  default-scheduler  Successfully assigned kube-system/kube-flannel-ds-w4mwc to localhost.localdomain

二、修改步骤(测试环境,生产慎用)

2.1、删除节点

[root@master01 ~]# kubectl delete node node01 node02 localhost.localdomain 
node "node01" deleted
node "node02" deleted
node "localhost.localdomain" deleted

2.2、查看是否删除完毕

[root@master01 ~]# kubectl get nodes
No resources found

# 已经变成Pending状态
[root@master01 ~]# kubectl get csr  
NAME        AGE    SIGNERNAME                                    REQUESTOR                           CONDITION
csr-6pqpf   43m    kubernetes.io/kube-apiserver-client-kubelet   system:node:localhost.localdomain   Pending
csr-8vj2f   90m    kubernetes.io/kube-apiserver-client-kubelet   system:node:localhost.localdomain   Pending
csr-9cs9r   59m    kubernetes.io/kube-apiserver-client-kubelet   system:node:localhost.localdomain   Pending
csr-9gh45   105m   kubernetes.io/kube-apiserver-client-kubelet   system:node:localhost.localdomain   Pending
csr-9ln7v   151m   kubernetes.io/kube-apiserver-client-kubelet   system:node:localhost.localdomain   Pending
csr-9zbnw   74m    kubernetes.io/kube-apiserver-client-kubelet   system:node:localhost.localdomain   Pending
csr-d7jdl   162m   kubernetes.io/kube-apiserver-client-kubelet   system:node:localhost.localdomain   Pending
csr-dh8hs   136m   kubernetes.io/kube-apiserver-client-kubelet   system:node:localhost.localdomain   Pending
csr-ktbl6   12m    kubernetes.io/kube-apiserver-client-kubelet   system:node:localhost.localdomain   Pending
csr-m7d22   121m   kubernetes.io/kube-apiserver-client-kubelet   system:node:localhost.localdomain   Pending
csr-zsfgr   28m    kubernetes.io/kube-apiserver-client-kubelet   system:node:localhost.localdomain   Pending

2.3、清除集群所有的配置(三节点)

[root@master01 ~]# kubeadm reset
[root@master01 ~]# rm -rf $HOME/.kube/config  (这个在配置了kubectl的节点执行即可)  ## yum install -y net-tools 
[root@master01 ~]# ifconfig cni0 down && ip link delete cni0  (如果cni0没干掉就手动干掉)
[root@master01 ~]# ifconfig flannel.1 down && ip link delete flannel.1
[root@master01 ~]# ifconfig kube-ipvs0 down && ip link delete kube-ipvs0
[root@master01 ~]# ifconfig dummy0 down && ip link delete dummy0  

2.4、修改kubeadm.yaml文件(重点)

[root@master01 ~]# grep -C2 nodeRegistration kubeadm.yaml | grep name
  name: master01

2.5、重新初始化集群

[root@master01 ~]# kubeadm init --config kubeadm.yaml
2.5.1、成功后添加node节点即可
Your Kubernetes control-plane has initialized successfully!

To start using your cluster, 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

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.1.70:6443 --token abcdef.0123456789abcdef \
    --discovery-token-ca-cert-hash sha256:f4d24e1b28d4dcb1ebaa9c4847221fda503bb08627175dbdacb589cc4ebfaa8a 

2.7、验证

[root@master01 ~]# kubectl get node
NAME       STATUS     ROLES    AGE     VERSION
master01   NotReady   master   2m37s   v1.19.3
node01     NotReady   <none>   34s     v1.19.3
node02     NotReady   <none>   38s     v1.19.3

2.8、部署网络插件

[root@master01 ~]# kubectl apply -f kube-flannel.yml

2.9、集群验证

[root@master01 ~]# kubectl get node
NAME       STATUS   ROLES    AGE   VERSION
master01   Ready    master   32m   v1.19.3
node01     Ready    <none>   30m   v1.19.3
node02     Ready    <none>   30m   v1.19.3

kubeadm参考: https://blog.csdn.net/qq_24794401/article/details/106654710

二进制安装可参坑:https://blog.csdn.net/chenshm/article/details/118718644

标签:node,kube,matser,master01,localdomain,kubeadm,k8s,root,localhost
来源: https://www.cnblogs.com/hsyw/p/15183210.html