Get up to 50% off on CKA, CKAD, CKS, KCNA, KCSA exams and courses!

Remove nodes from Kubespray Managed Kubernetes Cluster

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

Subscribe to YouTube Channel

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.

Gineesh Madapparambath

Gineesh Madapparambath

Gineesh Madapparambath is the founder of techbeatly. He is the co-author of The Kubernetes Bible, Second Edition and the author of Ansible for Real Life Automation. He has worked as a Systems Engineer, Automation Specialist, and content author. His primary focus is on Ansible Automation, Containerisation (OpenShift & Kubernetes), and Infrastructure as Code (Terraform). (Read more: iamgini.com)


Note

Disclaimer: The views expressed and the content shared in all published articles on this website are solely those of the respective authors, and they do not necessarily reflect the views of the author’s employer or the techbeatly platform. We strive to ensure the accuracy and validity of the content published on our website. However, we cannot guarantee the absolute correctness or completeness of the information provided. It is the responsibility of the readers and users of this website to verify the accuracy and appropriateness of any information or opinions expressed within the articles. If you come across any content that you believe to be incorrect or invalid, please contact us immediately so that we can address the issue promptly.

Share :

Related Posts

How to Increase Attachment File Size Limit in GitLab

How to Increase Attachment File Size Limit in GitLab

We know GitLab is one of the best and easy to use git server solutions available in the market now. And GitLab CE is available as free and we can …

Ansible Automates 2020 on 9th & 10th September

Ansible Automates 2020 on 9th & 10th September

Another good news during this unusual time as Ansible Automate 2020 is a Virtual Event this year and we all will get the chance to attend the same …

How To Add Custom Modules In Ansible

How To Add Custom Modules In Ansible

Image : bsbgroup.com/ Okay, we all know Ansible installation is coming with default modules and you don’t need to download or configure any …