博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
kubernetes修改节点名称
阅读量:6314 次
发布时间:2019-06-22

本文共 4605 字,大约阅读时间需要 15 分钟。

hot3.png

 

有时候因为场景需要,我们需要修改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 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-rh2kd                          1/2       CrashLoopBackOff   5          5m[root@host2 ~]# kubectl delete pod -n kube-system calico-node-rh2kdpod "calico-node-rh2kd" 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-9th4r                          2/2       Running   0          12scalico-node-dp8dz                          2/2       Running   0          40m

 

转载于:https://my.oschina.net/u/3390908/blog/1649764

你可能感兴趣的文章
ansible hosts文件详解
查看>>
屏幕录像专家录制超清视频教程如何解决转码后不清晰问题
查看>>
iotop命令性能监测与优化
查看>>
通用权限管理系统组件回答用户的常用问题:操作权限、用户角色、数据权限的解决方法...
查看>>
linux nc命令参数及用法详解--功能超级强大的网络工具netcat
查看>>
【JEECG Dubbo专题】jeecg-p3集成dubbo文档
查看>>
mysql的基本数据类型
查看>>
Java架构设计和开发中的小技巧
查看>>
最大子序和-LeetCode
查看>>
VDI网络配置的4个最佳实践
查看>>
Android导入第三方jar包,proguard混淆脚本(屏蔽警告,不混淆第三方包)
查看>>
【vSphere系列一】安装vSphere ESXi5.1
查看>>
centOS安装配置ganglia
查看>>
Mysql的逻辑备份与恢复
查看>>
【MYSQL】字符转换和group_concat()函数的排序方法
查看>>
烂泥:Linux系统与windows系统文件同步
查看>>
select count 时报 Duplicate column name 'orderid' 错误
查看>>
理解ssh加密和链接过程
查看>>
YUM的工作机制与配置
查看>>
《JAVA编程思想》学习笔记——第十二章 通过异常处理错误
查看>>