DevOps engineers are constantly under pressure to deliver faster, automate everything, and keep infrastructure reliable. But let's face it: writing yet another CI/CD pipeline, optimizing Docker images, or debugging Terraform state can eat hours. What if you could leverage AI to generate boilerplate, suggest optimizations, and even troubleshoot? This article isn't about generic AI hype—it's a collection of battle-tested prompts that I and other DevOps practitioners use daily. Each prompt is designed to be copy-pasted into your favorite LLM (like ChatGPT, Claude, or local models) to get actionable results. We'll cover CI/CD, Docker, Terraform, Kubernetes, and more. Expect real examples, code snippets, and practical tips. By the end, you'll have a toolkit to automate the boring parts and focus on architecture. Let's dive in.
1. Generate a Multi-Stage Dockerfile for a Node.js App
Why it works: Multi-stage builds reduce image size and attack surface. This prompt asks the AI to produce a production-ready Dockerfile with best practices.
Prompt:
You are a DevOps expert. Write a multi-stage Dockerfile for a Node.js 18 application. Use alpine-based images. Include:
- Build stage with dev dependencies
- Production stage with only production dependencies
- Non-root user
- Healthcheck
- Proper caching for npm install
Return only the Dockerfile with comments.
Example output:
# Build stage
FROM node:18-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
# Production stage
FROM node:18-alpine
WORKDIR /app
COPY --from=builder /app/node_modules ./node_modules
COPY . .
USER node
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=3s CMD wget -qO- http://localhost:3000/health || exit 1
CMD ["node", "server.js"]
Tip: Always verify the healthcheck endpoint exists. Adjust as needed.
2. Create a GitHub Actions CI Pipeline for Python
Why it works: CI pipelines are repetitive. This prompt generates a full workflow with linting, testing, and caching.
Prompt:
Generate a GitHub Actions workflow for a Python 3.11 project. Steps: checkout, setup Python, cache pip, install dependencies, run flake8, run pytest with coverage. Trigger on push and pull_request to main. Use ubuntu-latest. Output YAML only.
Example output:
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
- run: pip install -r requirements.txt
- run: flake8 .
- run: pytest --cov=.
Tip: Add a matrix for multiple Python versions if needed.
3. Optimize an Existing Dockerfile
Why it works: Sometimes you inherit a bloated Dockerfile. This prompt helps reduce size and improve layer caching.
Prompt:
Analyze this Dockerfile and suggest optimizations for size and build speed. Explain each change.
FROM ubuntu:latest
RUN apt-get update && apt-get install -y python3 python3-pip
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
CMD ["python3", "app.py"]
Example response:
- Use python:3.11-slim instead of ubuntu.
- Combine RUN commands to reduce layers.
- Copy requirements.txt first, install, then copy code to leverage caching.
- Use --no-cache-dir for pip.
Optimized version:
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "app.py"]
4. Generate Terraform for AWS VPC
Why it works: Terraform configs are verbose. This prompt generates a complete VPC with subnets, IGW, NAT, and route tables.
Prompt:
Write Terraform code for an AWS VPC with:
- 2 public subnets in different AZs
- 2 private subnets
- Internet Gateway
- NAT Gateway for private subnets
- Route tables and associations
Use variables for CIDR blocks and region. Output only HCL.
Example output (truncated):
resource "aws_vpc" "main" {
cidr_block = var.vpc_cidr
}
resource "aws_subnet" "public" {
count = 2
vpc_id = aws_vpc.main.id
cidr_block = cidrsubnet(var.vpc_cidr, 8, count.index)
availability_zone = data.aws_availability_zones.available.names[count.index]
map_public_ip_on_launch = true
}
# ... etc.
Tip: Always run terraform plan to validate.
5. Debug a Failing Kubernetes Deployment
Why it works: K8s errors can be cryptic. This prompt helps interpret logs and events.
Prompt:
My Kubernetes deployment is failing with CrashLoopBackOff. Here are the pod events and logs:
[attach logs]
What are the likely causes and how to fix? Provide kubectl commands to debug.
Example response:
- Check if the app exits immediately: kubectl logs <pod> --previous
- Check resource limits: kubectl describe pod <pod>
- Common fixes: adjust liveness probe, increase memory, fix entrypoint.
6. Write a Helm Chart for a Microservice
Why it works: Helm charts require boilerplate. This prompt generates a chart structure with values.yaml.
Prompt:
Create a Helm chart for a Node.js microservice. Include deployment, service, ingress, and HPA. Use values.yaml for image tag, replicas, and resource limits. Output the file structure and key files.
Example output:
my-chart/
Chart.yaml
values.yaml
templates/
deployment.yaml
service.yaml
ingress.yaml
hpa.yaml
values.yaml snippet:
replicaCount: 2
image:
repository: myapp
tag: latest
resources:
limits:
cpu: 500m
memory: 512Mi
7. Generate a GitLab CI Pipeline with Stages
Why it works: GitLab CI syntax differs from GitHub Actions. This prompt covers build, test, deploy.
Prompt:
Write a .gitlab-ci.yml for a Java Maven project. Stages: build, test, deploy. Use maven:3.8-jdk-11 image. Cache .m2. Deploy only on main branch to a staging server via SSH.
Example output:
stages:
- build
- test
- deploy
build:
stage: build
image: maven:3.8-jdk-11
script: mvn compile
cache:
paths:
- .m2/repository
test:
stage: test
script: mvn test
deploy:
stage: deploy
script:
- ssh user@staging "cd /app && git pull && mvn package && systemctl restart app"
only:
- main
8. Create a Prometheus Alert Rule
Why it works: Alerting rules require precise PromQL. This prompt generates a rule for high CPU usage.
Prompt:
Write a Prometheus alert rule that fires when CPU usage > 80% for 5 minutes. Include annotations and severity. Output YAML.
Example output:
groups:
- name: cpu
rules:
- alert: HighCPUUsage
expr: 100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80
for: 5m
labels:
severity: warning
annotations:
summary: "High CPU on {{ $labels.instance }}"
9. Generate a Docker Compose for Local Development
Why it works: Compose files for dev environments are common. This prompt includes app, database, and cache.
Prompt:
Write a docker-compose.yml for a Python Flask app with PostgreSQL and Redis. Include healthchecks, volumes, and environment variables. Use version 3.8.
Example output:
version: '3.8'
services:
web:
build: .
ports:
- "5000:5000"
depends_on:
- db
- redis
environment:
- DATABASE_URL=postgresql://user:pass@db:5432/mydb
db:
image: postgres:15
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: mydb
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U user"]
interval: 10s
redis:
image: redis:7
volumes:
pgdata:
10. Troubleshoot Terraform State Lock
Why it works: State locks can block deployments. This prompt explains how to safely unlock.
Prompt:
Terraform apply fails with "Error acquiring the state lock". How to resolve? Provide steps for AWS S3 backend and DynamoDB locking.
Example response:
- Check if another process is running.
- If not, force unlock: terraform force-unlock <LOCK_ID>
- Verify DynamoDB table for lock item and remove if stale.
Caution: Only force unlock if you're sure no other process is using the state.
Conclusion
These prompts are just the beginning. The key is to iterate: start with a prompt, refine the output, and save the best results as templates. Remember, AI is a tool—always review generated code for security and correctness. For more DevOps automation tips, explore our blog at asibiont.com/blog. Happy automating!
Comments