Skip to content
Kubernetes

Deployment & Rollout

Manage a replicated, rolling-updated workload.

By EZ4Code Team
deploymentrolloutreplica

Code

# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
spec:
  replicas: 3
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  selector:
    matchLabels: { app: api }
  template:
    metadata:
      labels: { app: api }
    spec:
      containers:
        - name: api
          image: myapp:2.0
          ports: [{ containerPort: 8080 }]

# Rollout commands
# kubectl rollout status deployment/api
# kubectl rollout undo deployment/api
# kubectl rollout history deployment/api

Explanation

A Deployment manages a ReplicaSet and provides declarative rolling updates and rollbacks. The selector must match the template's labels so the controller can find its Pods. maxSurge and maxUnavailable tune how aggressive the rollout is, balancing speed against availability.

More Kubernetes Snippets