Beyond YAML: 15 AI Prompts That Turn DevOps Chaos into Managed Infrastructure

Beyond YAML: 15 AI Prompts That Turn DevOps Chaos into Managed Infrastructure

You've been staring at the same cryptic error message for the last hour. The Kubernetes pod is crash-looping, the Docker image you just built is 2GB, and the CI pipeline that worked yesterday is suddenly red. Sound familiar? As DevOps engineers, we live in a world where complexity is the default, and the tools we use to manage that complexity often add their own layer of confusion.

What if you could have a senior colleague who knows every Dockerfile best practice, every Kubernetes networking quirk, and every CI/CD optimization trick? That's where AI prompts come in. By using carefully crafted prompts, you can turn AI into a powerful assistant that helps you debug, optimize, and automate your infrastructure routines. This isn't about replacing your expertise; it's about augmenting it, saving you hours of manual investigation, and helping you avoid common pitfalls.

In this guide, I'll share 15 battle-tested prompts organized by difficulty level, each with a concrete example and explanation. Whether you're a beginner trying to understand Docker basics or an expert optimizing a multi-cluster Kubernetes setup, there's a prompt here for you.

Why AI Prompts Matter in DevOps

Before diving into the prompts, let's address the elephant in the room: why use AI for infrastructure tasks? The answer is simple: speed and consistency. AI models have been trained on vast amounts of public code, documentation, and Stack Overflow threads, which means they can often spot issues or suggest solutions that might take a human hours to find. For instance, a 2024 survey by the Cloud Native Computing Foundation (CNCF) found that over 80% of organizations are now using cloud-native tools, and with that scale, even small inefficiencies in Dockerfiles or CI pipelines can have significant costs.

AI prompts allow you to:
- Accelerate troubleshooting: Instead of manually grepping logs and searching docs, you can describe the problem and get a list of likely causes and fixes.
- Standardize practices: Prompts can enforce your team's coding standards, ensuring every Dockerfile follows the same optimization patterns.
- Learn faster: For newcomers, prompts can explain complex concepts in plain language, making the learning curve less steep.

Basic Prompts: Getting Started

These prompts are perfect for beginners or for quick tasks that every DevOps engineer encounters daily.

1. Dockerfile Optimization

Task: Ask AI to analyze and optimize a Dockerfile.

Prompt:

Analyze the following Dockerfile and suggest improvements for size, build time, and security. Explain each suggestion.

