Skip to content

Remove nodes from Kubespray Managed Kubernetes Cluster

Avatar photo

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


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.

Avatar photo
Gineesh Madapparambath is the founder of techbeatly and he is the co-author of The Kubernetes Bible, Second Edition. and the author of ๐—”๐—ป๐˜€๐—ถ๐—ฏ๐—น๐—ฒ ๐—ณ๐—ผ๐—ฟ ๐—ฅ๐—ฒ๐—ฎ๐—น-๐—Ÿ๐—ถ๐—ณ๐—ฒ ๐—”๐˜‚๐˜๐—ผ๐—บ๐—ฎ๐˜๐—ถ๐—ผ๐—ป. 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). (aka Gini Gangadharan -


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.