您好,登录后才能下订单哦!
kubernetes中如何修改节点名称,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
一.修改系统主机名
[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服务并删除当前节点
[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-rh3kd 1/2 CrashLoopBackOff 5 5m [root@host2 ~]# kubectl delete pod -n kube-system calico-node-rh3kd pod "calico-node-rh3kd" 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-9th5r 2/2 Running 0 12s calico-node-dp8dz 2/2 Running 0 40m
看完上述内容,你们掌握kubernetes中如何修改节点名称的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。