Let’s Learn About Kubernetes Drain with it’s Illustration:

Reading Time: 3 minutes
How to Drain Nodes in Kubernetes With kubectl drain Command

Kubernetes Drain , Hello Readers…In my previous blog we have learn about the commands of cordon. Now Let’s learn about What is Drain in kubernetes.

What is Kubernetes Drain??

We use drain to safely evict all of our pods from a node before you perform maintenance on the node. (e.g. Kernal upgrade, hardware maintenance etc.)

When you drain a node, the scheduler will schedule the evicted pods on different nodes. If there is only one node, if kubernetes delete the pods.

If there are pods controlled by daemon sets they cannot be evicted as they will be scheduled on the same nodes again and again.

So these pods are ignored. We use –force flag to delete it forcefully.

When you drain a node, the node is first cordoned to avoid scheduling of pods during eviction. Then the pods running are evicted.

What is the purpose of node draining?

The node draining allows users to gracefully move all containers from one node to the other ones.

Illustration of Drain:

Note: update your minikube or start your minikube.

1} kubectl get pods

2} kubectl drain minikube

3} kubectl get nodes

4} kubectl drain minikube –ignore-daemonsets –force

5} kubectl get pods

6} kubectl uncordon minikube

7} kubectl get pods

8} kubectl get nodes

9} kubectl drain minikube

10} kubectl drain minikube –ignore-daemonsets –force

The “drain” is waiting for a proper termination. Do not operate the machine until the command is complete.This is all about the Drain in kubernetes.

Hope this blog will helpfull.

Happy Learning



Written by 

Mayuri Dhote is a Software Consultant at Knoldus Software. She has completed her MCA from VIT University. She has very dedicated towards her work. She has always ready to learn new things. Her practice area is Devops. When not working, you will find her writing poems and poetry.