Maintenance or abnormal node requires the graceful termination of the pods running on the node. Graceful termination is the operation where pods on the node will complete all running activities (for example serving HTTP requests) before the termination. But however, it’s required to run that pod somewhere else at the same time(evicting the pod).
Kubernetes supports the Node draining functionality through its API. It will evict/ delete the pods except for the mirror pods. Mirror pods are created by a kubelet in the kube-api server for each static pod kubelet created. Static pods are really important in terms of deploying the master components/node components as the pod. Also, the node will be marked not schedulable(unschedulable)to prevent new pods from arriving in draining process.
You can simply use the kubectl to drain the Kubernetes Node.
To drain node01:
$ kubectl drain node01
However, there is a possibility that some of the pods are neither mirror pods nor managed by Kubernetes objects (ReplicaSet, DaemonSet, StatefulSet or Job).
To force delete those pods whose managing resources are missing force option is used.
$ kubectl drain node01 --force
If there are daemonset managed pods, the drain will not proceed without –ignore-daemonsets option. Remember daemonsetController ignores the unschedulable nodes.
$ kubectl drain node01 --ignore-daemonsets
Eventually, there is also possible that pods may be using the local emptyDir volume to store the cache/data. It’s possible to evict those pods while using the –delete-local-data option.
$ kubectl drain node01 --delete-local-data
And sometimes you need combination of several option to drain the node.
$ kubectl drain node01 --ignore-daemonsets --delete-local-data --force