FROM ubuntu:20.04
RUN apt-get update && apt-get install -y python3-pip && rm -rf /var/lib/apt/lists/*
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
CMD ["python3", "app.py"]

Example Result:
The AI might respond with:
- Use a smaller base image like python:3.10-slim to reduce size.
- Combine RUN commands to reduce layers.
- Add --no-cache-dir to pip install to avoid caching unnecessary files.
- Use multi-stage builds to separate build dependencies from runtime.
- Add a non-root user for security.

Why it works: This prompt gives the AI specific code to analyze and asks for explanations, which helps you understand the reasoning behind each suggestion.

2. Docker Compose Service Setup

Task: Generate a docker-compose.yml for a simple web app with a database.

Prompt:

Create a docker-compose.yml for a Node.js web app with a PostgreSQL database. Include health checks, volumes for persistent data, and a network. Use environment variables for configuration.

Example Result:

version: '3.8'
services:
  web:
    build: .
    ports:
      - "3000:3000"
    environment:
      - DB_HOST=db
      - DB_USER=user
      - DB_PASS=pass
    depends_on:
      db:
        condition: service_healthy
    networks:
      - app-network
  db:
    image: postgres:14
    environment:
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=pass
    volumes:
      - db-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U user"]
      interval: 5s
      timeout: 5s
      retries: 5
    networks:
      - app-network
volumes:
  db-data:
networks:
  app-network:
    driver: bridge

Why it works: The prompt specifies the exact requirements, so the AI produces a production-ready configuration with health checks and volumes.

3. Kubernetes YAML Manifest Generation

Task: Generate a Kubernetes Deployment and Service for a simple web app.

Prompt:

Write a Kubernetes YAML manifest for a Deployment of a simple web app (image: nginx:1.25) with 3 replicas, and a Service of type LoadBalancer to expose it. Include resource limits and liveness probe.

Example Result:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - name: nginx
        image: nginx:1.25
        ports:
        - containerPort: 80
        resources:
          limits:
            cpu: "500m"
            memory: "512Mi"
          requests:
            cpu: "250m"
            memory: "256Mi"
        livenessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 3
          periodSeconds: 5
---
apiVersion: v1
kind: Service
metadata:
  name: web-service
spec:
  type: LoadBalancer
  selector:
    app: web
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80

Why it works: The prompt clearly defines the resource type, image, replicas, and additional features like probes, making the output as per best practices.

4. CI/CD Pipeline Skeleton

Task: Create a basic CI/CD pipeline for a GitHub Actions workflow.

Prompt:

Write a GitHub Actions workflow YAML for a Node.js project that runs tests on push and deploy to AWS ECS on tag push. Use environment secrets for AWS credentials.

Example Result:

name: CI/CD

on:
  push:
    branches: [ main ]
  tags:
    - 'v*'

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - uses: actions/setup-node@v3
      with:
        node-version: 18
    - run: npm ci
    - run: npm test

  deploy:
    if: startsWith(github.ref, 'refs/tags/v')
    runs-on: ubuntu-latest
    needs: test
    steps:
    - uses: actions/checkout@v3
    - name: Configure AWS credentials
      uses: aws-actions/configure-aws-credentials@v2
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: us-east-1
    - name: Deploy to ECS
      run: |
        # Commands to update ECS service
        aws ecs update-service --cluster my-cluster --service my-service --force-new-deployment

Why it works: The prompt specifies the trigger events and deployment target, so the AI generates a functional pipeline with proper secrets handling.

Advanced Prompts: Leveling Up

These prompts assume you have some experience and need more sophisticated solutions.

5. Debugging Kubernetes Cluster Issues

Task: Diagnose a problematic Kubernetes cluster.

Prompt:

I have a Kubernetes cluster where pods are stuck in Pending state. Describe the most common causes and how to diagnose them using kubectl commands. Provide a step-by-step troubleshooting guide.

Example Result:
The AI will list causes like insufficient resources, node selectors, taints and tolerations, and then give commands like kubectl describe pod <pod>, kubectl get nodes, kubectl describe node <node>, and explain how to interpret events.

Why it works: The prompt asks for a systematic approach, so the AI provides a logical troubleshooting flow.

6. Optimizing Docker Image Size

Task: Get specific strategies to reduce Docker image size.

Prompt:

List 10 techniques to reduce Docker image size, with examples for each. Focus on multi-stage builds, using distroless images, and minimizing layers.

Example Result:
The AI will provide a numbered list with examples like:
- Use alpine or distroless base images.
- Combine RUN commands.
- Use .dockerignore to exclude unnecessary files.
- Copy only required artifacts.
- Use --no-install-recommends for apt.

Why it works: The prompt requests a specific number of techniques, making the answer comprehensive and actionable.

7. Kubernetes Security Hardening

Task: Improve the security posture of a Kubernetes deployment.

Prompt:

Given the following Kubernetes deployment, suggest security hardening measures. Include RBAC, pod security policies, and network policies. Provide YAML examples.

Example Result:
The AI will analyze the deployment and suggest adding securityContext with runAsNonRoot, creating a NetworkPolicy to restrict ingress/egress, and using RBAC roles. It will provide YAML snippets for each.

Why it works: The prompt specifies the areas of focus, so the AI gives targeted advice.

8. CI/CD Pipeline Optimization

Task: Optimize an existing CI/CD pipeline for speed and reliability.

Prompt:

Here is a GitLab CI pipeline that runs tests and builds a Docker image. Optimize it for speed and caching. Suggest improvements.

stages:
  - test
  - build

test_job:
  stage: test
  script:
    - npm install
    - npm test

build_job:
  stage: build
  script:
    - docker build -t myapp .

Example Result:
The AI might suggest using caching for npm dependencies, using Docker layer caching, parallelizing jobs, and using docker pull with --cache-from.

Why it works: The prompt provides existing code and asks for optimization, so the AI tailors its suggestions.

9. Infrastructure as Code Best Practices

Task: Get best practices for Terraform.

Prompt:

What are the best practices for organizing Terraform configurations? Include module structure, state management, and remote backends. Provide an example directory layout.

Example Result:
The AI will describe a typical structure like modules/, environments/, main.tf, variables.tf, and recommend using remote state with locking (e.g., S3 + DynamoDB).

Why it works: The prompt asks for specific aspects, so the AI gives a detailed answer.

Expert Prompts: For the Masters

These prompts tackle complex, niche problems that even seasoned engineers find challenging.

10. Kubernetes Network Troubleshooting

Task: Solve a complex networking issue in Kubernetes.

Prompt:

I have a Kubernetes cluster with a service that is unreachable from outside. The pod is running and the service endpoints exist. Walk me through a systematic debugging process using kubectl and network tools like tcpdump. Include common issues like CNI misconfiguration, kube-proxy issues, and network policies.

Example Result:
The AI will provide a step-by-step guide starting with kubectl get endpoints, checking kube-proxy logs, verifying iptables rules, and then testing with curl and tcpdump. It will explain how to isolate the issue.

Why it works: The prompt is very specific, so the AI provides a deep, technical response.

11. Advanced Docker Multi-Stage Builds

Task: Design a multi-stage Dockerfile for a complex application.

Prompt:

Create a multi-stage Dockerfile for a Go application that needs to be compiled with CGO_ENABLED=0, uses a distroless base image, and copies only the binary. Include a stage for running tests and a stage for linting.

Example Result:

FROM golang:1.21 AS build
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o /app/main .

FROM golang:1.21 AS test
WORKDIR /app
COPY --from=build /app .
RUN go test ./...

FROM gcr.io/distroless/static AS runtime
COPY --from=build /app/main /main
ENTRYPOINT ["/main"]

Why it works: The prompt specifies the language, flags, and target base image, so the AI produces a precise Dockerfile.

12. CI/CD for Blue-Green Deployment

Task: Implement blue-green deployment strategy in a CI/CD pipeline.

Prompt:

Design a CI/CD pipeline for a blue-green deployment using ArgoCD and Kubernetes. Explain the steps and provide YAML for the ArgoCD Application and a shell script for the pipeline.

Example Result:
The AI will explain the concept and then provide YAML for an ArgoCD Application with two destinations (blue and green) and a script that updates the image tag in the green environment and then switches the service selector.

Why it works: The prompt asks for a specific deployment strategy and tools, so the AI gives a detailed implementation.

13. Kubernetes Cost Optimization

Task: Get strategies to reduce Kubernetes costs.

Prompt:

What are the best practices for optimizing Kubernetes costs? Include resource requests/limits, cluster autoscaling, and spot instances. Provide concrete examples with kubectl commands.

Example Result:
The AI will discuss setting appropriate requests/limits, using HPA and VPA, using spot instances for stateless workloads, and provide commands like kubectl describe nodes to check resource usage.

Why it works: The prompt is clear and asks for examples, making the answer practical.

14. Security Scanning in CI/CD

Task: Integrate security scanning into a CI/CD pipeline.

Prompt:

How can I integrate security scanning (SAST, DAST, image scanning) into a GitHub Actions pipeline? Provide examples using tools like Trivy, Semgrep, and OWASP ZAP.

Example Result:
The AI will provide a YAML snippet that includes steps for Trivy to scan the Docker image, Semgrep for static analysis, and OWASP ZAP for dynamic testing, with appropriate configurations.

Why it works: The prompt names specific tools, so the AI gives accurate examples.

15. Infrastructure Migration to Kubernetes

Task: Plan a migration from a monolithic VM-based architecture to Kubernetes.

Prompt:

I'm planning to migrate a monolithic application running on VMs to Kubernetes. Outline a step-by-step migration strategy, including breaking down the monolith, using Helm for packaging, and handling stateful services (e.g., database).

Example Result:
The AI will suggest phases like analyzing dependencies, containerizing the app, creating Helm charts, migrating stateful services using StatefulSets, and using a strangler pattern. It will also mention tools like Kompose for initial conversion.

Why it works: The prompt is about strategy, so the AI provides a comprehensive plan.

Putting It All Together

These prompts are just the beginning. The real power comes when you combine them with your own knowledge and adapt them to your specific context. For example, you could use the Dockerfile optimization prompt, then feed the output back into the CI/CD optimization prompt to get a fully optimized pipeline.

As you work with AI, you'll notice that the more specific and detailed your prompt, the better the result. Don't be afraid to iterate: if the AI gives a generic answer, provide more context or ask follow-up questions.

Final Thoughts

AI isn't going to replace DevOps engineers, but it's becoming an indispensable tool in our arsenal. By using prompts like these, you can automate the mundane, accelerate the complex, and free up time for the creative problem-solving that makes our field exciting. Start with one prompt, try it on a real task, and see the difference it makes.

Have you tried using AI for your infrastructure tasks? What's your go-to prompt? Share in the comments below — I'd love to hear your experiences.

If you want to dive deeper into these topics, consider exploring the courses on asibiont.com, where we cover DevOps, cloud, and infrastructure with AI-assisted learning.

← All posts

Comments