Courseiva
CKADChapter 3 of 18Objective 2.1

Deployments, ReplicaSets, and Scaling Applications

Exam objective 2.1 asks you to deploy and scale applications using Deployments and ReplicaSets. This matters because in the real world, your application must stay available even when things break, and it must handle sudden rushes of users without going down. For your CKAD exam, you will be tested on exactly how to create these objects, how to update them without downtime, and how to scale them up or down using simple commands.

12 min read
Beginner
Updated Jul 23, 2026
Editorial oversight: Johnson Ajibi· Security Systems Architect · MSc IT Security · IEEE Senior Member

A simple way to picture Deployments, ReplicaSets, and Scaling Applications

The Head Chef and Kitchen Brigade Analogy

A head chef runs a busy restaurant kitchen. She doesn't chop every carrot herself. She writes a recipe card (the Deployment) that describes exactly which dish to make, how many portions to prepare, and what to do if a plate breaks. She hands that card to a sous chef, who is the ReplicaSet manager. The sous chef's job is simple: keep exactly the right number of that dish on the pass, every shift. If a waiter drops a plate, the sous chef immediately sends a new one out. If the restaurant suddenly gets a huge booking, the head chef updates the recipe card to say 'make 20 portions instead of 5,' and the sous chef hires extra hands to cook them. If the head chef decides the recipe is outdated and develops a new one, she writes a new card, hands it to a new sous chef, and the old team packs up and leaves, one group at a time, without ever leaving the pass empty. The head chef never touches a single pan; she designs the plan, and the sous chef ensures reality matches the plan.

In your Kubernetes cluster, you are the head chef. You write a Deployment YAML file—that's your recipe card. A ReplicaSet is the sous chef, watching over a specific group of identical Pods (your cooked dishes). When you change the recipe (update your container image), the Deployment creates a new ReplicaSet that slowly replaces the old one, keeping your customers (users) fed throughout the process. Scaling is simply updating the number of portions (replicas) on the recipe card. The sous chef handles the rest.

How It Actually Works

Let's start with the smallest piece: a Pod. A Pod is the smallest deployable unit in Kubernetes. It runs one or more containers (like a tiny virtual machine for your app) and shares a network and storage among them. But on its own, a Pod is fragile. If the node (the physical or virtual server) it runs on crashes, that Pod is gone forever. You would have to manually create a new one. That's no good if you are running a website that must stay up.

Enter the ReplicaSet. A ReplicaSet is a Kubernetes controller—a piece of software that constantly watches the cluster and acts to keep the world in a desired state. Its only job is to ensure that a specified number of identical Pod replicas are running at all times. If a Pod dies (because of a crash, a node failure, or a manual deletion), the ReplicaSet immediately creates a replacement Pod. If someone accidentally creates too many identical Pods, the ReplicaSet kills the extras. This gives you basic self-healing. For example, if you set 'replicas: 3' in a ReplicaSet definition, the controller always makes sure exactly three Pods are running.

But a ReplicaSet on its own has a limitation: how do you update the application version? If you want to change the container image from version 1.0 to 2.0, you could delete the old ReplicaSet and create a new one. That would kill all Pods at once, causing downtime. Alternatively, you could manually create a new ReplicaSet with the new image, then slowly delete Pods from the old one. That is tedious and error-prone. This is where a Deployment comes in.

A Deployment is a higher-level controller that manages ReplicaSets. You never create a ReplicaSet directly (though you could). Instead, you create a Deployment, and the Deployment creates and manages one or more ReplicaSets for you. The Deployment gives you two superpowers: rolling updates and rollbacks.

When you update the container image in your Deployment YAML (say from 'myapp:1.0' to 'myapp:2.0'), the Deployment automatically creates a new ReplicaSet with the new image. Then it gradually scales down the old ReplicaSet while scaling up the new one. By default, it does this in a controlled way: it creates a new Pod, waits for it to become healthy, then destroys one old Pod, then creates another new one, and so on. This is called a rolling update. Your users never see a full outage—the old version handles traffic until the new version starts responding.

If something goes wrong with version 2.0 (maybe a bug causes errors), you can tell the Deployment to rollback. It immediately reverses the process: scales down the new ReplicaSet and scales up the old one, restoring the previous version. The Deployment keeps a history of revisions, so you can roll back to any previous state, not just the last one.

