Kubernetes with Generative AI – Cheat Sheet

1. Common Use Cases
| Use Case | Description |
|---|---|
| Infrastructure as Code validation | Auto-correct Kubernetes YAMLs using AI |
| Pod health explanation | Explain crashloops, readiness/liveness issues |
| Security Scanning | Scan misconfigured RBAC, Secrets, NetworkPolicies |
| Log Analysis | Summarize and explain logs from kubectl logs |
| Resource Optimization | Recommend CPU/Memory limits based on history |
| Debugging Errors | Use AI to suggest fixes for pod failures, scheduling issues |
| K8s YAML Generation | Describe service/app → AI generates YAML manifests |
| Policy Generation (OPA/Gatekeeper) | AI helps craft custom policies based on input behavior |
2. Prompt Templates for ChatGPT / Copilot
Generate Kubernetes Deployment YAML
Prompt: “Generate a Kubernetes Deployment YAML for a Node.js app with 3 replicas, image: node:18, and expose via LoadBalancer”
Analyze Pod Failure
Prompt: “Explain why the pod entered CrashLoopBackOff with this log: “
RBAC Suggestion
Prompt: “Generate an RBAC policy that gives read-only access to pods in namespace ‘dev'”
Tune Resource Limits
Prompt: “Suggest memory & CPU requests/limits for a Java app with average 70% CPU usage and 500Mi memory consumption”
3. Security Automation with Generative AI
| Task | Tool / Prompt Example |
|---|---|
| IAM/RBAC misconfig detection | “Find least privilege violation in this RBAC config” |
| Pod Security Policy (PSP) hardening | “Harden this PSP against privilege escalation” |
| NetworkPolicy misconfig detection | “Identify over-permissive rules in this NetworkPolicy YAML” |
| Secret Detection | “Scan this YAML for hardcoded credentials or secrets” |
4. AI Tools & Integrations with Kubernetes
| Tool / Platform | Purpose |
|---|---|
| K8sGPT | Explain Kubernetes objects & failures in plain English |
| Robusta.dev | Alerting & AI-based incident response on K8s |
| Kubiya.ai | ChatOps platform for DevOps workflows |
| OpenAI + Kubectl Shell | AI CLI assistant for Kubernetes troubleshooting |
| KubeLinter + AI | Lint configs with AI-augmented rule explanations |
| ChatGPT API + Bash | Auto-responder to analyze pod states/errors |
5. Tools to Use
- LangChain + K8s API → Automate querying K8s state and generating insights
- LLMs with Kubeconfig Access → Summarize cluster states securely
- GitHub Copilot in K8s repos → Instant suggestions during YAML authoring
- PromptFlow or OpenAI Function Call → Trigger AI tasks based on alerts
6. Real-time Scenarios
| Scenario | Generative AI Prompt |
|---|---|
| Pod Not Scheduling | “Why does this pod not schedule on any node? Here’s the YAML and node info.” |
| PersistentVolume Issue | “Explain why PVC is stuck in Pending state” |
| CI/CD Misconfig | “Find YAML error in this GitLab CI file for Kubernetes deploy” |
