[转载]kubernetes修改节点名称

kubernetes修改节点名称

 

 

有时候因为场景需要,我们需要修改kubernetes节点的主机名,假设有三个节点分别是:

host1,host2,host3,cni组件使用calico,需要将host1改为master。

在修改kubelet节点主机名的时候也需要修改calico服务中的主机名。具体步骤如下:

一.修改系统主机名

[root@host1 ~]# hostname master

二.修改kubelet节点主机名

修改kubelet启动参数--hostname-override=master

重启kubelet服务

[root@master ~]# systemctl restart kubelet

这时查看kubelet运行日志

[root@master ~]# journalctl -xe -u kubelet

会看到如下报错

Mar 23 13:15:27 master kubelet[13508]: E0323 13:15:27.320556   13508 kubelet_node_status.go:106] Unable to register node "master" with API server: nodes "master" is forbidden: node "host1" cannot modify node "master"

停止kubelet服务并删除当前节点

  1.   [root@master ~]# systemctl stop kubelet
  2.   [root@master ~]# kubectl delete node host1

删除kubelet.kubeconfig,kubelet.key,kubelet.crt,kubelet-client.key和kubelet-client.crt

  1.   [root@master ~]# rm -f /etc/kubernetes/kubelet.kubeconfig
  2.   [root@master ~]# rm -f /etc/kubernetes/ssl/kubelet*

再重启kubelet

[root@master ~]# systemctl restart kubelet

 查看证书状态

  1.   [root@master ~]# kubectl get csr
  2.   NAME AGE REQUESTOR CONDITION
  3.   node-csr-GIAqC5LBI_7c6TlMW8wugv_TlHfs1CShZhnEyLgxvSI 1m kubelet-bootstrap Pending

 允许证书

[root@master ~]# kubectl certificate approve node-csr-GIAqC5LBI_7c6TlMW8wugv_TlHfs1CShZhnEyLgxvSI

 再次查看证书状态

  1.   [root@master ~]# kubectl get csr
  2.   NAME AGE REQUESTOR CONDITION
  3.   node-csr-GIAqC5LBI_7c6TlMW8wugv_TlHfs1CShZhnEyLgxvSI 1m kubelet-bootstrap Approved,Issued

 查看节点状态

  1.   [root@master ~]# kubectl get node
  2.   NAME STATUS ROLES AGE VERSION
  3.   host2 Ready <none> 34m v1.9.5
  4.   host3 Ready <none> 34m v1.9.5
  5.   master Ready <none> 18s v1.9.5

三.修改calico节点主机名

这时候查看calico运行状态 

  1.   [root@master ~]# calicoctl node status
  2.   Calico process is not running.

calico服务会输出如下错误日志

[WARNING][9] startup.go 757: calico node 'host1' is already using the IPv4 address 10.233.119.0

切换到其他节点上查看,如host2

  1.   [root@host2 ~]# calicoctl get node
  2.   NAME
  3.   host1
  4.   host2
  5.   host3
  6.   [root@host2 ~]# calicoctl node status
  7.   Calico process is running.
  8.    
  9.   IPv4 BGP status
  10.   +--------------+-------------------+-------+----------+--------------------------------+
  11.   | PEER ADDRESS | PEER TYPE | STATE | SINCE | INFO |
  12.   +--------------+-------------------+-------+----------+--------------------------------+
  13.   | 10.21.21.254 | node-to-node mesh | start | 05:16:47 | Active Socket: Connection |
  14.   | | | | | refused |
  15.   | 10.21.21.245 | node-to-node mesh | up | 04:44:35 | Established |
  16.   +--------------+-------------------+-------+----------+--------------------------------+
  17.    
  18.   IPv6 BGP status
  19.   No IPv6 peers found.
  20.    

获取host1节点配置,保存输出内容到文件master.yaml中

  1.   [root@host2 ~]# calicoctl get node host1 -o yaml
  2.   apiVersion: projectcalico.org/v3
  3.   kind: Node
  4.   metadata:
  5.   creationTimestamp: 2018-03-23T04:44:29Z
  6.   name: host1
  7.   resourceVersion: "485"
  8.   uid: dfb352cf-2e54-11e8-82e7-52540000361b
  9.   spec:
  10.   bgp:
  11.   ipv4Address: 10.21.21.254/16
  12.   ipv4IPIPTunnelAddr: 10.233.119.0

删除host1

  1.   [root@host2 ~]# calicoctl delete node host1
  2.   Successfully deleted 1 'Node' resource(s)

修改master.yaml

  1.   apiVersion: projectcalico.org/v3
  2.   kind: Node
  3.   metadata:
  4.   name: master
  5.   uid: dfb352cf-2e54-11e8-82e7-52540000361b
  6.   spec:
  7.   bgp:
  8.   ipv4Address: 10.21.21.254/16
  9.   ipv4IPIPTunnelAddr: 10.233.119.0

创建calico节点

  1.   [root@host2 ~]# calicoctl apply -f master.yaml
  2.   Successfully applied 1 'Node' resource(s)

删除异常的calico Pod

  1.   [root@host2 ~]# kubectl get pod -n kube-system
  2.   NAME READY STATUS RESTARTS AGE
  3.   calico-kube-controllers-5f47974799-ttz7s 1/1 Running 0 6m
  4.   calico-node-274q9 2/2 Running 0 40m
  5.   calico-node-dp8dz 2/2 Running 0 40m
  6.   calico-node-rh2kd 1/2 CrashLoopBackOff 5 5m
  7.   [root@host2 ~]# kubectl delete pod -n kube-system calico-node-rh2kd
  8.   pod "calico-node-rh2kd" deleted

等待calico Pod重建

  1.   [root@host2 ~]# kubectl get pod -n kube-system
  2.   NAME READY STATUS RESTARTS AGE
  3.   calico-kube-controllers-5f47974799-ttz7s 1/1 Running 0 7m
  4.   calico-node-274q9 2/2 Running 0 40m
  5.   calico-node-9th4r 2/2 Running 0 12s
  6.   calico-node-dp8dz 2/2 Running 0 40m

 

 

转载于:https://my.oschina.net/u/3390908/blog/1649764

上一篇:mysql


下一篇:k8s搭建部署