Ansible / Automation / DevOps / Kubernetes
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
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.
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
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
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.
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.
Gineesh Madapparambath
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 - iamgini.com)
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Leave a Reply