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

<p>I have tried to </p>

<ol>
<li>delete the node using kubectl delete</li>
<li>change the name in the node's manifest</li>
<li>add the node back.</li>
</ol>

<p>But the node won't start.</p>

<p>Anyone know how it should be done?</p>

<p>Thanks</p>

<p>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.</p>

<p>(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
)</p>

<p>Ideally you have removed the running pods on it.
You can try to run <code>kubectl drain &lt;node_name_to_rename&gt;</code> . 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.</p>

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

<pre><code>kubectl delete node &lt;original-nodename&gt;
</code></pre>

<p>Then on the node that you want to rejoin, as root:</p>

<pre><code>kubeadm reset
</code></pre>

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

<p>Now generate the join command on the master node:</p>

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

<p>Run the output on the worker node you have just reset:</p>

<pre><code>kubeadm join &lt;masternode_ip_address&gt;:6443 --token somegeneratedtoken --discovery-token-ca-cert-hash sha256:somesha256hashthatyougotfromtheabovecommand
</code></pre>

<p>If you run <code>kubectl get nodes</code> it should show up now with the new name </p>

<p>output in my case:</p>

<pre><code>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.
</code></pre>

<p>Enjoy your renamed node!</p>

<p>Based on source: <a href="https://www.youtube.com/watch?v=TqoA9HwFLVU" rel="noreferrer">https://www.youtube.com/watch?v=TqoA9HwFLVU</a></p>
