Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to change Node name in Kubernetes Cluster

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

What this article shares with you is about how to change the node name of a Kubernetes cluster. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.

The Kubernetes cluster node uses the machine name or DNS of / etc/hostname. It is best to set the domain name and machine name properly before creating the cluster. It will be troublesome to change the node name after the cluster is set up. In particular, if you need to change the name of the first node, you will fail to create key and token, and you can no longer add master nodes to the cluster, so you need to rebuild the cluster or manually modify the parameters of all relevant configuration files.

There is no easy way to change the node name of Kubernetes cluster. The steps are as follows:

Delete pod

Delete nod

Clean up etcd

Create token

Rejoin the cluster

The specific operations are as follows:

1. Delete a task

Before performing maintenance operations on the node (for example, kernel upgrade, hardware maintenance, etc.), you can use kubectl drain to safely expel all the pod above the node. Safe eviction will allow containers in the pod to perform an elegant abort following the specified PodDisruptionBudgets.

First, you need to determine the name of the node you want to remove. You can list all the nodes in the cluster with the following command:

Kubectl get nodes

Next, tell Kubernetes to remove the node:

Kubectl drain

After the execution is complete, if no errors are returned, you can shut down the node (if you are on the cloud platform, you can delete the virtual machines that support the node). If you want to leave the nodes in the cluster during the maintenance operation, you need to run the following command:

Kubectl uncordon

It then tells Kubernetes to allow new pod to be dispatched to that node.

Reference:

Expel the task pod, https://www.cnblogs.com/weifeng1463/p/10359581.html on the node

⚠️ Note: if drain is not used to expel the pod on all nodes to be deleted, even if the node is deleted, the pod will run until the node service is restarted.

2. Delete a node

Delete the node:

Kubectl delete node podc01

And then the problem remains. It is found that the etcd service address of the deleted node is still in the cluster and is inaccessible, so the upgrade cannot be completed.

According to the kubeadm instructions on the Internet, using kubeadm reset will automatically delete the node information of etcd.

However, after kubeadm reset, it is found that the etcd service address of the deleted node is still in the cluster and is inaccessible, so the upgrade cannot be completed.

3. Delete etcd node manually

View and manually delete etcd node information:

Alias etcdv3= "ETCDCTL_API=3 etcdctl-endpoints= https://[10.1.1.202]:2379-cacert=/etc/kubernetes/pki/etcd/ca.crt-cert=/etc/kubernetes/pki/etcd/peer.crt-key=/etc/kubernetes/pki/etcd/peer.key"

Because the etcd command is long, simplify it with an individual name.

Change 10.1.1.202 above to your own available master node IP address.

For more etcd usage guidelines, please refer to:

Practical skills of etcd Multi-node capacity expansion of Kubernetes

Exploring the secrets of Kubernetes-expanding the capacity of etcd nodes and instances

Etcd data viewing and migration for Kubernetes

Kubernetes Secret Exploration-etcd status data and its backup

Then, run:

# View members of etcd cluster: etcdv3 member list# delete inaccessible members of etcd cluster: etcdv3 member remove XXXXXXXXXX# view members of etcd cluster again: etcdv3 member list

Etcd error for kubernetes high availability cluster upgrade

Modify the server address in all configuration files under / etc/kubernetes to the available node address.

4. Create token

Add a node to the current cluster:

The first step is to recreate certificate key and token:

Sudo kubeadm init phase upload-certs-- upload-certs### Got:# [upload-certs] Using certificate key:# 2ffe5bbf7d2e670d5bcfb03dac194e2f21eb9715f2099c5f8574e4ba7679ff78# Add certificate-key for Multi Master Node.kubeadm token create-- print-join-command-- certificate-key 2ffe5bbf7d2e670d5bcfb03dac194e2f21eb9715f2099c5f8574e4ba7679ff785, rejoin the cluster

Add Worker nodes:

Kubeadm join 192.168.199.173Groupe 6443-token rlxvkn.2ine1loolri50tzt-discovery-token-ca-cert-hash sha256:86e68de8febb844ab8f015f6af4526d78a980d9cdcf7863eebb05b17c24b9383

Add master nodes:

Kubeadm join 192.168.199.173Viru 6443-token rlxvkn.2ine1loolri50tzt-discovery-token-ca-cert-hash sha256:86e68de8febb844ab8f015f6af4526d78a980d9cdcf7863eebb05b17c24b9383-control-plane-certificate-key 440a880086e7e9cbbcebbd7924e6a9562d77ee8de7e0ec63511436f2467f7dde

View a list of new nodes:

Kubectl get node-o wide

If the service is not up, test it:

View the service version, kubectl version

View cluster information, kubectl cluster-info

View service status, sudo systemctl status kubelet

View the service log, journalctl-xefu kubelet

The above is how to change the node name of the Kubernetes cluster. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report