From Manual Chaos to 5-Minute Deploys: 12 Docker & Kubernetes Prompts for a Self-Driving CI/CD Pipeline

From Manual Chaos to 5-Minute Deploys: 12 Docker & Kubernetes Prompts for a Self-Driving CI/CD Pipeline

Remember the last time you manually deployed to production? The sweaty palms, the frantic kubectl commands, the 2 AM rollback because a container crashed. You're not alone. Many DevOps engineers still spend hours on repetitive tasks that could be automated. But what if you could turn those tedious manual steps into a few well-crafted prompts for AI assistants? That's exactly what I did. In this article, I'll share 12 prompts that transformed my workflow from manual chaos to a self-driving CI/CD pipeline that deploys to production in under 5 minutes.

These prompts are designed for AI coding assistants like GitHub Copilot, ChatGPT, or Claude. They cover Dockerfile optimization, Kubernetes manifests, CI/CD pipeline generation, debugging, and monitoring. Each prompt includes a clear explanation and a real-world example. Use them as a starting point and adapt to your stack.

1. Dockerfile Optimization Prompt

Task: Generate an optimized multi-stage Dockerfile for a Node.js app.
Prompt:
"Create a multi-stage Dockerfile for a Node.js 20 application. Use Alpine Linux for the final stage, copy only production dependencies, and set NODE_ENV=production. Include a non-root user and expose port 3000. Explain each stage."
Example Output:

# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build

# Final stage
FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
USER node
EXPOSE 3000
CMD ["node", "dist/index.js"]

This reduces image size by up to 70% compared to a single-stage build.

2. Kubernetes Deployment Manifest Prompt

Task: Generate a Kubernetes Deployment and Service for a web app.
Prompt:
"Write a Kubernetes Deployment for a Node.js app with 3 replicas, resource limits (CPU: 500m, memory: 512Mi), liveness and readiness probes on /health, and a Service of type ClusterIP. Use image myapp:latest. Include labels and selectors."
Example Output:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: myapp:latest
        ports:
        - containerPort: 3000
        resources:
          limits:
            cpu: "500m"
            memory: "512Mi"
        livenessProbe:
          httpGet:
            path: /health
            port: 3000
        readinessProbe:
          httpGet:
            path: /health
            port: 3000
---
apiVersion: v1
kind: Service
metadata:
  name: myapp-service
spec:
  selector:
    app: myapp
  ports:
  - port: 80
    targetPort: 3000

3. CI/CD Pipeline Generation Prompt

Task: Create a GitHub Actions workflow for building, testing, and deploying to Kubernetes.
Prompt:
"Generate a GitHub Actions workflow that builds a Docker image, runs tests, pushes to Docker Hub, and deploys to a Kubernetes cluster using kubectl. Use secrets for Docker Hub credentials and kubeconfig. Trigger on push to main."
Example Output:

name: CI/CD
on:
  push:
    branches: [ main ]
jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: Build Docker image
      run: docker build -t myapp:${{ github.sha }} .
    - name: Run tests
      run: docker run myapp:${{ github.sha }} npm test
    - name: Log in to Docker Hub
      uses: docker/login-action@v3
      with:
        username: ${{ secrets.DOCKER_USERNAME }}
        password: ${{ secrets.DOCKER_PASSWORD }}
    - name: Push to Docker Hub
      run: docker push myapp:${{ github.sha }}
    - name: Deploy to Kubernetes
      uses: azure/setup-kubectl@v3
      with:
        version: 'latest'
      env:
        KUBECONFIG: ${{ secrets.KUBECONFIG }}
      run: kubectl set image deployment/myapp myapp=myapp:${{ github.sha }}

4. Debugging Failing Pods Prompt

Task: Diagnose why a Kubernetes pod is in CrashLoopBackOff.
Prompt:
"My pod is in CrashLoopBackOff. What are the common causes and how to debug? Provide a step-by-step guide with kubectl commands."
Example Output:
1. Check pod logs: kubectl logs <pod-name> --previous
2. Describe pod: kubectl describe pod <pod-name>
3. Check events: kubectl get events --sort-by=.metadata.creationTimestamp
4. Common causes: misconfigured environment variables, missing secrets, application errors, resource limits.

5. Helm Chart Generation Prompt

Task: Create a Helm chart for a microservice.
Prompt:
"Generate a Helm chart for a Node.js microservice with configurable replica count, image repository, and resource limits. Include values.yaml, deployment.yaml, service.yaml, and ingress.yaml."
Example Output:

