kubernetes modify node name

 

Sometimes due to the needs of the scene, we need to modify the hostname of the kubernetes node, assuming that there are three nodes:

host1, host2, host3, cni components use calico, you need to change host1 to master.

When modifying the hostname of the kubelet node, you also need to modify the hostname in the calico service. Specific steps are as follows:

1. Modify the system hostname

[root@host1 ~]# hostname master

2. Modify the hostname of the kubelet node

Modify the kubelet startup parameter --hostname-override=master

Restart the kubelet service

[root@master ~]# systemctl restart kubelet

Check the kubelet running log at this time

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

You will see the following error

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"

Stop the kubelet service and delete the current node

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

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

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

Restart kubelet

[root@master ~]# systemctl restart kubelet

 View certificate status

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

 allow certificate

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

 Check the certificate status again

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

 View node status

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

3. Modify the hostname of the calico node

At this time, check the running status of calico 

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

The calico service will output the following error log

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

Switch to other nodes to view, such as host2

[root@host2 ~]# calicoctl get node
NAME    
host1   
host2   
host3
[root@host2 ~]# calicoctl node status
Calico process is running.

IPv4 BGP status
+--------------+-------------------+-------+----------+--------------------------------+
| PEER ADDRESS |     PEER TYPE     | STATE |  SINCE   |              INFO              |
+--------------+-------------------+-------+----------+--------------------------------+
| 10.21.21.254 | node-to-node mesh | start | 05:16:47 | Active Socket: Connection      |
|              |                   |       |          | refused                        |
| 10.21.21.245 | node-to-node mesh | up    | 04:44:35 | Established                    |
+--------------+-------------------+-------+----------+--------------------------------+

IPv6 BGP status
No IPv6 peers found.

Get the host1 node configuration and save the output to the file master.yaml

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

delete host1

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

Modify master.yaml

apiVersion: projectcalico.org/v3
kind: Node
metadata:
  name: master
  uid: dfb352cf-2e54-11e8-82e7-52540000361b
spec:
  bgp:
    ipv4Address: 10.21.21.254/16
    ipv4IPIPTunnelAddr: 10.233.119.0

Create calico node

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

Delete abnormal calico Pod

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

Waiting for the calico Pod to rebuild

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

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324401311&siteId=291194637