drain-node

X-McKay's avatarfrom X-McKay

Safely evict all pods from a node for maintenance. Cordons the node first, then evicts pods respecting PodDisruptionBudgets. Use before node maintenance or decommissioning. Keywords: drain, evict, node maintenance, pod migration.

⭐1stars🔀0forks📁View on GitHub🕐Updated Jan 11, 2026

When & Why to Use This Skill

This Claude skill automates the Kubernetes node draining process, ensuring safe pod eviction and workload migration during maintenance or decommissioning. It follows SRE best practices by cordoning nodes first and respecting PodDisruptionBudgets (PDBs) to maintain high availability and prevent service disruptions.

Use Cases

  • Scheduled Hardware Maintenance: Safely clear a physical or virtual node of all workloads before performing hardware repairs or firmware updates.
  • Cluster Scaling and Decommissioning: Gracefully migrate pods to other nodes when downsizing a cluster or replacing outdated instances to ensure zero downtime.
  • Node OS and Kernel Upgrades: Automate the preparation of nodes for operating system patches or Kubernetes version upgrades by evacuating active pods.
  • Troubleshooting and Remediation: Quickly isolate a problematic node by moving all non-essential workloads to healthy nodes for further investigation and debugging.
namedrain-node
description>
or decommissioning. Keywordsdrain, evict, node maintenance, pod migration.
domaink8s
categoryremediation
requires-approvaltrue
confidence0.8

Drain Node

Preconditions

Before applying this skill, verify:

  • Node name is known
  • Other nodes have capacity for evicted pods
  • PodDisruptionBudgets won't block critical evictions
  • DaemonSet pods are acceptable to ignore

Actions

1. Cordon the Node First

Prevent new pods from scheduling.

mcp_tool: kubernetes-mcp-server/resources_create_or_update
params:
  resource: |
    apiVersion: v1
    kind: Node
    metadata:
      name: $node_name
    spec:
      unschedulable: true
timeout: 30s

2. Get Pods on Node

List all pods running on the node.

mcp_tool: kubernetes-mcp-server/pods_list
params:
  labelSelector: ""
timeout: 30s

3. Evict Each Pod

Delete pods to trigger rescheduling (skip DaemonSets).

mcp_tool: kubernetes-mcp-server/pods_delete
params:
  name: $pod_name
  namespace: $pod_namespace
timeout: 30s

4. Verify Node is Drained

Confirm only DaemonSet pods remain.

mcp_tool: kubernetes-mcp-server/pods_list
params:
  labelSelector: ""
timeout: 30s

Success Criteria

The skill succeeds when:

  • Node is cordoned
  • All non-DaemonSet pods evicted
  • Evicted pods rescheduled elsewhere
  • No unexpected errors during eviction

Failure Handling

If draining fails:

  1. Check PodDisruptionBudget constraints
  2. Identify stuck pods (finalizers, etc.)
  3. May need to force delete specific pods
  4. Uncordon if drain aborted

Examples

Input Context:

{
  "node_name": "worker-node-3",
  "ignore_daemonsets": true,
  "force": false
}

Output:

{
  "node": "worker-node-3",
  "pods_evicted": 12,
  "daemonset_pods_skipped": 3,
  "pods_rescheduled": 12,
  "success": true
}