14 June 2023
Nodes are usually drained for maintenance or for performing some fixes on the particular node.
kubectl drain NODE_NAME --ignore-daemonsets
--ignore-daemonsets
is a flag to ignore the daemonset pods on the node that is to be drained.
kubectl uncordon NODE_NAME
We will require a 4 node kubernetes cluster with 1 control plane node and 3 worker nodes.
These nodes are named as db1, db2, db3, db4 respectively.
Setup a 4 node kubernetes cluster using the following guide :- https://panchalhimself.github.io/docs/technical/Notes/k8s/k8s-1.3-initialize-and-setup-k8s-cluster.html
1. Check the 4 node setup setup.
kubectl get nodes
command for checking the cluster status.
2. Check the single pod nginx deployment and scale to 30 pods.
kubectl get pods
get list of pods
kubectl scale deployment nginx --replicas=30
to scale the pods to 30 pods from 1 pod.
3. Check the status of the pods over the cluster (sorted by node name)
kubectl get pods -o wide --sort-by="{.spec.nodeName}"
4. drain the node db2
kubectl drain db2 --ignore-daemonsets
5. Check the status of the cluster after draining
kubectl get nodes
6. Check the status of the pods after draining (sorted by node name) and scale up to 50 pods
kubectl get pods -o wide --sort-by="{.spec.nodeName}"
we can observer that all the pods from db2 node have been distributed to db3 and db4 nodes.
On further scaling the pods are assigned to db3 and db4 nodes.
kubectl scale deployment nginx --replicas=50
to scale the pods to 50 pods from 30 pod.
7. Uncordon the db2 node
kubectl uncordon db2
8. Scale down the pods and back up to 20
kubectl scale deployment nginx --replicas=30
to scale the pods to 1 pods from 50 pods.
To check if the db2 node is working as normal we scale down the pods to 1, then we will scale the pods to 20.