Scaling is the third piece. Scaling means changing the number of Pod replicas. You can scale two ways: manually (by editing the Deployment's 'replicas' field) or automatically (using a HorizontalPodAutoscaler, which we will cover later). When you scale up, the Deployment tells the current ReplicaSet to create more Pods. When you scale down, it tells the ReplicaSet to delete some Pods. The Deployment always maintains the desired number of replicas, even during updates.

Here is a concrete example. Imagine you run an online store. You have a Deployment called 'store-frontend' with 5 replicas running image 'store:v1'. You push a new feature and update the image to 'store:v2'. The Deployment creates a new ReplicaSet with 1 Pod of v2. When that Pod passes its health check, the Deployment reduces the old ReplicaSet to 4 Pods and increases the new one to 2 Pods. It continues this pattern until all 5 Pods are running v2. If v2 is broken, you run 'kubectl rollout undo deployment store-frontend', and the Deployment reverses the process.

Key terms to remember:

Pod: The smallest unit, runs your container.

ReplicaSet: Ensures a specific number of identical Pods are running.

Deployment: Manages ReplicaSets, enables rolling updates and rollbacks.

Replicas: The desired number of Pods for a ReplicaSet or Deployment.

Rolling update: A gradual replacement of old Pods with new ones, avoiding downtime.

Rollback: Reverting to a previous version of a Deployment.

In the exam, you will mostly interact with Deployments. You will use 'kubectl create deployment', 'kubectl scale deployment', 'kubectl set image deployment', and 'kubectl rollout status/undo'. You will also need to understand how Deployments relate to ReplicaSets, because when you debug, you may need to look at ReplicaSets to understand why Pods are not starting. The key insight is: a Deployment is a declarative way to manage your application's lifecycle. You tell Kubernetes what you want (the desired state), and the controllers work to make it true.

A Deployment manages two ReplicaSets (v1 and v2) during a rolling update, each controlling three identical Pods with their own containers.

Walk-Through

1

Read the exam task carefully

The task will tell you exactly what to create (e.g., a Deployment named 'web-app' with image 'nginx:1.19' and 3 replicas). Note the exact name, image, replica count, and any specific requirements like 'use RollingUpdate strategy' or 'set maxSurge to 2'. Missing a detail here wastes time later.

2

Create the Deployment imperatively or declaratively

You have two options: run 'kubectl create deployment web-app --image=nginx:1.19' (which does not set replicas) followed by 'kubectl scale deployment web-app --replicas=3', or write a YAML file with all fields and run 'kubectl apply -f'. For speed, practise the imperative approach. Verify with 'kubectl get deployments'.

3

Update the Deployment image to a new version

Run 'kubectl set image deployment/web-app web-app=nginx:1.20 --record'. The '--record' flag adds a change-cause annotation to the rollout history. After this, the Deployment creates a new ReplicaSet with the new image and begins the rolling update.

4

Monitor the rollout status

Use 'kubectl rollout status deployment/web-app' to watch the update progress. This command blocks until the rollout completes or fails. If it reports an error (e.g., 'CrashLoopBackOff'), you need to troubleshoot immediately. Do not move to the next step until the rollout is successful.

5

Scale the Deployment up or down as required

If the task asks to increase replicas to 5, run 'kubectl scale deployment web-app --replicas=5'. This modifies the replica count on the current ReplicaSet. Verify with 'kubectl get pods' that the correct number of Pods appear and are in 'Running' state.

6

Practise rolling back a deployment

If the task instructs you to roll back, run 'kubectl rollout undo deployment/web-app'. This reverts to the previous ReplicaSet. To roll back to a specific revision, list history with 'kubectl rollout history deployment/web-app', then use 'kubectl rollout undo deployment/web-app --to-revision=2'.

7

Verify the final state

Always end by running 'kubectl get all -l app=web-app' (or whatever label your Deployment uses) to confirm the correct number of Pods, their images, and the desired state. This catches mistakes like missing labels or incorrect image tags.

What This Looks Like on the Job

Imagine you are a platform engineer at a company called 'QuickCart', an e-commerce platform that sells groceries online. You are responsible for deploying and scaling the 'order-service', which processes customer orders.

Your day might start like this: You open a terminal and run 'kubectl get deployments' to check the status of all running services. You see that 'order-service' has 3 replicas, all ready. But it's 8:55 AM, and you know that at 9 AM, a flash sale starts. Traffic is expected to triple. You need to scale up before the rush.

You run 'kubectl scale deployment order-service --replicas=10'. Behind the scenes, the Deployment finds the current ReplicaSet (which is managing the 3 Pods) and updates its 'replicas' field to 10. The ReplicaSet sees the desired count is now 10, so it creates 7 new Pods. Each new Pod goes through a readiness probe—a health check that tells the service when the Pod is actually ready to accept traffic. Once all 10 Pods are ready, they start receiving requests via a Service (a stable network endpoint).

After the flash sale ends at 10 AM, traffic drops. You scale back down: 'kubectl scale deployment order-service --replicas=3'. The ReplicaSet terminates 7 Pods gracefully, giving each a few seconds to finish any in-flight orders before shutting down. The service stays up the entire time.

Later that day, your development team releases version 2.0 of the order service with a new coupon feature. You update the image: 'kubectl set image deployment/order-service order-service=quickcart/order-service:v2.0 --record'. The '--record' flag saves the command in the rollout history for auditing. A rolling update begins. The Deployment creates a new ReplicaSet with 1 Pod of v2.0. After that Pod becomes ready, the old ReplicaSet is scaled down to 2 Pods, and the new one scaled up to 2. This continues until all 10 Pods (now the desired count) are running v2.0.

But something goes wrong: the new coupon feature has a bug that crashes the service under load. Users start seeing errors. You run 'kubectl rollout undo deployment order-service'. The Deployment immediately begins rolling back. It takes one minute to revert the update, and the service is restored to v1.0. You then investigate the bug, fix it, and redeploy later.

What tools and commands do you use day-to-day?

'kubectl get deployments' to list all deployments.

'kubectl describe deployment order-service' to see details like strategy, replicas, and events.

'kubectl get replicasets' to see which ReplicaSets exist and how many Pods each manages.

'kubectl rollout status deployment order-service' to watch the progress of an update.

'kubectl rollout history deployment order-service' to see previous revisions.

'kubectl rollout undo deployment order-service --to-revision=2' to roll back to a specific revision.

'kubectl scale deployment order-service --replicas=5' to manually scale.

In larger organisations, you might not manually scale. Instead, you set up a HorizontalPodAutoscaler (HPA) that automatically scales based on CPU or memory usage. But the fundamental concept—Deployments manage ReplicaSets, and ReplicaSets maintain Pod counts—remains the same.

How CKAD Actually Tests This

The CKAD exam tests your ability to actually do these things in a terminal under time pressure. You will not be asked to define terms in a multiple-choice question. Instead, you will be given a task like: 'Create a Deployment named web-app with 3 replicas using image nginx:1.19. Update the image to nginx:1.20. Then scale the Deployment to 5 replicas.' You must type the exact commands quickly and correctly.

Here are the exact concepts and traps the exam loves:

- Creating a Deployment: You must know how to use 'kubectl create deployment' with the '--image' flag. Remember that 'kubectl create deployment' does not take a '--replicas' flag directly—you must specify replicas later in the YAML or use 'kubectl scale'. Alternatively, you can write a YAML file and use 'kubectl apply -f'. The exam will let you use either method, but writing YAML from scratch under time pressure is risky. Learn the imperative commands well. - Scaling: The command 'kubectl scale deployment <name> --replicas=<number>' is straightforward. But beware: the exam might ask you to scale a ReplicaSet directly. If you see 'scale replicaset my-rs --replicas=4', know that works too, but typically you should scale the Deployment, not the ReplicaSet, because the Deployment will revert your change if it is managing that ReplicaSet. - Rolling updates: The command 'kubectl set image deployment/<name> <container-name>=<new-image>' is the standard way to update. Traps: the container name matters. If the container is named 'my-container' and you write 'myapp:2.0' without the container name prefix, it will fail. Also, the '--record' flag is often required in the exam to save the command in rollout history, so get into the habit of using it. - Rollback: 'kubectl rollout undo deployment/<name>' rolls back to the previous revision. To roll back to a specific revision, use '--to-revision=2'. You can check the history with 'kubectl rollout history deployment/<name>'. - Checking rollout status: 'kubectl rollout status deployment/<name>' is a blocking command—it watches the rollout until it completes. Use it to verify your update finished. The exam will expect you to wait for the rollout to complete before moving on. - Troubleshooting: If a Deployment's Pods are not starting, you need to examine the ReplicaSet. Run 'kubectl describe replicaset <name>' to see events like 'FailedCreate' or 'Failed to pull image'. The ReplicaSet will reveal the underlying problem (wrong image tag, insufficient CPU, etc.). Traps: beginners often look at the Deployment and miss that the ReplicaSet holds the real details about what is failing. - YAML structure: If you write YAML, you must know the exact fields. The Deployment spec has 'replicas', 'selector', and 'template'. The 'selector' must match the 'labels' in the 'template'. If they don't match, the Deployment will not manage the Pods. This is a common trap. - Strategy: The Deployment has a 'strategy' field. The default is 'RollingUpdate' with 'maxSurge' and 'maxUnavailable' controlling the speed of updates. The exam might ask you to modify these. For example, set 'maxSurge: 2' and 'maxUnavailable: 0' to force zero downtime. - Imperative vs declarative: The exam allows both. But if you use 'kubectl apply -f', the file must be valid. If you use imperative commands, you must be fast. Practise both. - Key definitions to memorise: - 'replicas': The desired number of Pods. - 'selector.matchLabels': Used to identify which Pods the ReplicaSet controls. - 'template': The Pod template that defines what containers to run. - 'strategy.type': Either 'RollingUpdate' or 'Recreate'. 'Recreate' kills all Pods at once before creating new ones (downtime). - 'minReadySeconds': How long a Pod must be ready before it counts as available.

The exam expects you to be comfortable with these commands and concepts under time pressure. Practise creating, updating, scaling, and rolling back Deployments until you can do it in your sleep.

Key Takeaways

A Deployment manages ReplicaSets, which in turn manage identical Pods to maintain a desired count at all times.

Use 'kubectl scale deployment <name> --replicas=<number>' to manually increase or decrease the number of running Pods.

Rolling updates replace old Pods with new ones gradually, ensuring zero downtime during application version changes.

Use 'kubectl rollout undo deployment/<name>' to revert to a previous version; the old ReplicaSet is preserved for this purpose.

When a Deployment rollout fails, inspect the ReplicaSet with 'kubectl describe replicaset' to see the root cause of the failure.

The '--record' flag on 'kubectl set image' saves the command in rollout history for auditing and rollback purposes.

The 'strategy.type' field in a Deployment can be 'RollingUpdate' (default) or 'Recreate'; 'Recreate' causes downtime by killing all Pods at once.

Pods created by a ReplicaSet are ephemeral and get new names and IP addresses each time they are replaced.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

Deployment

Manages the entire application lifecycle including updates and rollbacks

Creates and manages ReplicaSets underneath

Supports declarative updates via 'kubectl set image' or YAML changes

ReplicaSet

Only ensures a specific number of Pods are running

Is created by a Deployment automatically

Does not support rolling updates or rollbacks on its own

Scaling

Changes the number of Pods (replicas)

Uses 'kubectl scale' command

Modifies the existing ReplicaSet's replica count

Updating

Changes the Pod template (e.g., image version)

Uses 'kubectl set image' or 'kubectl apply'

Creates a new ReplicaSet with a new Pod template

RollingUpdate Strategy

Replaces Pods one by one, avoiding downtime

Default strategy for Deployments

Supports 'maxSurge' and 'maxUnavailable' tuning

Recreate Strategy

Kills all existing Pods at once before creating new ones

Causes downtime but is simpler and faster

Used when application requires it (e.g., exclusive database access)

Imperative Commands

Fast to type in exam (e.g., 'kubectl create deployment')

No file management required

Harder to track changes over time

Declarative Manifests

Reproducible via YAML files

Supports 'kubectl diff' to see changes before applying

Slower to write but better for production and team use

Watch Out for These

Mistake

I only need to learn about Deployments; ReplicaSets don't matter for the exam.

Correct

You must understand ReplicaSets because the exam tests your ability to troubleshoot failed Pods. When a Deployment fails to create Pods, the error is visible in the ReplicaSet's events. You will need to inspect ReplicaSets to diagnose image pull errors or scheduling failures.

Deployments are the main interface, but under the hood they create ReplicaSets. Beginners skip ReplicaSets, then fail exam questions that ask them to find the reason a rollout is stuck.

Mistake

The 'kubectl scale' command immediately terminates old Pods without waiting.

Correct

The 'kubectl scale' command triggers a controlled scale-down. Each Pod receives a SIGTERM signal and has a grace period (default 30 seconds) to finish what it's doing before being killed. This is part of Kubernetes' graceful termination.

Many think scaling is like turning off a light switch. They don't realise the Pods get a chance to shut down cleanly, which is critical for stateful applications that need to save data.

Mistake

A ReplicaSet ensures that specific Pods stay alive—if a Pod is restarted, it keeps the same name.

Correct

A ReplicaSet creates new Pods with new names and IP addresses. It does not 'heal' the old Pod; it replaces it with a brand new one. The identity of the Pod changes, so any logs or local storage on the old Pod are lost unless you use PersistentVolumes.

People expect 'self-healing' to mean the same Pod comes back. In reality, Kubernetes just creates a fresh Pod from the same template. This is confusing for anyone coming from traditional virtual machine thinking.

Mistake

If I update a Deployment, the old ReplicaSet is deleted immediately.

Correct

The Deployment keeps the old ReplicaSet around (by default) with its replicas scaled to zero. This is what enables rollbacks. The old ReplicaSet is preserved in the revision history, and you can undo the rollout to revive it.

Beginners think updating destroys the old version. But Kubernetes keeps the old ReplicaSet as a snapshot so you can roll back. Without this, rollbacks would not be possible.

Mistake

Scaling a Deployment up or down changes the number of ReplicaSets.

Correct

Scaling changes the number of Pods within the current ReplicaSet. It does not create a new ReplicaSet. Only changing the Pod template (e.g., image, environment variables) creates a new ReplicaSet. Scaling modifies the replica count on the existing ReplicaSet.

People conflate the concepts of updating (which creates a new ReplicaSet) and scaling (which changes the count within the existing ReplicaSet). This leads to confusion during exam tasks that ask you to scale without updating.

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

What is the difference between a Deployment and a ReplicaSet?

A ReplicaSet ensures a specific number of Pods are running. A Deployment is a higher-level controller that manages ReplicaSets, provides rolling updates and rollbacks, and is the standard way to run stateless applications in Kubernetes.

How do I scale a Deployment to zero replicas?

Run 'kubectl scale deployment <name> --replicas=0'. This terminates all Pods managed by the Deployment. The ReplicaSet remains but with zero Pods. You can scale back up later.

Why are my Pods not starting after a deployment update?

Check the ReplicaSet with 'kubectl describe replicaset <name>'. Look for events like 'FailedCreate', 'ImagePullBackOff', or 'CrashLoopBackOff'. Common causes: wrong image tag, insufficient cluster resources, or a container that crashes on startup.

Can I have multiple ReplicaSets for the same Deployment?

Yes, during a rolling update, the Deployment manages two ReplicaSets: the old one (being scaled down) and the new one (being scaled up). After the update completes, the old ReplicaSet remains with zero replicas for rollback purposes.

What does the '--record' flag do in a rollout command?

The '--record' flag annotates the Deployment with the command that triggered the change. This is stored in the rollout history, allowing you to see what command caused each revision when you run 'kubectl rollout history deployment/<name>'.

How do I perform a zero-downtime deployment in Kubernetes?

Use a Deployment with strategy type 'RollingUpdate' and set 'maxUnavailable: 0' and 'maxSurge: 1' (or higher). This ensures that new Pods are created before old ones are destroyed, so there is always at least one Pod serving traffic. Combine this with readiness probes on your Pods for true zero downtime.

What happens if I manually delete a Pod managed by a ReplicaSet?

The ReplicaSet controller detects that the actual Pod count is lower than desired, and immediately creates a replacement Pod with a new name. Manual deletion is effectively undone within seconds.

Terms Worth Knowing

Keep going

You've finished Deployments, ReplicaSets, and Scaling Applications. Continue through the CKAD study guide to build a complete picture of the exam.

Done with this chapter?