kubernetes修改节点名称
框架(架构)  /  管理员 发布于 4年前   2212
有时候因为场景需要,我们需要修改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服务并删除当前节点
[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
host3 Ready
master Ready
三.修改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
123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..路人 在
php中使用hyperf框架调用讯飞星火大模型实现国内版chatgpt功能示例中评论 教程很详细,如果加个前端chatgpt对话页面就完美了..Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号