Deployments

Harry · 11 Sep 2026 · 9 views

Why Deployments?

A Deployment is a controller that manages a set of identical pods via a ReplicaSet. It guarantees the desired number of replicas, supports rolling updates and lets you roll back.

A Deployment Manifest

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

Save as deployment.yaml and apply it:

kubectl apply -f deployment.yaml
kubectl get deployments
kubectl get pods -o wide

Scaling

kubectl scale deployment web --replicas=5
kubectl rollout status deployment/web

Rolling Update and Rollback

kubectl set image deployment/web web=nginx:1.27
kubectl rollout status deployment/web
kubectl rollout undo deployment/web   # roll back

By default a rolling update replaces pods gradually, keeping the app available.

Key Points

  • Deployment -> ReplicaSet -> Pods is the standard hierarchy.
  • The selector must match labels on the pod template.
  • Rolling updates avoid downtime; rollout undo reverts a bad release.
Share this post:

Comments (0)

Please login or register to comment.