← Back to blog

Runbook Automation for Kubernetes

· 3 min read · Stew Team
runbook automationkubernetesdevopsSRE

Kubernetes operations involve repetitive, error-prone commands. Pod debugging, deployment rollbacks, and scaling operations follow predictable patterns—patterns that should be automated.

This guide shows how runbook automation tools can streamline your Kubernetes workflows.

Why Kubernetes Needs Runbook Automation

Kubernetes commands are verbose and context-dependent:

kubectl get pods -n production -l app=api -o wide
kubectl describe pod api-7d4f8b6c9-x2k4j -n production
kubectl logs api-7d4f8b6c9-x2k4j -n production --tail=100

During an incident, you’re running these commands repeatedly, changing namespaces, pod names, and flags. Mistakes happen. A runbook automation tool eliminates the friction.

Essential Kubernetes Runbooks

1. Pod Health Check

A basic runbook for checking pod status:

# Pod Health Check

## Set Context

​```bash
export NAMESPACE=production
export APP=api
​```

## Check Pod Status

​```bash
kubectl get pods -n $NAMESPACE -l app=$APP
​```

## Get Pod Details

​```bash
kubectl describe pods -n $NAMESPACE -l app=$APP
​```

## Check Recent Logs

​```bash
kubectl logs -n $NAMESPACE -l app=$APP --tail=50
​```

With a runbook automation tool like Stew, each block executes independently while sharing environment variables.

2. Deployment Rollback

When a bad deployment goes out:

# Deployment Rollback

## Check Current Status

​```bash
kubectl rollout status deployment/$DEPLOYMENT -n $NAMESPACE
​```

## View Rollout History

​```bash
kubectl rollout history deployment/$DEPLOYMENT -n $NAMESPACE
​```

## Rollback to Previous Version

​```bash
kubectl rollout undo deployment/$DEPLOYMENT -n $NAMESPACE
​```

## Verify Rollback

​```bash
kubectl rollout status deployment/$DEPLOYMENT -n $NAMESPACE
​```

3. Resource Scaling

For handling load spikes:

# Scale Deployment

## Current Replica Count

​```bash
kubectl get deployment $DEPLOYMENT -n $NAMESPACE -o jsonpath='{.spec.replicas}'
​```

## Scale Up

​```bash
kubectl scale deployment $DEPLOYMENT -n $NAMESPACE --replicas=$REPLICAS
​```

## Watch Scaling Progress

​```bash
kubectl get pods -n $NAMESPACE -l app=$APP -w
​```

4. Node Troubleshooting

When nodes are unhealthy:

# Node Troubleshooting

## List Node Status

​```bash
kubectl get nodes -o wide
​```

## Check Node Conditions

​```bash
kubectl describe node $NODE_NAME | grep -A 10 "Conditions:"
​```

## Get Pods on Node

​```bash
kubectl get pods --all-namespaces -o wide --field-selector spec.nodeName=$NODE_NAME
​```

## Check Node Resources

​```bash
kubectl top node $NODE_NAME
​```

Benefits of Automated Kubernetes Runbooks

Reduced Context Switching

Instead of remembering kubectl flags, you execute pre-built runbooks. Mental energy goes to problem-solving, not command syntax.

Consistent Execution

Every engineer runs the same commands in the same order. No more “works on my machine” variations.

Onboarding Acceleration

New team members execute complex Kubernetes operations on day one. The runbook encodes expert knowledge.

Audit Compliance

Every command execution is logged. For regulated industries, this audit trail is essential.

Choosing a Runbook Automation Tool for Kubernetes

When evaluating tools, consider:

  1. SSH support — Can you run kubectl from bastion hosts?
  2. Variable injection — Can you parameterize namespaces, deployments, pod names?
  3. Output capture — Can you see kubectl output inline?
  4. Portability — Does it work across clusters and environments?

Stew for Kubernetes Operations

Stew is designed for exactly this use case. Write your Kubernetes runbooks in Markdown, execute them anywhere:

  • Local terminal with your kubeconfig
  • SSH to a bastion host
  • Web interface for on-call engineers

Join the waitlist and bring runbook automation to your Kubernetes workflows.