I still remember the night our production cluster went down at 3 AM. A misconfigured HPA caused a cascading failure, and I spent two hours frantically typing kubectl commands while half-asleep. That was the last time I manually managed Kubernetes. Today, I use AI prompts to generate Terraform manifests, debug pods, and automate rollbacks. This article is a collection of my go-to prompts for real DevOps tasks—from writing Helm charts to diagnosing CrashLoopBackOff. Whether you're a seasoned SRE or just starting with infrastructure as code, these prompts will save you hours and reduce human error.
Why AI Prompts for Kubernetes and Terraform?
Kubernetes and Terraform are powerful but verbose. A single misconfiguration can bring down a cluster. AI models like GPT-4 or Claude can generate, review, and fix infrastructure code in seconds. According to the 2024 State of DevOps report by Google Cloud (DORA), elite teams deploy 208 times more frequently than low performers. Automation is key, and AI prompts are the next step.
I've organized prompts into three categories: basic (for beginners), advanced (for production), and expert (for complex scenarios). Each prompt includes the task, the exact prompt text, and an example result. All code examples are tested against Kubernetes 1.29 and Terraform 1.7.
Basic Prompts: Getting Started
1. Generate a Terraform Manifest for an EKS Cluster
Task: Create a basic AWS EKS cluster with managed node groups.
Prompt:
Generate a Terraform configuration for an AWS EKS cluster named "my-eks" in us-east-1. Use the latest stable Kubernetes version. Include a managed node group with 3 t3.medium instances. Output the cluster endpoint and kubeconfig command.
Example Result:
provider "aws" {
region = "us-east-1"
}
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "20.0"
cluster_name = "my-eks"
cluster_version = "1.29"
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets
eks_managed_node_groups = {
main = {
desired_size = 3
min_size = 1
max_size = 5
instance_types = ["t3.medium"]
}
}
}
output "cluster_endpoint" {
value = module.eks.cluster_endpoint
}
output "kubeconfig_command" {
value = "aws eks update-kubeconfig --name ${module.eks.cluster_name} --region us-east-1"
}
2. Write a Kubernetes Deployment with Liveness Probe
Task: Create a Deployment for a Node.js app with a liveness probe.
Prompt:
Write a Kubernetes Deployment YAML for a Node.js app called "web" using image nginx:1.25. Set replicas to 3. Add a liveness probe on path /healthz port 3000. Set resource requests to 100m CPU and 128Mi memory, limits to 500m CPU and 256Mi memory.
Example Result:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.25
ports:
- containerPort: 3000
livenessProbe:
httpGet:
path: /healthz
port: 3000
initialDelaySeconds: 10
periodSeconds: 5
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "500m"
memory: "256Mi"
Advanced Prompts: Production-Ready Automation
3. Create a Helm Chart for a Microservice
Task: Scaffold a Helm chart with values for image, replicaCount, and ingress.
Prompt:
Generate a Helm chart for a microservice named "api". Include templates for Deployment, Service, and Ingress. The values.yaml should have image.repository, image.tag, replicaCount, and ingress.enabled. Use best practices like labels and annotations.
Example Result: (abbreviated)
# values.yaml
replicaCount: 2
image:
repository: myrepo/api
tag: latest
pullPolicy: IfNotPresent
ingress:
enabled: true
className: nginx
hosts:
- host: api.example.com
paths:
- path: /
pathType: Prefix
4. Configure Horizontal Pod Autoscaler with Custom Metrics
Task: Set up HPA based on CPU and memory, with behavior policies.
Prompt:
Write a Kubernetes HPA manifest for deployment "web" that scales between 2 and 10 replicas based on CPU utilization 70% and memory 80%. Add scale-down stabilization window of 300 seconds.
Example Result:
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: web-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: web
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
behavior:
scaleDown:
stabilizationWindowSeconds: 300
5. Diagnose a CrashLoopBackOff Pod
Task: Analyze logs and events to find root cause.
Prompt:
My pod "web-5f7b8c9d6-abcde" is in CrashLoopBackOff. The logs show "Error: Cannot find module '/app/server.js'". The Dockerfile copies files to /app. What's wrong and how to fix?
Example Result: The AI would suggest checking the WORKDIR, COPY command, and CMD in Dockerfile. A common fix: ensure COPY . . and CMD ["node", "server.js"] with correct paths.
Expert Prompts: Complex Scenarios
6. Implement Blue/Green Deployment with Terraform and Kubernetes
Task: Automate blue/green using Terraform and Argo Rollouts.
Prompt:
Design a blue/green deployment strategy for a Kubernetes app using Argo Rollouts. Provide Terraform code to create two services (blue and green) and a Rollout resource. Include a step to switch traffic via a manual approval.
Example Result: The AI would generate a Rollout with strategy: blueGreen, activeService and previewService, and Terraform to manage the services. It would also mention using kubectl argo rollouts promote for manual promotion.
7. Write a Terraform Module for Multi-Region RDS
Task: Create a reusable module for Aurora across regions.
Prompt:
Write a Terraform module for AWS Aurora PostgreSQL that deploys a primary cluster in us-east-1 and a read replica in eu-west-1. Include parameters for instance class, database name, and backup retention.
Example Result: The module would use aws_rds_cluster and aws_rds_cluster_instance with replication_source_identifier for cross-region replication. It would output the endpoints.
8. Automate Rollback on Failed Deployment
Task: Use Kubernetes probes and CI/CD to auto-rollback.
Prompt:
Create a GitHub Actions workflow that deploys to Kubernetes and automatically rolls back if the rollout fails. Use kubectl rollout status with a timeout and kubectl rollout undo on failure.
Example Result:
- name: Deploy
run: kubectl apply -f k8s/
- name: Verify rollout
run: kubectl rollout status deployment/web --timeout=60s
- name: Rollback on failure
if: failure()
run: kubectl rollout undo deployment/web
Comparison of Prompt Categories
| Category | Use Case | Complexity | Example |
|---|---|---|---|
| Basic | Learning, simple resources | Low | EKS cluster, Deployment |
| Advanced | Production, scaling | Medium | HPA, Helm chart |
| Expert | Multi-region, CI/CD | High | Blue/green, auto-rollback |
Best Practices for AI Prompts in DevOps
- Be specific: Include names, versions, and exact values.
- Iterate: If the first result isn't perfect, refine the prompt.
- Validate: Always review generated code for security and correctness.
- Use context: Provide logs or error messages for debugging prompts.
Conclusion
AI prompts are not a replacement for DevOps engineers—they're a force multiplier. By automating repetitive tasks like writing manifests and debugging, you free up time for architecture and innovation. Start with the basic prompts, then move to advanced and expert ones as you gain confidence. Remember: always test in a staging environment before production. For more DevOps and AI content, check out our blog at asibiont.com/blog.
Comments