Skip to content

Deployments — Example Manifests

simple-deployment.yaml — Basic Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.21
          ports:
            - containerPort: 80
              name: http

deployment-with-strategy.yaml — Custom update strategy

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-deployment
  labels:
    app: web
spec:
  replicas: 4
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1          # Max 1 extra Pod during update (total: 5)
      maxUnavailable: 1    # Max 1 Pod unavailable (minimum: 3)
  selector:
    matchLabels:
      app: web
      tier: frontend
  template:
    metadata:
      labels:
        app: web
        tier: frontend
        version: "1.0"
    spec:
      containers:
        - name: nginx
          image: nginx:1.21
          ports:
            - containerPort: 80
          resources:
            requests:
              memory: "64Mi"
              cpu: "250m"
            limits:
              memory: "128Mi"
              cpu: "500m"

compose.yaml — Docker Compose comparison

# Docker Compose comparison for Deployment concepts

version: '3.8'
services:
  # Simple replicated service
  web:
    image: nginx:1.21
    deploy:
      replicas: 3
      update_config:
        parallelism: 1        # Similar to maxSurge/maxUnavailable
        delay: 10s
        order: start-first    # Similar to RollingUpdate
      restart_policy:
        condition: any        # Similar to Kubernetes restartPolicy
    ports:
      - "8080:80"

  # Service with resource limits
  api:
    image: nginx:1.21
    deploy:
      replicas: 4
      resources:
        limits:
          cpus: '0.5'
          memory: 128M
        reservations:
          cpus: '0.25'
          memory: 64M
      update_config:
        failure_action: rollback  # Similar to Kubernetes rollback
    ports:
      - "8081:80"