Cordoning Nodes with kubectl
Cordoning a Node
To cordon a Node in Kubernetes, you can use the kubectl cordon
command. For example, to cordon a Node named node1
, you can run the following command:
kubectl cordon node1
This will mark the Node as unschedulable, and new Pods will not be placed on it.
You can also cordon multiple Nodes at once by specifying multiple Node names:
kubectl cordon node1 node2 node3
Verifying Node Cordoning
To verify that a Node has been cordoned, you can use the kubectl get nodes
command. The output will show the Node with the SchedulingDisabled
condition:
NAME STATUS ROLES AGE VERSION
node1 Ready,SchedulingDisabled <none> 1d v1.20.0
node2 Ready <none> 1d v1.20.0
node3 Ready,SchedulingDisabled <none> 1d v1.20.0
You can also use the kubectl describe node
command to get more detailed information about a Node's status:
kubectl describe node node1
This will show the SchedulingDisabled
condition in the Node's status.
Uncordoning a Node
To uncordon a Node and make it schedulable again, you can use the kubectl uncordon
command:
kubectl uncordon node1
This will remove the SchedulingDisabled
condition from the Node, and it will be able to accept new Pods again.
As with cordoning, you can also uncordon multiple Nodes at once:
kubectl uncordon node1 node2 node3
Cordoning and Draining Nodes
Cordoning a Node is often the first step in the process of draining a Node. Draining a Node means safely evicting all the Pods running on that Node, so that the Node can be safely decommissioned or upgraded.
To drain a Node, you can use the kubectl drain
command:
kubectl drain node1
This will cordon the Node and then evict all the Pods running on it, moving them to other Nodes in the cluster.