Cordoning and Uncordoning a Kubernetes Node
In the context of Kubernetes, cordoning and uncordoning a node are two distinct operations that allow you to control the scheduling of pods on a specific node.
Cordoning a Node
Cordoning a node is the process of marking a Kubernetes node as unschedulable, which means that no new pods will be scheduled on that node. This is useful when you need to perform maintenance or upgrades on a node, or when you want to drain a node before removing it from the cluster.
When a node is cordoned, the following happens:
- Existing Pods: Existing pods on the cordoned node will continue to run, but no new pods will be scheduled on that node.
- New Pod Scheduling: Kubernetes will not schedule any new pods on the cordoned node, even if the node has available resources.
- Node Labeling: The node will be labeled with the
node.kubernetes.io/unschedulable=true
label, indicating that it is unschedulable.
You can cordon a node using the kubectl cordon <node-name>
command. For example:
$ kubectl cordon node1
node/node1 cordoned
After cordoning a node, you can check its status using the kubectl get nodes
command:
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
node1 Ready,SchedulingDisabled worker 5d v1.19.0
node2 Ready worker 5d v1.19.0
Notice that the STATUS
column for the cordoned node shows Ready,SchedulingDisabled
, indicating that the node is cordoned.
Uncordoning a Node
Uncordoning a node is the process of making a Kubernetes node schedulable again, which means that new pods can be scheduled on that node.
When a node is uncordoned, the following happens:
- Existing Pods: Existing pods on the uncordoned node will continue to run.
- New Pod Scheduling: Kubernetes will resume scheduling new pods on the uncordoned node, based on available resources and scheduling policies.
- Node Labeling: The
node.kubernetes.io/unschedulable=true
label will be removed from the node, indicating that it is schedulable again.
You can uncordon a node using the kubectl uncordon <node-name>
command. For example:
$ kubectl uncordon node1
node/node1 uncordoned
After uncordoning a node, you can check its status using the kubectl get nodes
command:
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
node1 Ready worker 5d v1.19.0
node2 Ready worker 5d v1.19.0
Notice that the STATUS
column for the uncordoned node shows Ready
, indicating that the node is schedulable again.
Mermaid Diagram
Here's a Mermaid diagram that illustrates the difference between cordoning and uncordoning a Kubernetes node:
In summary, cordoning a node marks it as unschedulable, preventing new pods from being scheduled on that node, while uncordoning a node makes it schedulable again, allowing new pods to be scheduled on the node.