Site icon techbeatly

Remove nodes from Kubespray Managed Kubernetes Cluster

Kubespray is a combination of Ansible and Kubernetes and you can use Kubespray for deploying production ready Kubernetes clusters.

Read how to deploy a Kubernetes cluster using Kubespray.

(Photo by Aneta Foubíková from Pexels)

You can manage full-lifecycle of Kubernetes clusters using Kubespray and in this demo we will see how to remove nodes from existing Kubernetes clusters.

Read how to add new nodes in Kubespray managed Kubernetes Cluster

Also read Adding new nodes in Kubespray Managed Kubernetes Cluster

For the demo, we have a running kubernetes cluster with 1x master node and 3x worker nodes.

gini@greenmango kubespray % kubectl get nodes                                   
NAME       STATUS   ROLES    AGE    VERSION
master-1   Ready    master   4h9m   v1.19.3
node-1     Ready    <none>   4h8m   v1.19.3
node-2     Ready    <none>   4h8m   v1.19.3
node-3     Ready    <none>   82s    v1.19.3

Step 1: Evacuate the Nodes

We will skip this task as we do not have any workload running on the nodes right now. Also, the remove-node.yml will try to drain and evacuate the nodes we pass to playbook.

Note: If you are running workloads on your cluster, you need to evacuate the nodes which you want to remove before this action. You can see the steps for how to evacuate or drain kubernetes cluster nodes in this article.

Step 2: Run remove-node.yml

We will remove node-2 and node-3 for this demo.

gini@greenmango kubespray % ansible-playbook \
  -i inventory/mycluster/hosts.yaml -u devops -b \ 
  remove-node.yml -e "node=node-2,node-3"

Playbook will validate the hosts.yml and cluster details. Playbook will ask for confirmation as well.

.
.
TASK [Set up proxy environment] *************************************************************************
ok: [master-1]
ok: [node-1]
ok: [node-2]
ok: [node-3]
Are you sure you want to delete nodes state? Type 'yes' to delete nodes. [no]: yes
.
.

If the node you want to remove is not online, you should add reset_nodes=false to your extra-vars; -e node=NODE_NAME -e reset_nodes=false. Use this flag even when you remove other types of nodes like a master or etcd nodes.

Wait for playbook to be completed.

Also Read : 10 Tips for CKA & CKAD Exams

Step 3: Verify nodes Kubernetes cluster

Let us see if the nodes the added to Kubernetes cluster.

gini@greenmango kubespray % kubectl get nodes                                                 
NAME       STATUS   ROLES    AGE     VERSION
master-1   Ready    master   4h36m   v1.19.3
node-1     Ready    <none>   4h35m   v1.19.3

Step 4: Remove the node from Inventory

Once you confirm the nodes are removed from cluster, then remove all entries of those nodes from your inventory as well – inventory/mycluster/hosts.yaml.

Learn how to deploy a Kubernetes Cluster using Kubespray.

Exit mobile version