⎈ k8s knowledge compiler

kubectl drain [page]deterministic

Drain node in preparation for maintenance

reference

##

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/ eviction 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 Workflowhttps://kubernetes.io/images/docs/kubectl_drain.svg

``` kubectl drain NODE ```

##

``` # Drain node "foo", even if there are pods not managed by a replication controller, replica set, job, daemon set, or stateful set on it 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 kubectl drain foo --grace-period=900 ```

##

<table style="width: 100%; table-layout: fixed;"> <colgroup> <col span="1" style="width: 10px;" /> <col span="1" /> </colgroup> <tbody>

<tr> <td colspan="2">--chunk-size int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Default: 500</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Return large lists in chunks rather than all at once. Pass 0 to disable.</p></td> </tr>

<tr> <td colspan="2">--delete-emptydir-data</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Continue even if there are pods using emptyDir (local data that will be deleted when the node is drained).</p></td> </tr>

<tr> <td colspan="2">--disable-eviction</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Force drain to use delete, even if eviction is supported. This will bypass checking PodDisruptionBudgets, use with caution.</p></td> </tr>

<tr> <td colspan="2">--dry-run string[="unchanged"]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Default: "none"</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Must be &quot;none&quot;, &quot;server&quot;, or &quot;client&quot;. 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.</p></td> </tr>

<tr> <td colspan="2">--force</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Continue even if there are pods that do not declare a controller.</p></td> </tr>

<tr> <td colspan="2">--grace-period int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Default: -1</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Period of time in seconds given to each pod to terminate gracefully. If negative, the default value specified in the pod will be used.</p></td> </tr>

<tr> <td colspan="2">-h, --help</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>help for drain</p></td> </tr>

<tr> <td colspan="2">--ignore-daemonsets</td> </tr> <tr> <td></td><td style="line-height: 130%; word-wrap: break-word;"><p>Ignore DaemonSet-managed pods.</p></td> </tr>

<tr> <td colspan="2">- …(trimmed)

Sources

reference/kubectl/generated/kubectl_drain/_index.md · dockubectl drain

Related (5)

part_of {{% heading "synopsis" %}}describes conf=1
part_of {{% heading "examples" %}}describes conf=1
part_of {{% heading "options" %}}describes conf=1
part_of {{% heading "parentoptions" %}}describes conf=1
part_of {{% heading "seealso" %}}describes conf=1

← all Docs