Kubernetes: Manage Nodes with drain, cordon, and uncordon Commands

Claire Lee
4 min readMar 18, 2023

--

The drain, cordon, and uncordon commands are used in Kubernetes to manage nodes during maintenance or to temporarily take them offline. The drain command is used to gracefully remove a node from service by evicting all pods running on that node, scheduling them onto other available nodes and preventing new pods from being scheduled. The cordon command is used to temporarily disable scheduling new pods on a node, while allowing existing pods to continue running until they complete. The uncordon enables the scheduling of new pods onto a previously drained or cordoned node. These commands help ensure that workloads are safely migrated and prevent disruption to end-users during maintenance.

Kubernetes: Manage Nodes with drain, cordon, and uncordon Commands

drain, cordon, and uncordon are commands used in Kubernetes for managing nodes during maintenance or for temporarily taking them offline.

drain Command

$ kubectl drain <node_name>
$ kubectl drain <node_name> --ignore-daemonsets

--ignore-daemonsets option: Tell Kubernetes to ignore the DaemonSet pods running on the node being drained and only evict the other pods running on that node.

The drain command in Kubernetes is used to gracefully remove a node from service. Think of it as a way of temporarily taking a node offline for maintenance or when it is experiencing issues. When a node is drained, all the pods running on that node are evicted and scheduled onto other available nodes. At the same time, it also prevents new pods from being scheduled on that node. Therefore, it allows system administrators to take nodes offline for maintenance or repair, without causing any downtime or disruption to the end-users.

Analogy

Imagine a busy restaurant kitchen with multiple cooking stations, each managed by a different chef. Now, let’s say that one of the cooking stations needs maintenance, and the chef in charge of that station needs to take it offline temporarily. In order to do this, the chef needs to ensure that all the dishes originally assigned to that station are safely transferred to other stations, so that they can be completed without any delays.

cordon Command

$ kubectl cordon <node_name>

The cordon command in Kubernetes is used to mark a node as unschedulable. This means that no new pods will be scheduled on that node, but the existing pods will continue to run on it. This can be useful in situations where maintenance is required, resources are scarce, troubleshooting is needed, or scaling down is necessary.

Analogy

In a busy restaurant kitchen, each chef is responsible for a different cooking station. When one chef needs to take a break or leave early, their station is temporarily closed. To do this, the chef would “cordon off” their station, preventing any new orders from being taken. Existing orders would continue cooking until completed, gradually moving the workload off the station while fulfilling orders already in progress.

uncordon Command

$ kubectl uncordon <node_name>

The uncordon command is used to reverse the effects of cordon and mark a previously unschedulable node as schedulable again. Once uncordoned, the node can accept new pods for scheduling.

Anology

Continuing with the analogy of a busy restaurant kitchen, a chef resumes work at their station in a restaurant. They mark their station as available, customers can place new orders, and the workload gradually returns to the station until it is fully operational again.

Node Status Changes

  • drain: Ready → Ready, SchedulingDisabled
  • cordon: Ready → Ready, SchedulingDisabled
  • uncordon: Ready, SchedulingDisabled → Ready
node status change

--

--

Claire Lee
Claire Lee

Responses (1)