Published on

Draining and Uncordoning Nodes in AKS with kubectl

Authors
  • avatar
    Name
    Alexander Arana Escobedo
    Twitter

Prerequisites

  • Install Azure cli
    • Run az login to authenticate with your Azure account.
    • Install kubectl with az aks install-cli command

Introduction

Maintaining AKS clusters sometimes requires draining nodes — for example, during upgrades, scaling, or when a node experiences hardware problems like disk failures, memory errors, or network instability. Draining safely evicts (removes) pods from a node, allowing Kubernetes to reschedule them elsewhere with minimal downtime. Once maintenance is complete, Uncordoning makes a node schedulable again, allowing Kubernetes to place new pods onto it.

In this post, we'll focus on two essential commands: kubectl drain and kubectl uncordon.

Draining a Node

kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data

Placeholder flags explained:

  • --ignore-daemonsets: (Optional) Skips evicting pods managed by DaemonSets.
    • A DaemonSet ensures a copy of a specific pod runs on every (or selected) node in the cluster, and since these pods stay tied to their nodes without being rescheduled elsewhere, draining operations safely ignore them.
  • --delete-emptydir-data: (Optional) Lets Kubernetes know it’s okay to delete any temporary files stored in emptyDir when the node is drained, since this data is not saved permanently.

The node is now unschedulable and free of most pods, ready for maintenance.

Uncordoning a Node

kubectl uncordon <node-name>

Now, the node is schedulable again, and Kubernetes can place new pods onto it.

I hope this guide helps you out! Now you know how to safely drain and uncordon AKS nodes without disrupting your workloads. If you have any questions, don’t hesitate to reach out! 🙏

Alexander Arana.E