<p>I succeeded in setup a control-plane,master node in my vm. Then I copied the vm, trying to join the copied vm to the existed kubernete cluster.</p>
<p>Problem is that the original vm(node)'s name is new-master-1, and the copied node has the same name. Even after I <code>vi /etc/hostname</code> and change the copied vm's name to new-master-2, after running <code>kubectl get nodes</code> in the copied vm, the output name is still <code>new-master-1</code>:</p>
<pre><code>root@new-master-2:/home/hzg# kubectl get nodes
NAME           STATUS   ROLES                  AGE   VERSION
new-master-1   Ready    control-plane,master   32h   v1.20.2
</code></pre>
<p>I think I can only join the copied vm as another master node to the cluster after I see that the name change to <code>new-master-2</code>, right?  How to change the node's name?</p>

ZhaoGang
<p><strong>TL;DR:</strong></p>
<p>Run: <code>kubeadm join</code> - adjust this command based on the output from <code>kubeadm token create</code> and add flags like <code>--control-plane</code> and <code>--node-name</code> if needed. Take a look at the <a href="https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-join/" rel="nofollow noreferrer">kubeadm join</a> before proceeding.</p>
<hr />
<p>The <code>kubelet</code> registers a node under a particular name. And usually you can <a href="https://kubernetes.io/docs/tasks/administer-cluster/reconfigure-kubelet/" rel="nofollow noreferrer">Reconfigure a Node's Kubelet in a Live Cluster</a>. But it does not apply when it comes to changing the Node's name. If you try to use <code>kubectl edit node</code> for that, you will get an error:</p>
<pre><code>error: At least one of apiVersion, kind and name was changed
</code></pre>
<p>There is a way however. You need to change the hostname and than remove the Node, reset and rejoin it.</p>
<p>Here are the steps. On the Node that needs its name to be changed:</p>
<ul>
<li><p>Change the hostname.</p>
</li>
<li><p>Run: <code>kubectl delete node &lt;nodename&gt;</code> (notice that you still have to use the old Node name)</p>
</li>
<li><p>Run: <code>kubeadm reset</code> (as <code>root</code> if needed)</p>
</li>
</ul>
<p>Now, on the original Master Node:</p>
<ul>
<li><p>Run: <code>export KUBECONFIG=/path/to/admin.conf</code></p>
</li>
<li><p>Run: <code>kubeadm token create --print-join-command</code></p>
</li>
</ul>
<p>Back on the renamed Node:</p>
<ul>
<li>Run: <code>kubeadm join</code> - adjust this command based on the output from <code>kubeadm token create</code> and add flags like <code>--control-plane</code> and <code>--node-name</code> if needed. Take a look at the <a href="https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-join/" rel="nofollow noreferrer">kubeadm join</a> before proceeding.</li>
</ul>
<p>You can check out <a href="https://www.youtube.com/watch?v=TqoA9HwFLVU" rel="nofollow noreferrer">this source</a> for a tutorial video.</p>
<hr />
<p><strong>EXAMPLE:</strong></p>
<pre><code>kube-master:~$ kubectl get nodes
NAME          STATUS   
kube-master   Ready    
kube-node-1   Ready    
kube-node-2   Ready 



kube-master:~$ kubectl delete node kube-node-2
node &quot;kube-node-2&quot; deleted



kube-node-2:~$ sudo kubeadm reset
[reset] WARNING: Changes made to this host by 'kubeadm init' or 'kubeadm join' will be reverted.
[reset] Are you sure you want to proceed? [y/N]: y



kube-node-2:~$ sudo kubeadm join --node-name kube-node-22 &lt;rest-of-the-join-command&gt;

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.



kube-master:~$ kubectl get nodes
NAME           STATUS   
kube-master    Ready    
kube-node-1    Ready    
kube-node-22   Ready 
</code></pre>
<p>Result: the name of <code>kube-node-2</code> was successfully  changed to <code>kube-node-22</code></p>
