有時候由於場景須要,咱們須要修改kubernetes節點的主機名,假設有三個節點分別是:node
host1,host2,host3,cni組件使用calico,須要將host1改成master。bootstrap
在修改kubelet節點主機名的時候也須要修改calico服務中的主機名。具體步驟以下:api
一.修改系統主機名app
[root@host1 ~]# hostname master
二.修改kubelet節點主機名ide
修改kubelet啓動參數--hostname-override=masteroop
重啓kubelet服務ui
[root@master ~]# systemctl restart kubelet
這時查看kubelet運行日誌rest
[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服務並刪除當前節點code
[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*
再重啓kubelet
[root@master ~]# systemctl restart kubelet
查看證書狀態
[root@master ~]# kubectl get csr NAME AGE REQUESTOR CONDITION node-csr-GIAqC5LBI_7c6TlMW8wugv_TlHfs1CShZhnEyLgxvSI 1m kubelet-bootstrap Pending
容許證書
[root@master ~]# kubectl certificate approve node-csr-GIAqC5LBI_7c6TlMW8wugv_TlHfs1CShZhnEyLgxvSI
再次查看證書狀態
[root@master ~]# kubectl get csr NAME AGE REQUESTOR CONDITION node-csr-GIAqC5LBI_7c6TlMW8wugv_TlHfs1CShZhnEyLgxvSI 1m kubelet-bootstrap Approved,Issued
查看節點狀態
[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
三.修改calico節點主機名
這時候查看calico運行狀態
[root@master ~]# calicoctl node status 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
[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.
獲取host1節點配置,保存輸出內容到文件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
刪除host1
[root@host2 ~]# calicoctl delete node host1 Successfully deleted 1 'Node' resource(s)
修改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
建立calico節點
[root@host2 ~]# calicoctl apply -f master.yaml Successfully applied 1 'Node' resource(s)
刪除異常的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
等待calico Pod重建
[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