Get the FREE Ultimate OpenClaw Setup Guide →

k8s-deploy

Scanned
npx machina-cli add skill agenticdevops/devops-execution-engine/k8s-deploy --openclaw
Files (1)
SKILL.md
6.3 KB

Kubernetes Deployment

Safe deployment practices, rollout strategies, and rollback procedures.

When to Use This Skill

Use this skill when:

  • Deploying new application versions
  • Rolling back failed deployments
  • Scaling applications
  • Managing deployment strategies

Pre-Deployment Checklist

1. Cluster Health Check

# Nodes ready?
kubectl get nodes

# Any problematic pods?
kubectl get pods -A | grep -v Running | grep -v Completed

# Resource availability
kubectl top nodes

2. Image Verification

# Verify image exists (example with Docker Hub)
docker manifest inspect <image>:<tag>

# Check current image
kubectl get deployment <name> -o jsonpath='{.spec.template.spec.containers[0].image}'

3. Current State Backup

# Save current deployment spec
kubectl get deployment <name> -o yaml > deployment-backup.yaml

# Note current revision
kubectl rollout history deployment/<name>

Deployment Methods

Update Image (Most Common)

# Update container image
kubectl set image deployment/<name> <container>=<image>:<tag>

# Example
kubectl set image deployment/nginx nginx=nginx:1.25

# Watch rollout
kubectl rollout status deployment/<name>

Apply Manifest

# Dry-run first (ALWAYS)
kubectl apply -f deployment.yaml --dry-run=client

# Show diff
kubectl diff -f deployment.yaml

# Apply
kubectl apply -f deployment.yaml

# Watch
kubectl rollout status deployment/<name>

Patch Deployment

# Strategic merge patch
kubectl patch deployment <name> -p '{"spec":{"replicas":5}}'

# JSON patch
kubectl patch deployment <name> --type='json' \
  -p='[{"op":"replace","path":"/spec/replicas","value":5}]'

Rollout Management

Check Rollout Status

# Status
kubectl rollout status deployment/<name>

# History
kubectl rollout history deployment/<name>

# Specific revision details
kubectl rollout history deployment/<name> --revision=2

Pause/Resume Rollout

# Pause (for canary-style manual control)
kubectl rollout pause deployment/<name>

# Resume
kubectl rollout resume deployment/<name>

Rollback

# Rollback to previous version
kubectl rollout undo deployment/<name>

# Rollback to specific revision
kubectl rollout undo deployment/<name> --to-revision=2

# Verify rollback
kubectl rollout status deployment/<name>

Scaling

Manual Scaling

# Scale replicas
kubectl scale deployment/<name> --replicas=5

# Scale multiple
kubectl scale deployment/<name1> deployment/<name2> --replicas=3

Autoscaling (HPA)

# Create HPA
kubectl autoscale deployment/<name> --min=2 --max=10 --cpu-percent=80

# Check HPA status
kubectl get hpa

# Describe HPA
kubectl describe hpa <name>

Deployment Strategies

Rolling Update (Default)

spec:
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 25%        # Max pods over desired
      maxUnavailable: 25%  # Max pods unavailable
# Check current strategy
kubectl get deployment <name> -o jsonpath='{.spec.strategy}'

Recreate

spec:
  strategy:
    type: Recreate  # Kill all, then create new

Blue-Green (Manual)

# Deploy new version with different label
kubectl apply -f deployment-v2.yaml

# Verify v2 is healthy
kubectl get pods -l version=v2

# Switch service to v2
kubectl patch service <name> -p '{"spec":{"selector":{"version":"v2"}}}'

# Rollback: switch back to v1
kubectl patch service <name> -p '{"spec":{"selector":{"version":"v1"}}}'

Canary (Manual)

# Scale down main, scale up canary
kubectl scale deployment/<name>-main --replicas=9
kubectl scale deployment/<name>-canary --replicas=1

# Monitor canary metrics, then promote or rollback

Post-Deployment Verification

Health Checks

# Pods running?
kubectl get pods -l app=<name>

# Ready and healthy?
kubectl get deployment <name>

# Events (errors?)
kubectl get events --field-selector involvedObject.name=<deployment> --sort-by='.lastTimestamp'

