Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 37 ยท Projects and Workloads

Deployments and Rollouts

Run replicated apps with Deployments, update them with rolling and recreate strategies, roll back with oc rollout undo, and learn why DeploymentConfig is deprecated.

A Deployment keeps a desired number of identical Pods running and manages how you move from one version of your app to the next. It is the workload object you will use most. On OpenShift it is a standard Kubernetes Deployment, with a few OpenShift conveniences such as image triggers.

A Deployment manifest

YAML
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: web
          image: quay.io/example/web:1.0
          ports:
            - containerPort: 8080
          readinessProbe:
            httpGet:
              path: /healthz
              port: 8080

Three parts matter: replicas (how many Pods), selector (which Pods belong, matched by label) and template (the Pod recipe). The Deployment creates a ReplicaSet for each version of the template. Changing the template, for example the image tag, creates a new ReplicaSet and gradually shifts Pods to it.

Terminal
oc apply -f web-deployment.yaml
oc get deployment web
oc get replicaset -l app=web

Strategies

RollingUpdate (the default) replaces Pods gradually. Two numbers control the speed:

  • maxSurge: how many extra Pods may exist above replicas during the update.
  • maxUnavailable: how many Pods may be missing during the update.

With replicas: 3, maxSurge: 1 and maxUnavailable: 0, the Deployment starts one new Pod, waits until it is Ready, then stops one old Pod, and repeats. You never drop below three ready Pods. This is why a correct readiness probe matters: it tells the rollout when a new Pod can take traffic (next lesson).

Recreate stops all old Pods first, then starts new ones. It causes downtime but is right when two versions must never run together (some database schema changes or single-writer apps).

Updating and watching

Terminal
oc set image deployment/web web=quay.io/example/web:1.1
oc rollout status deployment/web
oc rollout history deployment/web
oc get pods -w

oc set image edits the template; oc rollout status waits and exits non-zero if the rollout fails, which is ideal in scripts. oc rollout history lists revisions.

Rolling back

Terminal
oc rollout undo deployment/web
oc rollout undo deployment/web --to-revision=2

Rollback returns the template to an earlier revision. It does not undo changes to databases or ConfigMaps, so keep versions backward compatible where you can. You can also pause and resume to batch several edits into a single rollout:

Terminal
oc rollout pause deployment/web
oc set image deployment/web web=quay.io/example/web:1.2
oc set resources deployment/web -c=web --limits=memory=256Mi
oc rollout resume deployment/web

To restart all Pods with the same template (for example after a Secret changed and the app reads it only at startup):

Terminal
oc rollout restart deployment/web

Scaling

Terminal
oc scale deployment/web --replicas=5
oc autoscale deployment/web --min=2 --max=10 --cpu-percent=70

The second command creates a HorizontalPodAutoscaler. Storage and Scaling covers it properly.

Image triggers

OpenShift can redeploy automatically when an ImageStream tag changes. This is enabled by an annotation on the Deployment:

Terminal
oc set triggers deployment/web --from-image=web:latest -c web

You will use this together with builds in ImageStreams and tags. Triggers are opt-in; with plain registry images your pipeline usually updates the tag in Git instead.

DeploymentConfig, in one paragraph

Before Kubernetes had Deployments, OpenShift offered DeploymentConfig with hooks, triggers and its own controller. It still works on existing clusters, but Red Hat has deprecated it in OpenShift 4, and new work should use Deployments. The command forms differ (oc rollout latest dc/web versus oc rollout restart deployment/web), and DeploymentConfig used ReplicationControllers instead of ReplicaSets. When reading older tutorials, translate dc to deployment.

Rollout simulation

The stand-in below simulates a rolling update with maxSurge and maxUnavailable so you can see the Pod count at each step. It models the principle and is not the Deployment controller.

Python Stand-in: rolling update steps

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The model assumes each new Pod becomes Ready instantly; in a real rollout the controller waits for the readiness probe at every step.

Revisions and rollback

Python Stand-in: revision history and undo

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

In real Kubernetes an undo reuses the old ReplicaSet and the revision numbers work slightly differently; the stand-in only shows the idea.

Common mistakes

  • No readiness probe. The rollout marks Pods ready immediately, and traffic reaches an app that is still starting.
  • latest tags. The same tag can mean different content, so rollbacks and audits become unreliable. Use immutable tags or digests.
  • Editing Pods directly. A Pod owned by a Deployment is replaced; change the Deployment instead.
  • Too few replicas for zero downtime. One replica cannot roll without a gap unless maxSurge is at least 1.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does maxUnavailable: 0 with maxSurge: 1 guarantee during a rolling update?

    A new Pod must become Ready before an old one is removed, so capacity never dips.
  2. 2. Which strategy causes downtime by design?

    Recreate stops all old Pods before starting new ones.
  3. 3. How do you revert to the previous revision?

    oc rollout undo returns the Pod template to an earlier revision.
  4. 4. What is the status of DeploymentConfig in OpenShift 4?

    DeploymentConfig still exists for older workloads but is deprecated in favour of Deployment.

Summary

  • A Deployment manages ReplicaSets and Pods for a desired replica count.
  • RollingUpdate uses maxSurge and maxUnavailable; Recreate accepts downtime.
  • Use oc rollout status, history, undo, pause, resume and restart.
  • Readiness probes decide when a rollout may continue.
  • DeploymentConfig is deprecated; prefer Deployment.

Next: Pods and Health Probes