# values.yaml
replicaCount: 2
image:
  repository: myapp
  tag: latest
resources:
  limits:
    cpu: 500m
    memory: 512Mi
# templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "myapp.fullname" . }}
spec:
  replicas: {{ .Values.replicaCount }}
  template:
    spec:
      containers:
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        resources: {{- toYaml .Values.resources | nindent 10 }}

6. Docker Compose for Local Development Prompt

Task: Set up a local development environment with Docker Compose.
Prompt:
"Write a docker-compose.yml for a Node.js app with PostgreSQL and Redis. Include volume mounts for live reload, environment variables, and healthchecks."
Example Output:

version: '3.8'
services:
  app:
    build: .
    ports:
      - "3000:3000"
    volumes:
      - .:/app
      - /app/node_modules
    environment:
      - NODE_ENV=development
      - DATABASE_URL=postgres://user:pass@db:5432/mydb
      - REDIS_URL=redis://cache:6379
    depends_on:
      db:
        condition: service_healthy
      cache:
        condition: service_started
  db:
    image: postgres:15
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: pass
      POSTGRES_DB: mydb
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U user"]
      interval: 5s
  cache:
    image: redis:7

7. Kubernetes Secrets Management Prompt

Task: Manage secrets securely in Kubernetes.
Prompt:
"How to create and use Kubernetes Secrets for database credentials? Provide examples using kubectl and in a Deployment."
Example Output:
Create secret: kubectl create secret generic db-secret --from-literal=username=admin --from-literal=password=secret
Use in Deployment:

env:
- name: DB_USER
  valueFrom:
    secretKeyRef:
      name: db-secret
      key: username

8. Horizontal Pod Autoscaler Prompt

Task: Configure HPA based on CPU usage.
Prompt:
"Write a Horizontal Pod Autoscaler manifest for a Deployment named myapp targeting 70% CPU utilization, with minReplicas 2 and maxReplicas 10."
Example Output:

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: myapp-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: myapp
  minReplicas: 2
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 70

9. Rolling Update Strategy Prompt

Task: Configure zero-downtime rolling updates.
Prompt:
"How to set up a rolling update strategy for a Kubernetes Deployment to ensure zero downtime? Provide the spec with maxSurge and maxUnavailable."
Example Output:

spec:
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0

This ensures at least the desired number of replicas are available during updates.

10. Monitoring with Prometheus and Grafana Prompt

Task: Set up monitoring for a Kubernetes cluster.
Prompt:
"Generate a docker-compose.yml for Prometheus and Grafana to monitor a Kubernetes cluster. Include scraping config for Kubernetes metrics."
Example Output:

version: '3.8'
services:
  prometheus:
    image: prom/prometheus
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
    ports:
      - "9090:9090"
  grafana:
    image: grafana/grafana
    ports:
      - "3000:3000"

With prometheus.yml scraping Kubernetes API.

11. Infrastructure as Code with Terraform Prompt

Task: Provision a Kubernetes cluster on AWS EKS.
Prompt:
"Write Terraform code to create an EKS cluster with a managed node group. Include VPC, subnets, and IAM roles."
Example Output:

module "eks" {
  source          = "terraform-aws-modules/eks/aws"
  cluster_name    = "my-cluster"
  cluster_version = "1.28"
  vpc_id          = module.vpc.vpc_id
  subnet_ids      = module.vpc.private_subnets
  eks_managed_node_groups = {
    default = {
      min_size     = 2
      max_size     = 10
      desired_size = 3
      instance_types = ["t3.medium"]
    }
  }
}

12. Cost Optimization Prompt

Task: Reduce Kubernetes costs.
Prompt:
"What are the best practices to optimize Kubernetes costs? Provide actionable tips and kubectl commands to analyze resource usage."
Example Output:
- Use Horizontal Pod Autoscaler and Cluster Autoscaler.
- Set resource requests and limits appropriately.
- Use spot instances for non-critical workloads.
- Analyze with kubectl top pods and kubectl top nodes.
- Consider tools like Kubecost for visibility.

These 12 prompts have helped me automate my pipeline and reduce deployment time from hours to minutes. The key is to iterate: start with one prompt, refine it, and gradually build your automation. Remember, AI is a tool—you're still the engineer. Always review generated code for security and correctness.

Give these prompts a try in your next project. Start with the Dockerfile optimization and CI/CD pipeline prompts, and see how much time you save. For more DevOps automation tips, explore our blog. Happy deploying!

← All posts

Comments