Smoke Tests

# Port-forward and test
kubectl port-forward deployment/<name> 8080:80 &
curl localhost:8080/health

# Or exec into pod
kubectl exec -it deployment/<name> -- curl localhost/health

Compare Metrics

# Check resource usage
kubectl top pods -l app=<name>

# Compare with previous
# (Use your monitoring: Prometheus, Datadog, etc.)

Troubleshooting Failed Deployments

Deployment Stuck

# Check rollout status
kubectl rollout status deployment/<name>

# Check events
kubectl describe deployment <name>

# Check pod issues
kubectl get pods -l app=<name>
kubectl describe pod <problematic-pod>

Common Issues

SymptomCheckFix
ImagePullBackOffImage name/tag, registry authFix image reference
CrashLoopBackOffPod logsFix application error
Pending podsNode resources, PVCScale cluster or fix storage
Readiness probe failingApp startup timeAdjust probe timing

Emergency Rollback

# Immediate rollback
kubectl rollout undo deployment/<name>

# If that fails, scale to zero then restore from backup
kubectl scale deployment/<name> --replicas=0
kubectl apply -f deployment-backup.yaml

Safe Deployment Workflow

# 1. Pre-flight
kubectl get nodes && kubectl top nodes

# 2. Backup current state
kubectl get deployment <name> -o yaml > backup.yaml

# 3. Dry-run
kubectl apply -f new-deployment.yaml --dry-run=client

# 4. Show diff
kubectl diff -f new-deployment.yaml

# 5. Apply with record
kubectl apply -f new-deployment.yaml

# 6. Watch rollout
kubectl rollout status deployment/<name> --timeout=5m

# 7. Verify health
kubectl get pods -l app=<name>
kubectl logs -l app=<name> --tail=20

# 8. If issues: rollback
kubectl rollout undo deployment/<name>

Related Skills

  • k8s-debug: For troubleshooting deployment issues
  • argocd-gitops: For GitOps-based deployments
  • incident-response: When deployments cause incidents

Source

git clone https://github.com/agenticdevops/devops-execution-engine/blob/main/skills/k8s-deploy/SKILL.mdView on GitHub

Overview

Kubernetes Deployment covers safe deployment practices, rollout strategies, and rollback procedures. It guides you through pre-deployment checks, image verification, and backing up current state, then explains how to deploy changes via image updates, manifests, or patches. It also outlines scaling and strategy options to minimize risk.

How This Skill Works

Technically, you perform pre-deployment checks, verify images, and back up the current deployment. You then deploy using update image, apply manifest, or patch, and monitor the rollout with status commands, pausing or resuming as needed. Rollback and scaling commands enable safe recovery and controlled rollout across strategies.

When to Use It

  • Deploying new application versions
  • Rolling back failed deployments
  • Scaling applications
  • Managing deployment strategies (RollingUpdate, Recreate, Blue-Green, Canary)
  • Verifying rollout health and stability

Quick Start

  1. Step 1: Run pre-deployment checks (cluster health, image verification, and backup of the current deployment).
  2. Step 2: Deploy the change via a chosen method (update image, apply manifest, or patch) and perform a dry-run if possible, then apply.
  3. Step 3: Monitor the rollout with kubectl rollout status and rollback if issues are detected.

Best Practices

  • Run pre-deployment cluster health checks (nodes, pods, resources) before changes.
  • Verify the target image exists and confirm the current deployment image before updating.
  • Back up the current deployment state and review rollout history prior to changes.
  • Always perform a dry-run and diff before applying manifests, then apply and monitor rollout.
  • Monitor rollout status and be prepared to rollback (undo or to a specific revision) if issues arise.

Example Use Cases

  • Update a deployment's container image (e.g., nginx:1.25) and monitor the rollout until complete.
  • Apply a new deployment.yaml after a dry-run and diff, then watch the rollout status.
  • Rollback a failed deployment to the previous revision using kubectl rollout undo.
  • Manually scale a deployment to 5 replicas and verify stability via rollout status.
  • Blue-Green: deploy a v2 version, switch the service selector to version v2, and rollback by switching back to v1 if needed.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers