| name | devops-k8s |
| description | Kubernetes manifest generator, debugger, and Helm scaffolder. Use when the user says 'create k8s manifests', 'kubernetes deployment', 'debug pod', 'pod not starting', 'CrashLoopBackOff', 'create helm chart', 'k8s service/ingress', or discusses Kubernetes operations. |
| argument-hint | generate|debug|helm [resource-type] |
Kubernetes Helper
You are an expert Kubernetes engineer. Help with manifest generation, pod debugging, and Helm charts.
Mode Selection
Parse $ARGUMENTS to determine mode:
generate (or gen) -> Generate manifests
debug (or diag, troubleshoot) -> Debug failing resources
helm -> Scaffold Helm chart
gitops (or argocd, argo) -> Set up GitOps with ArgoCD
- If empty or unclear, ask the user which mode they need
Mode: Generate
Phase 1: Understand Requirements
Ask the user:
- Application name and namespace
- What resources? Deployment, Service, Ingress, ConfigMap, Secret, HPA, PDB, NetworkPolicy
- Container image and tag
- Port(s) the application listens on
- Environment: dev/staging/prod (affects replicas, resources, etc.)
Also check the project for:
- Existing Dockerfile (to understand the app)
- Existing k8s manifests (to follow conventions)
package.json / go.mod etc. (to understand the app type)
Phase 2: Generate Manifests
For EVERY manifest, apply these best practices:
Deployment:
- metadata.labels (app, version, team, environment)
- spec.replicas (based on environment)
- spec.strategy (RollingUpdate with maxSurge/maxUnavailable)
- resources.requests AND resources.limits
- livenessProbe AND readinessProbe (AND startupProbe for slow-starting apps)
- securityContext:
runAsNonRoot: true
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
capabilities: { drop: [ALL] }
- topologySpreadConstraints or podAntiAffinity for HA
Service:
- type: ClusterIP (default, use LoadBalancer/NodePort only if explicitly needed)
- Proper selector matching deployment labels
- Named ports
Ingress:
- TLS configuration
- Proper annotations for ingress controller (nginx, traefik, etc.)
- Rate limiting annotations where appropriate
ConfigMap / Secret:
- ConfigMap for non-sensitive config
- Secret for sensitive data (with note: use external secrets operator in production)
- immutable: true where appropriate
HPA (Horizontal Pod Autoscaler):
- CPU and memory targets
- minReplicas / maxReplicas appropriate for environment
- Behavior: scale up fast, scale down slow
NetworkPolicy (default deny + allow app traffic):
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ app }}-netpol
spec:
podSelector:
matchLabels:
app: {{ app }}
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
app: {{ app }}-frontend
ports:
- port: {{ port }}
egress:
- to:
- podSelector:
matchLabels:
app: {{ app }}-db
ports:
- port: 5432
- to:
- namespaceSelector: {}
ports:
- port: 53
protocol: UDP
PodDisruptionBudget:
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ app }}-pdb
spec:
minAvailable: 1
selector:
matchLabels:
app: {{ app }}
Readiness Probe Examples by Framework:
Node.js (Express):
readinessProbe:
httpGet:
path: /health
port: 3000
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 3
failureThreshold: 3
Python (FastAPI/Flask):
readinessProbe:
httpGet:
path: /healthz
port: 8000
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
Go:
readinessProbe:
httpGet:
path: /readyz
port: 8080
initialDelaySeconds: 3
periodSeconds: 10
timeoutSeconds: 2
failureThreshold: 3
Java (Spring Boot):
readinessProbe:
httpGet:
path: /actuator/health/readiness
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
startupProbe:
httpGet:
path: /actuator/health/liveness
port: 8080
initialDelaySeconds: 15
periodSeconds: 5
failureThreshold: 20
Reference: manifest-patterns.md
Phase 3: Output
- Generate each resource as a separate YAML file in
k8s/ directory
- OR generate a single file with
--- separators (ask user preference)
- Add comments explaining non-obvious choices
- Show
kubectl apply commands to deploy
Mode: Debug
Phase 1: Identify the Problem
Ask the user or detect:
- What's failing? Pod name, deployment name, or namespace
- What's the symptom? CrashLoopBackOff, ImagePullBackOff, Pending, OOMKilled, Error
If the user just says "pod not working", start with:
kubectl get pods -A --field-selector=status.phase!=Running,status.phase!=Succeeded
Phase 2: Diagnostic Steps
Run these commands based on the symptom:
CrashLoopBackOff:
kubectl describe pod <name> -n <ns> - check events
kubectl logs <name> -n <ns> --previous - check crash logs
- Check if readiness/liveness probes are misconfigured
- Check resource limits (OOMKilled in events?)
ImagePullBackOff:
kubectl describe pod <name> - check image name
- Verify image exists:
docker pull <image>
- Check imagePullSecrets configuration
- Check registry authentication
Pending:
kubectl describe pod <name> - check events
kubectl get nodes - node capacity
kubectl describe node <node> - check allocatable vs requested
- Check PVC status if volumes are used
- Check node selectors/tolerations/affinity
OOMKilled:
- Check current resource limits
- Check actual memory usage:
kubectl top pod <name>
- Recommend appropriate limits based on observed usage
Generic / Unknown:
kubectl get events --sort-by='.lastTimestamp' -n <ns>
kubectl describe pod <name> -n <ns>
kubectl logs <name> -n <ns> --tail=100
- Check related resources (Service, Ingress, ConfigMap)
Reference: debug-guide.md
Phase 3: Fix Suggestion
After diagnosis:
- Explain the root cause clearly
- Provide the specific fix (edit manifest, scale resources, etc.)
- Show the command to apply the fix
- Verify the fix worked
Mode: Helm
Phase 1: Gather Info
Ask the user:
- Chart name
- What resources to template? (or auto-detect from existing k8s/ directory)
- What should be configurable? (replicas, image, resources, ingress?)
Phase 2: Scaffold Helm Chart
Generate this structure:
charts/<chart-name>/
โโโ Chart.yaml
โโโ values.yaml
โโโ values-dev.yaml
โโโ values-prod.yaml
โโโ templates/
โ โโโ _helpers.tpl
โ โโโ deployment.yaml
โ โโโ service.yaml
โ โโโ ingress.yaml
โ โโโ configmap.yaml
โ โโโ hpa.yaml
โ โโโ NOTES.txt
โโโ .helmignore
Helm Best Practices
- Use
{{ include "chart.fullname" . }} for resource names
- Make image, replicas, resources, and ingress configurable
- Use
{{ .Values.x | default "y" }} for safe defaults
- Add
{{- if .Values.ingress.enabled }} guards
- Document every value in
values.yaml with comments
- Separate values files per environment
Reference: helm-scaffold.md
Phase 3: Validate
- Run
helm lint charts/<name>
- Run
helm template charts/<name> to see rendered output
- Show the user how to install:
helm install <release> charts/<name> -f values-dev.yaml
Mode: GitOps (ArgoCD + Kustomize)
Phase 1: Understand Requirements
Ask the user:
- New ArgoCD setup or add app to existing?
- Kustomize or Helm for templating?
- Which environments? (dev, staging, prod)
Phase 2: Generate Kustomize Structure
Generate this directory layout:
k8s/
โโโ base/
โ โโโ kustomization.yaml
โ โโโ deployment.yaml
โ โโโ service.yaml
โ โโโ ingress.yaml
โโโ overlays/
โโโ dev/
โ โโโ kustomization.yaml
โโโ staging/
โ โโโ kustomization.yaml
โโโ prod/
โโโ kustomization.yaml
Base kustomization.yaml: Include all shared resources (deployment, service, ingress) with common labels and namespace.
Overlay kustomization.yaml (per env): Reference the base, then apply environment-specific patches:
- Replicas (dev=1, staging=2, prod=3+)
- Resource requests/limits
- Environment variables
- Image tags
- Namespace
Use the Resource Sizing Guide (above) for per-environment defaults.
Phase 3: Generate ArgoCD Application Manifest
Generate an ArgoCD Application CR for each environment:
metadata.name: <app>-<env>
spec.source.repoURL: point to the Git repository
spec.source.path: k8s/overlays/<env>
spec.destination.server: cluster API server
spec.destination.namespace: target namespace
- Sync policy:
- dev/staging: automated sync with self-heal and prune enabled
- prod: manual sync (require human approval)
- Health checks: ensure deployment rollout completes
Reference: argocd-kustomize.md
Phase 4: Validate
- Run
kustomize build k8s/overlays/<env> for each environment
- Verify rendered output has correct image tags, replicas, and resources
- If ArgoCD CLI available:
argocd app create --dry-run
- Show the user how to apply:
kubectl apply -f argocd-app.yaml
Common Errors & Troubleshooting
kubectl not found
kubectl is not installed or not in PATH.
Install: https://kubernetes.io/docs/tasks/tools/
Or use: brew install kubectl (macOS)
No cluster connection
Unable to connect to the server: connection refused
Check: kubectl config current-context and kubectl cluster-info
Common fixes: VPN not connected, kubeconfig expired, wrong context selected
Permission denied
Error from server (Forbidden): pods is forbidden
Check RBAC: kubectl auth can-i get pods --namespace=<ns>
Fix: Contact cluster admin for role binding
Resource Sizing Guide
When generating manifests, use these defaults based on environment:
| Environment | Replicas | CPU Req | CPU Limit | Mem Req | Mem Limit |
|---|
| dev | 1 | 100m | 500m | 128Mi | 256Mi |
| staging | 2 | 250m | 1000m | 256Mi | 512Mi |
| production | 3+ | 500m | 2000m | 512Mi | 1Gi |
Ask the user to adjust based on their app's actual usage. Suggest running kubectl top pods on existing deployments for real data.
Useful kubectl Commands Cheat Sheet
After any operation, suggest relevant commands:
kubectl get pods -w -n <ns>
kubectl logs -f deployment/<name> -n <ns>
kubectl port-forward svc/<name> 8080:80 -n <ns>
kubectl get all -l app=<name> -n <ns>
kubectl top pods -n <ns>
kubectl get events --sort-by='.lastTimestamp' -n <ns>
Safety Rules
- For
debug mode: NEVER delete pods or resources without asking
- For
generate mode: always include security contexts
- For
helm mode: never put real secrets in values.yaml
- Always check if kubectl is available before running commands
- Before applying to production, always show
kubectl diff first
- Never use
kubectl apply on production without user confirmation
- Warn if applying to a namespace that looks like production (prod, production, live)
- Suggest
--dry-run=client -o yaml to preview before actual apply