[Kubernetes (K8S) Kubespray] Use Kubespray to add or remove control-plane,master node into the exist kubernetes (K8S) cluster
Add or remove control-plane,master node into the exist kubernetes (K8S) cluster
This still be the easiest with Kubespray.
Usages
First, check current all node status(2 nodes, 2 control-plane,master nodes):
1 | kubectl get nodes |
Add a new control-plane,master node
Add the new control-plane,master into kubernetes (K8S) cluster.
1) Add a new node to the inventory
Edit inventory/mycluster/hosts.yaml
file to add node3
host.
1 | all: |
2) Run cluster.yml
Run ansible-playbook
command with cluster.yml
and --limit=node3
.
1 | ansible-playbook -i inventory/mycluster/hosts.yaml cluster.yml |
Append the new host to the inventory and run cluster.yml
. You can NOT use scale.yml
for that.
3) Restart Docker or kube-system/nginx-proxy
In all hosts, restart docker or reboot the host. Kubespray will update its static config, but it needs to be restarted in order to reload.
1 | systemctl restart docker |
4) Check current node status
check current all node status(3 nodes, 3 control-plane,master nodes):
1 | kubectl get nodes |
Remove the control-plane,master node
Remove the control-plane,master 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
.
2) Check current node status
Check current all node status(2 nodes, 2 control-plane,master nodes, without work node):
1 | kubectl get nodes |
1) Remove the control-plane,master from the inventory
Edit inventory/mycluster/hosts.yaml
file to remove node3
host.
1 | all: |
FAQs
Check apiserver Certificate
1 | On all nodes, check apiserver Certificate. |
Update apiserver Certificate
1 | On control-plane,master nodes |
error downloading certs
1 | error execution phase control-plane-prepare/download-certs: error downloading certs: error downloading the secret: Secret \"kubeadm-certs\" was not found in the \"kube-system\" Namespace. This Secret might have expired. Please, run `kubeadm init phase upload-certs --upload-certs` on a control plane to generate a new one |
Manually upload Certificate.
1 | On control-plane,master nodes |
Run reset.yml
If you are doing this after you ended up with a broken master, be sure to run reset.yml
using the parameter --limit=<broken_master_hostname>
before continuing. If you take the precaution of recreating the certificate before adding the new master node, you won’t need this.
Run ansible-playbook
command with reset.yml
and --limit=node3
.
1 | ansible-playbook -i inventory/mycluster/hosts.yaml reset.yml --limit=node3 |
You should use --limit=NODE_NAME
to limit Kubespray to avoid disturbing other nodes in the cluster.
References
[1] Adding/replacing a node - https://kubespray.io/#/docs/nodes
[3] Getting started - https://kubespray.io/#/docs/getting-started
[4] Deploy a Production Ready Kubernetes Cluster | Readme - https://kubespray.io/
[5] Ansible is Simple IT Automation - https://www.ansible.com/