Revision History

The Deployment Object and Its Revision History

A Deployment adds a rollout strategy to the same fields. It never touches Pods: each distinct template gets its own ReplicaSet, and a rollout scales the new one up and the old one down. Old ReplicaSets stay at zero replicas as the revision history. BookNest's API as a Deployment, at image 1.3:

k8s/api-deployment.yaml: three API replicas with a cautious rolloutYAML
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
  labels: { app: booknest, tier: api }
  annotations: { kubernetes.io/change-cause: "BookNest API 1.3" }
spec:
  replicas: 3
  minReadySeconds: 5
  progressDeadlineSeconds: 60
  strategy: { type: RollingUpdate, rollingUpdate: { maxSurge: 1, maxUnavailable: 0 } }
  selector: { matchLabels: { app: booknest, tier: api } }
  template:
    metadata: { labels: { app: booknest, tier: api } }
    spec:
      containers:
      - name: api
        image: localhost:33500/booknest-api:1.3
        ports: [{ name: http, containerPort: 3000 }]
        env: [{ name: PGHOST, value: db }, { name: PGUSER, value: booknest },
              { name: PGPASSWORD, value: booknest }]
        readinessProbe: { httpGet: { path: /ready, port: http }, periodSeconds: 5 }
        livenessProbe: { httpGet: { path: /health, port: http }, periodSeconds: 10 }
        resources: { requests: { cpu: 50m, memory: 64Mi }, limits: { memory: 256Mi } }
        securityContext: { runAsNonRoot: true, allowPrivilegeEscalation: false }

The template is Pods's Pod minus the init container. Replace the bare Pod with it:

Creating the Deployment and its first ReplicaSetShell
kubectl delete pod api web-probed crash-always crash-onfailure crash-never >/dev/null
kubectl apply -f k8s/api-deployment.yaml && kubectl rollout status deployment/api >/dev/null
kubectl get replicasets -l tier=api
Output
deployment.apps/api created
NAME             DESIRED   CURRENT   READY   AGE
api-58cb445bff   3         3         3       11s

The suffix is the pod-template-hash, also added to each ReplicaSet's selector so that it counts only its own Pods. kubectl 5,150 rollout history lists the revisions, labeled with the kubernetes.io/change-cause annotation.