千家信息网

kubernetes中如何修改节点名称

发表于:2024-11-14 作者:千家信息网编辑
千家信息网最后更新 2024年11月14日,kubernetes中如何修改节点名称,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。一.修改系统主机名[root@host1 ~]# h
千家信息网最后更新 2024年11月14日kubernetes中如何修改节点名称

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 csrNAME                                                   AGE       REQUESTOR           CONDITIONnode-csr-GIAqC5LBI_7c6TlMW8wugv_TlHfs1CShZhnEyLgxvSI   1m        kubelet-bootstrap   Pending

允许证书

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

再次查看证书状态

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

查看节点状态

[root@master ~]# kubectl get nodeNAME           STATUS    ROLES     AGE       VERSIONhost2          Ready         34m       v1.9.5host3          Ready         34m       v1.9.5master         Ready         18s       v1.9.5

三.修改calico节点主机名

这时候查看calico运行状态

[root@master ~]# calicoctl node statusCalico 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 nodeNAME    host1   host2   host3[root@host2 ~]# calicoctl node statusCalico 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 statusNo IPv6 peers found.

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

[root@host2 ~]# calicoctl get node host1 -o yamlapiVersion: projectcalico.org/v3kind: Nodemetadata:  creationTimestamp: 2018-03-23T04:44:29Z  name: host1  resourceVersion: "485"  uid: dfb352cf-2e54-11e8-82e7-52540000361bspec:  bgp:    ipv4Address: 10.21.21.254/16    ipv4IPIPTunnelAddr: 10.233.119.0

删除host1

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

修改master.yaml

apiVersion: projectcalico.org/v3kind: Nodemetadata:  name: master  uid: dfb352cf-2e54-11e8-82e7-52540000361bspec:  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-systemNAME                                       READY     STATUS             RESTARTS   AGEcalico-kube-controllers-5f47974799-ttz7s   1/1       Running            0          6mcalico-node-274q9                          2/2       Running            0          40mcalico-node-dp8dz                          2/2       Running            0          40mcalico-node-rh3kd                          1/2       CrashLoopBackOff   5          5m[root@host2 ~]# kubectl delete pod -n kube-system calico-node-rh3kdpod "calico-node-rh3kd" deleted

等待calico Pod重建

[root@host2 ~]# kubectl get pod -n kube-systemNAME                                       READY     STATUS    RESTARTS   AGEcalico-kube-controllers-5f47974799-ttz7s   1/1       Running   0          7mcalico-node-274q9                          2/2       Running   0          40mcalico-node-9th5r                          2/2       Running   0          12scalico-node-dp8dz                          2/2       Running   0          40m

看完上述内容,你们掌握kubernetes中如何修改节点名称的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!

0