[Kubernetes (K8S) Kubespray] Use Kubespray to add or remove work node into the exist kubernetes (K8S) cluster
Add or remove work node into the exist kubernetes (K8S) cluster
This should be the easiest with Kubespray.
Usages
First, check current all node status(2 nodes, 2 control-plane,master nodes, without work node):
1 | kubectl get nodes |
Add a new work node
Add the new work node into kubernetes (K8S) cluster.
1) Add new node to the inventory
Edit inventory/mycluster/hosts.yaml
file to add node3
host.
1 | all: |
2) Run scale.yml
Run ansible-playbook
command with scale.yml
and --limit=node3
.
1 | ansible-playbook -i inventory/mycluster/hosts.yaml scale.yml --limit=node3 |
You can use --limit=NODE_NAME
to limit Kubespray to avoid disturbing other nodes in the cluster.
Before using --limit
run playbook facts.yml
without the limit
to refresh facts cache for all nodes.
3) Check current node status
Check current all node status(3 nodes, 2 control-plane,master nodes, 1 work node):
1 | kubectl get nodes |
Remove the work node
Remove the work node from kubernetes (K8S) cluster.
1) Run remove-node.yml
Run ansible-playbook
command with remove-node.yml
and --e=node=node3
.
1 | ansible-playbook -i inventory/mycluster/hosts.yaml remove-node.yml -e node=node3 |
With the old node still in the inventory, run remove-node.yml
. You need to pass -e node=NODE_NAME
to the playbook to limit the execution to the node being removed.
If the node you want to remove is not online, you should add reset_nodes=false
and allow_ungraceful_removal=true
to your extra-vars: -e node=NODE_NAME -e reset_nodes=false -e allow_ungraceful_removal=true
. Use this flag even when you remove other types of nodes like a control plane or etcd nodes.
2) Check current node status
check current all node status(2 nodes, 2 control-plane,master nodes, without work node):
1 | kubectl get nodes |
3) Remove the node from the inventory
Edit inventory/mycluster/hosts.yaml
file to remove node3
host.
1 | all: |
References
[1] Adding/replacing a node - https://kubespray.io/#/docs/nodes
[3] Getting started - https://kubespray.io/#/docs/getting-started
[3] Deploy a Production Ready Kubernetes Cluster | Readme - https://kubespray.io/
[4] Ansible is Simple IT Automation - https://www.ansible.com/