The DevOps landscape is evolving at breakneck speed. As infrastructure grows more complex, engineers are turning to AI assistants to automate repetitive tasks, debug configurations, and optimize pipelines. This article provides a practical collection of 25 prompts you can use with AI tools like ChatGPT, Claude, or GitHub Copilot to supercharge your DevOps workflow. Each prompt is designed to be specific, actionable, and accompanied by real-world examples to help you integrate AI into your daily operations.
Why AI for DevOps?
AI assistants can analyze large codebases, generate boilerplate configurations, explain error messages, and even suggest optimizations. According to a 2024 survey by Stack Overflow, 70% of developers use or plan to use AI tools. For DevOps engineers, this means faster incident response, reduced manual toil, and more time for strategic work.
How to Use These Prompts
Each prompt below is a template. Replace the placeholders (like <service> or <path>) with your specific details. The more context you provide, the better the AI's response. Always verify AI-generated code before deployment, and follow security best practices.
Basic Prompts
1. Generate a Dockerfile for a Specific Service
Prompt: "Create a production-ready Dockerfile for a Python Flask app that uses Gunicorn as the WSGI server. The app runs on Python 3.11, has a requirements.txt file, and listens on port 5000. Include a multi-stage build to keep the image small, use a non-root user, and set environment variables."
Example Result:
# Stage 1: Build
FROM python:3.11-slim AS builder
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Stage 2: Run
FROM python:3.11-slim
RUN groupadd -r app && useradd -r -g app app
WORKDIR /app
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY . .
USER app
EXPOSE 5000
ENV FLASK_ENV=production
CMD ["gunicorn", "-b", "0.0.0.0:5000", "app:app"]
Why it works: The prompt specifies the stack, runtime, and security requirements, yielding a secure and optimized Dockerfile.
2. Write a Kubernetes Deployment Manifest
Prompt: "Write a Kubernetes Deployment manifest for the Docker image myapp:v1.2. Replicas: 3, update strategy: RollingUpdate with maxSurge 1 and maxUnavailable 0. Add a liveness probe hitting /healthz on port 8080 and a readiness probe on /ready. Set resource requests to 100m CPU and 256Mi memory, limits to 500m CPU and 512Mi memory. Include a Service of type ClusterIP on port 80."
Example Result:
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deployment
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myapp:v1.2
ports:
- containerPort: 8080
resources:
requests:
cpu: 100m
memory: 256Mi
limits:
cpu: 500m
memory: 512Mi
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 10
periodSeconds: 5
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
---
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
selector:
app: myapp
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: ClusterIP
Why it works: The prompt includes all necessary parameters, so the AI generates a complete and correct manifest.
3. Explain a Docker Compose File
Prompt: "Explain the following Docker Compose file. What services are defined, how do they communicate, and what are potential issues?" (paste your compose file)
Example Result: The AI will break down each service, network, volume, and environment variable, highlighting any missing dependencies or misconfigurations.
Why it works: This prompt helps you understand existing infrastructure and spot issues.
4. Generate a CI/CD Pipeline for GitHub Actions
Prompt: "Create a GitHub Actions workflow for a Node.js project that runs tests, builds a Docker image, and pushes it to Docker Hub on every push to main. Use Node.js 20, cache npm dependencies, and include a step to scan for vulnerabilities with Trivy."
Example Result:
name: CI/CD
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20
cache: 'npm'
- run: npm ci
- run: npm test
- name: Build Docker image
run: docker build -t ${{ secrets.DOCKER_USERNAME }}/myapp:${{ github.sha }} .
- name: Scan image
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ secrets.DOCKER_USERNAME }}/myapp:${{ github.sha }}
- name: Push to Docker Hub
run: |
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
docker push ${{ secrets.DOCKER_USERNAME }}/myapp:${{ github.sha }}
Why it works: The prompt specifies the trigger, language, and actions, resulting in a ready-to-use pipeline.
5. Write a Terraform Configuration for AWS EC2
Prompt: "Write a Terraform configuration to provision an AWS EC2 instance with the following parameters: AMI ami-0c55b159cbfafe1f0 (Amazon Linux 2), instance type t3.micro, a security group allowing SSH and HTTP, and a key pair named my-key. Use the aws provider version ~> 4.0."
Example Result:
provider "aws" {
region = "us-east-1"
}
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t3.micro"
key_name = "my-key"
vpc_security_group_ids = [aws_security_group.web_sg.id]
tags = {
Name = "web-server"
}
}
resource "aws_security_group" "web_sg" {
name = "web-sg"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
Why it works: The prompt includes all required parameters, and the AI produces a valid Terraform script.
Advanced Prompts
6. Debug a Kubernetes Deployment
Prompt: "My Kubernetes deployment is stuck in CrashLoopBackOff. Here is the pod description and logs. What could be the issue and how do I fix it?" (paste kubectl describe pod and kubectl logs output)
Example Result: The AI analyzes the logs and configuration, identifies common causes like missing environment variables, resource limits, or startup command errors, and provides step-by-step solutions.
Why it works: This prompt leverages the AI's ability to parse logs and suggest fixes.
7. Optimize an Existing Dockerfile
Prompt: "Here is my current Dockerfile. Optimize it for build speed and image size. Use Docker layer caching, combine RUN commands, and consider using a smaller base image." (paste your Dockerfile)
Example Result: The AI suggests improvements like changing ubuntu:latest to alpine, merging apt-get update and install, and using multi-stage builds.
Why it works: The prompt provides context and specific optimization goals.
8. Create a Helm Chart for a Microservice
Prompt: "Write a Helm chart for a simple microservice. The chart should include a Deployment, Service, ConfigMap for environment variables, and Ingress. Use templates for the image tag and replicas."
Example Result: A complete chart structure with Chart.yaml, values.yaml, and templates for each resource.
Why it works: The prompt specifies the required resources and templating needs.
9. Write a Bash Script to Automate Backup
Prompt: "Write a Bash script that backs up a PostgreSQL database to an S3 bucket using pg_dump and aws s3 cp. The script should be idempotent, use variables for database credentials, and log the output to a file."
Example Result:
#!/bin/bash
set -e
DB_NAME="mydb"
DB_USER="myuser"
BUCKET="my-backup-bucket"
TIMESTAMP=$(date +%Y%m%d%H%M%S)
BACKUP_FILE="/tmp/${DB_NAME}_${TIMESTAMP}.sql"
LOG_FILE="/var/log/backup.log"
pg_dump -U $DB_USER $DB_NAME > $BACKUP_FILE
aws s3 cp $BACKUP_FILE s3://$BUCKET/
rm $BACKUP_FILE
echo "Backup completed at $(date)" >> $LOG_FILE
Why it works: The prompt specifies the tools, variables, and logging requirements.
10. Explain a Terraform State File
Prompt: "Explain the following Terraform state file. What resources are tracked, and are there any sensitive data that should be encrypted?" (paste a snippet)
Example Result: The AI describes the resources, points out potential secrets, and advises on using remote state storage with encryption.
Why it works: This prompt helps understand state management and security.
11. Generate a Docker Compose for Local Development
Prompt: "Create a docker-compose.yml for a local development environment with a Node.js backend, PostgreSQL database, and Redis. Include health checks, volume mounts for code, and environment variables for database connection."
Example Result: A compose file with three services, each with proper configurations.
Why it works: The prompt specifies the services and requirements.
12. Write a GitLab CI/CD Pipeline
Prompt: "Create a GitLab CI/CD pipeline for a Python project. Stages: test, build, deploy. Use a Python 3.11 image, run pytest, build a Docker image, and deploy to a Kubernetes cluster using kubectl."
Example Result: A .gitlab-ci.yml file with stages, jobs, and environment variables.
Why it works: The prompt defines the stages and tools.
13. Convert a Docker Command to Kubernetes YAML
Prompt: "I have this Docker run command: docker run -p 8080:80 -e ENV=prod myapp:latest. Convert it to a Kubernetes Deployment and Service."
Example Result: YAML manifests for the deployment and service, including the environment variable.
Why it works: The AI translates the Docker command into K8s objects.
Expert Prompts
14. Design a Multi-Cluster Kubernetes Architecture
Prompt: "Design a multi-cluster Kubernetes architecture for a global application. Consider high availability, disaster recovery, and networking. Use tools like Istio for service mesh and ArgoCD for GitOps. Provide a diagram description and key components."
Example Result: A detailed architecture description with cluster setups, federation, and traffic routing strategies.
Why it works: The prompt asks for a high-level design, leveraging the AI's knowledge of best practices.
15. Troubleshoot a Network Policy Issue
Prompt: "My pods cannot communicate across namespaces. Here is my NetworkPolicy and pod configuration. Diagnose and fix." (paste configs)
Example Result: The AI identifies misconfigured selectors or missing ports, and provides corrected YAML.
Why it works: The prompt includes specific details for diagnosis.
16. Write a Custom Prometheus Exporter in Go
Prompt: "Write a Prometheus exporter in Go that exposes metrics about the current number of orders in a database. Use the prometheus/client_golang library. Include a metric orders_total with a label status."
Example Result: A Go program with a collector that queries the DB and exposes metrics.
Why it works: The prompt specifies the language, library, and metric format.
17. Optimize a Terraform Module for Reusability
Prompt: "Refactor this Terraform module to be more reusable. Use variables for resource names, tags, and sizes. Add outputs for important attributes." (paste module)
Example Result: A modularized version with input variables and outputs.
Why it works: The prompt targets specific improvements.
18. Create a CI/CD Pipeline with Canary Deployments
Prompt: "Write a GitHub Actions workflow that deploys a new version of a service to Kubernetes as a canary (10% traffic) and then gradually increases to 100% if the canary is healthy. Use Argo Rollouts and include a manual approval step."
Example Result: A workflow with Argo Rollouts commands and approval gates.
Why it works: The prompt specifies the deployment strategy and tools.
19. Analyze a Kubernetes Cluster for Security Issues
Prompt: "Given this kubectl get all output and RBAC policies, identify potential security risks and suggest remediation." (paste output)
Example Result: The AI lists issues like privileged containers, exposed ports, or overly permissive RBAC.
Why it works: The prompt provides the necessary context for security analysis.
20. Generate a Service Mesh Configuration
Prompt: "Write an Istio VirtualService and DestinationRule for a service checkout that routes 90% traffic to checkout-v1 and 10% to checkout-v2. Include a timeout of 5 seconds and retries with 3 attempts."
Example Result: YAML configurations for the resources.
Why it works: The prompt specifies routing and resilience parameters.
21. Write a Python Script to Clean Up Old Docker Images
Prompt: "Write a Python script using the Docker SDK that deletes all Docker images tagged as myapp:dev older than 7 days, but keeps the latest 5."
Example Result: A script that lists images, filters by age, and removes them.
Why it works: The prompt defines the logic and constraints.
22. Explain a Kubernetes Operator Pattern
Prompt: "Explain the Kubernetes Operator pattern. Provide a simple example of a custom resource and controller using the operator-sdk."
Example Result: A detailed explanation with code snippets.
Why it works: The prompt asks for both explanation and example.
23. Create a Terraform Policy as Code with OPA
Prompt: "Write an OPA policy that requires all EC2 instances to have tags owner and environment. Use Terraform's terraform plan JSON output as input."
Example Result: A Rego policy file.
Why it works: The prompt specifies the input and requirement.
24. Generate a Kubernetes Admission Webhook
Prompt: "Write a Kubernetes admission webhook in Go that validates that all Pods have a resource limit set. Provide the webhook server code, configuration, and deployment manifest."
Example Result: Complete code and YAML files.
Why it works: The prompt is very specific, yielding a comprehensive answer.
25. Design a Full GitOps Workflow
Prompt: "Design a GitOps workflow using Argo CD and GitHub Actions. Include steps for building, testing, and syncing to a Kubernetes cluster, with a rollback strategy."
Example Result: A detailed workflow with diagrams and configuration files.
Why it works: The prompt asks for a comprehensive design.
Conclusion
These 25 prompts are just a starting point. By adapting them to your specific environment, you can dramatically improve your productivity as a DevOps engineer. AI assistants are not here to replace you but to handle the mundane tasks, allowing you to focus on architecture and innovation. Start with a few prompts, see the results, and refine your approach. Happy automating!
Comments