drain

Drain node “foo”, even if there are pods not managed by a replication controller, replica set, job, daemon set or stateful set on it

  1. kubectl drain foo --force

As above, but abort if there are pods not managed by a replication controller, replica set, job, daemon set or stateful set, and use a grace period of 15 minutes

  1. kubectl drain foo --grace-period=900

Drain node in preparation for maintenance.

The given node will be marked unschedulable to prevent new pods from arriving. ‘drain’ evicts the pods if the API server supports https://kubernetes.io/docs/concepts/workloads/pods/disruptions/ . Otherwise, it will use normal DELETE to delete the pods. The ‘drain’ evicts or deletes all pods except mirror pods (which cannot be deleted through the API server). If there are daemon set-managed pods, drain will not proceed without —ignore-daemonsets, and regardless it will not delete any daemon set-managed pods, because those pods would be immediately replaced by the daemon set controller, which ignores unschedulable markings. If there are any pods that are neither mirror pods nor managed by a replication controller, replica set, daemon set, stateful set, or job, then drain will not delete any pods unless you use —force. —force will also allow deletion to proceed if the managing resource of one or more pods is missing.

‘drain’ waits for graceful termination. You should not operate on the machine until the command completes.

When you are ready to put the node back into service, use kubectl uncordon, which will make the node schedulable again.

https://kubernetes.io/images/docs/kubectl_drain.svg

Usage

$ kubectl drain NODE

Flags

NameShorthandDefaultUsage
chunk-size500Return large lists in chunks rather than all at once. Pass 0 to disable. This flag is beta and may change in the future.
delete-emptydir-datafalseContinue even if there are pods using emptyDir (local data that will be deleted when the node is drained).
delete-local-datafalseContinue even if there are pods using emptyDir (local data that will be deleted when the node is drained).
disable-evictionfalseForce drain to use delete, even if eviction is supported. This will bypass checking PodDisruptionBudgets, use with caution.
dry-runnoneMust be “none”, “server”, or “client”. If client strategy, only print the object that would be sent, without sending it. If server strategy, submit server-side request without persisting the resource.
forcefalseContinue even if there are pods not managed by a ReplicationController, ReplicaSet, Job, DaemonSet or StatefulSet.
grace-period-1Period of time in seconds given to each pod to terminate gracefully. If negative, the default value specified in the pod will be used.
ignore-daemonsetsfalseIgnore DaemonSet-managed pods.
ignore-errorsfalseIgnore errors occurred between drain nodes in group.
pod-selectorLabel selector to filter pods on the node
selectorlSelector (label query) to filter on
skip-wait-for-delete-timeout0If pod DeletionTimestamp older than N seconds, skip waiting for the pod. Seconds must be greater than 0 to skip.
timeout0sThe length of time to wait before giving up, zero means infinite