How to change name of a kubernetes node

9/1/2017

I have a running node in a kubernetes cluster. Is there a way I can change its name?

I have tried to

  1. delete the node using kubectl delete
  2. change the name in the node's manifest
  3. add the node back.

But the node won't start.

Anyone know how it should be done?

Thanks

-- Abelard Chow
kubernetes

2 Answers

9/1/2017

Usualy it's kubelet that is responsible for registering the node under particular name, so you should make changes to your nodes kubelet configuration and then it should pop up as new node.

-- Radek 'Goblin' Pieczonka
Source: StackOverflow

2/20/2020

Changing the node's name is not possible at the moment, it requires you to remove and rejoin the node. You need to make sure the hostname is changed to the new name, remove the node, reset it and rejoin it.

(you will notice that with the command : kubectl edit node , you will get an error if you try and save the name: A copy of your changes has been stored to "/tmp/kubectl-edit-qlh54.yaml" error: At least one of apiVersion, kind and name was changed )

Ideally you have removed the running pods on it. You can try to run kubectl drain <node_name_to_rename> . Proceed at your own risk if that doesn't complete . --ignore-daemon-sets can be used to ignore possible issues for pods that cannot be evicted.

In short, for a node that has been renamed and is out of the cluster on CentOS 7:

kubectl delete node <original-nodename>

Then on the node that you want to rejoin, as root:

kubeadm reset

check the output and see if it applies to your setup (for potential further cleanup).

Now generate the join command on the master node:

export KUBECONFIG=/etc/kubernetes/admin.conf #(or wherever you have it)
kubeadm token create --print-join-command

Run the output on the worker node you have just reset:

kubeadm join <masternode_ip_address>:6443 --token somegeneratedtoken --discovery-token-ca-cert-hash sha256:somesha256hashthatyougotfromtheabovecommand

If you run kubectl get nodes it should show up now with the new name

output in my case:

W0220 10:43:23.286109   11473 join.go:346] [preflight] WARNING: JoinControlPane.controlPlane settings will be ignored when control-plane flag is not set.
[preflight] Running pre-flight checks
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[kubelet-start] Downloading configuration for the kubelet from the "kubelet-config-1.17" ConfigMap in the kube-system namespace
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

Enjoy your renamed node!

Based on source: https://www.youtube.com/watch?v=TqoA9HwFLVU

-- Vincent Gerris
Source: StackOverflow