kubernetes 集群 master 节点名称是 k8s-master0,想修改为 kube-master0
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master0 Ready control-plane,master 372d v1.20.2
这个 node name 对应的 etcd 配置数据项 key 是 /registry/minions/k8s-master0
,如果通过下面的命令删除这个 key,k8s-master0 就会从 kubectl get nodes 的命令结果中消失。
etcdctl del /registry/minions/k8s-master0
现在的企图是通过修改这个 etcd 配置数据项修改 node name,由于没有找到直接修改 key 与 value 的方法,于是采用导出->修改->添加的方式,使用了如下的 shell 命令
key=/registry/minions/k8s-master0
etcdctl get $key --print-value-only > kv-item.txt
sed -i "s/k8s-master0/kube-master0/" kv-item.txt
cat kv-item.txt | etcdctl put `echo $key | sed "s/k8s-master0/kube-master0/"`
确认是否添加成功
$ etcdctl get /registry/minions/kube-master0 --keys-only
/registry/minions/kube-master0
添加成功,但运行 kubectl get nodes 命令却报错
$ kubectl get nodes
Error from server: proto: Unknown: illegal tag 0 (wire type 0)
请问如何解决?
给 etcdctl 加了 -w fields
参数后有了进展
key=/registry/minions/k8s-master0
etcdctl get $key -w fields > kv-item.txt
sed -i "s/k8s-master0/kube-master0/" kv-item.txt
cat kv-item.txt | etcdctl put `echo $key | sed "s/k8s-master0/kube-master0/"` -w fields
运行上面的命令后,kubectl get nodes
不报错了,输出如下
NAME STATUS ROLES AGE VERSION
k8s-master0 Ready control-plane,master 373d v1.20.2
Unknown <none> <unknown>
kubectl get node kube-master0 -o yaml
输出如下
apiVersion: v1
kind: Node
metadata:
creationTimestamp: null
resourceVersion: "146719967"
spec: {}
status:
daemonEndpoints:
kubeletEndpoint:
Port: 0
nodeInfo:
architecture: ""
bootID: ""
containerRuntimeVersion: ""
kernelVersion: ""
kubeProxyVersion: ""
kubeletVersion: ""
machineID: ""
operatingSystem: ""
osImage: ""
systemUUID: ""