Kubernetes Deployments Explained: Rolling Updates and Rollbacks
Learn how Kubernetes Deployments manage Pods, scale applications, perform rolling updates, roll back releases and troubleshoot common Pod issues.

✍️ Translate this blog into Hindi, Tamil or Telugu
Introduction
Imagine you have an application running on Kubernetes. Everything is working correctly, but now you want to release a newer version.
How do you update the application without manually deleting the existing Pods?
What happens if the new version does not work?
🛍️✨ From the author · ByteStore1:1 DevOps Project & Learning Discussionโน500View offer →And how can you return to the previous working version?
This is where Kubernetes Deployments help.
A Deployment manages application Pods and helps us:
Create and maintain the required number of Pods.
Scale applications up or down.
Update applications gradually.
Check whether an update has completed.
Roll back to a previous version when needed.
A ReplicaSet maintains Pods, but how do we safely update an application? That's where Deployments help.
1. What Is a Kubernetes Deployment?
A Kubernetes Deployment is a resource that manages the lifecycle of application Pods.
Instead of creating and managing individual Pods manually, we tell Kubernetes what we want.
For example:
Run 3 copies of an NGINX application.
Keep all 3 copies available.
Use NGINX version 1.27.
Update to version 1.28 when required.
The Deployment continuously works to maintain the desired state.
If one Pod fails, Kubernetes works to replace it.
Think of a Deployment as a manager who makes sure the required number of workers are available.
2. Understand Deployment, ReplicaSet and Pods
Before creating a Deployment, let's understand how these three resources are connected.
Deployment โ ReplicaSet โ Pods
Deployment: Manages application updates and the desired state.
ReplicaSet: Makes sure the required number of Pods are running.
Pods: Run the actual application containers.
For example, when we create a Deployment with 3 replicas:
The Deployment creates a ReplicaSet.
The ReplicaSet creates 3 Pods.
If a Pod fails, the ReplicaSet works to replace it.
The Deployment manages the ReplicaSet, and the ReplicaSet manages the Pods.

3. Prerequisites
Before starting, make sure you have:
A running Kubernetes cluster.
kubectlinstalled and configured.Basic knowledge of YAML.
We'll use Minikube in the examples, but any suitable Kubernetes cluster works.
Check your cluster:
kubectl get nodesExpected output will show your cluster node with the status Ready.
4. Create Your First Deployment
Let's create a Deployment that runs three NGINX Pods.
Create a file named nginx-deployment.yaml.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.27
ports:
- containerPort: 80Let's understand the important fields:
| Field | Meaning |
|---|---|
apiVersion | API version used to create the resource |
kind | Type of Kubernetes resource |
metadata.name | Name of the Deployment |
replicas | Number of Pods we want |
selector | Identifies the Pods managed by the Deployment |
template | Describes how the Pods should be created |
containers | Defines the container inside the Pod |
image | Container image to run |
containerPort | Port the container is configured to use |
Important: The labels in template.metadata.labels must match the selector in spec.selector.matchLabels.
Important: containerPort: 80 documents the port used by the container. It does not expose the application outside the Pod or make it accessible to users. A Kubernetes Service provides a way to expose the application.
The Deployment selector is generally immutable after creation. If you need to change it, you normally create a new Deployment with the correct selector rather than trying to update the existing selector.
Also, containerPort: 80 documents the port used by the container. It does not expose the application outside the Pod or make it accessible to users. We will learn how Kubernetes Services provide access in the next article.
Apply the YAML file
kubectl apply -f nginx-deployment.yamlThis command creates the Deployment from the YAML file.
Check the Deployment:
kubectl get deploymentsWait until the READY column shows 3/3.
Check the Pods:
kubectl get pods -l app=nginxYou should see three NGINX Pods running.
Check the ReplicaSet:
kubectl get rsYou should see a ReplicaSet with three desired and ready replicas for this Deployment.
To check the Deployment in more detail:
kubectl describe deployment nginx-deployment
5. Scale a Deployment
Suppose your application initially runs 3 Pods.
Now more users are accessing the application, so you want to increase the number of Pods to 5.
This is called scaling up.
Run:
kubectl scale deployment nginx-deployment --replicas=5Verify:
kubectl get deploymentsWait until READY shows 5/5.
Now let's reduce the number of Pods to 2.
kubectl scale deployment nginx-deployment --replicas=2Verify:
kubectl get deploymentsWait until READY shows 2/2.
Restore the count to 3:
kubectl scale deployment nginx-deployment --replicas=3Verify again:
kubectl get deploymentsWait until READY shows 3/3 before continuing.
Remember:
Scaling up increases the number of Pods.
Scaling down decreases the number of Pods.
Scaling changes the replica count; it does not change the Pod template, so it does not create a new Deployment revision by itself.
6. Understand Deployment Update Strategies
Kubernetes supports different Deployment update strategies.
Two commonly used strategies are:
RollingUpdate
A RollingUpdate gradually replaces old Pods with new Pods.
For example, when updating NGINX from 1.27 to 1.28, Kubernetes creates new Pods and gradually removes the old ones.
This helps maintain application availability during an update.
Recreate
The Recreate strategy terminates the existing Pods before creating new Pods with the updated configuration.
This can cause downtime because the old Pods are removed before the new Pods become available.
| Strategy | How it works |
|---|---|
RollingUpdate | Gradually replaces old Pods with new Pods |
Recreate | Terminates old Pods before creating new Pods |
For applications that should remain available during updates, RollingUpdate is commonly preferred.
Understand RollingUpdate settings
A RollingUpdate strategy can be configured with:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%These settings will be included in the complete Deployment YAML in Section 12, so you don't need to edit your file separately at this stage.
Let's understand the fields:
| Field | Meaning |
|---|---|
maxSurge | Maximum additional Pods allowed during an update |
maxUnavailable | Maximum Pods allowed to be unavailable during an update |
For 3 replicas:
maxSurge: 25%rounds up to 1 additional Pod.maxUnavailable: 25%rounds down to 0 unavailable Pods.
These settings help Kubernetes control how the update happens.
Note: Changing the update strategy alone does not create a new Deployment revision if the Pod template remains unchanged.

7. Perform a Rolling Update
Imagine your application is running NGINX version 1.27.
Now you want to upgrade it to NGINX version 1.28.
Before updating, open another terminal and run:
kubectl get pods -wThe -w option means watch. It continuously displays changes in Pod status.
Keep this terminal open while performing the update.
In your first terminal, add a change-cause annotation:
kubectl annotate deployment nginx-deployment \
kubernetes.io/change-cause="Update NGINX to 1.28" \
--overwriteThis adds a description that can be displayed in the rollout history.
Now update the container image:
kubectl set image deployment/nginx-deployment nginx=nginx:1.28Here:
deployment/nginx-deploymentidentifies the Deployment.nginxis the container name.nginx:1.28is the new container image.
Check the rollout:
kubectl rollout status deployment/nginx-deploymentWhen the update finishes, Kubernetes reports:
deployment "nginx-deployment" successfully rolled outVerify the image:
kubectl get deployment nginx-deployment \
-o jsonpath='{.spec.template.spec.containers[0].image}'Expected output:
nginx:1.28Return to the second terminal and observe the Pod changes. Press Ctrl+C to stop watching.
The exact sequence and timing of Pod changes can vary depending on the cluster.
8. Understand ReplicaSets During a Rolling Update
What happens to the ReplicaSets when we update the image?
Suppose the original Deployment runs NGINX 1.27.
When we update it to NGINX 1.28:
Kubernetes creates a new ReplicaSet for the updated Pod template.
The new ReplicaSet creates the new Pods.
The old ReplicaSet gradually scales down.
The old ReplicaSet is retained for possible rollback.
Check the ReplicaSets:
kubectl get rsYou may see output similar to:
NAME DESIRED CURRENT READY
nginx-deployment-old-hash 0 0 0
nginx-deployment-new-hash 3 3 3The actual ReplicaSet names contain generated hashes.
The old ReplicaSet has zero replicas, while the new ReplicaSet manages the three running Pods.
This is how Kubernetes keeps the previous Deployment configuration available for rollback.
9. Check Deployment Rollout History
Kubernetes keeps a history of Deployment revisions.
A revision represents a change to the Deployment's Pod template.
For example, changing the container image or adding a readiness probe creates a new revision.
Check the history:
kubectl rollout history deployment/nginx-deploymentExample output:
REVISION CHANGE-CAUSE
1 <none>
2 Update NGINX to 1.28The actual revision numbers and change-cause values depend on the changes made to your Deployment.
To view details of a particular revision:
kubectl rollout history deployment/nginx-deployment --revision=2Replace 2 with a revision that exists in your Deployment history.
Why can CHANGE-CAUSE appear on multiple revisions?
The kubernetes.io/change-cause annotation is stored in the Deployment's metadata.
When a later revision is created, that annotation may still be present. As a result, the same change-cause description can appear against more than one revision.
It is a useful description, but it should not be treated as a unique revision identifier.
Important: Add or update the annotation before making a Pod-template change if you want to record a meaningful description for that change.
10. Roll Back a Deployment
Suppose you updated your application to NGINX 1.28.
After the update, you discover that the new version is causing problems.
You want to return to the previous working version.
This is called a rollback.
Kubernetes allows us to undo a Deployment rollout.
Run:
kubectl rollout undo deployment/nginx-deploymentCheck the rollout:
kubectl rollout status deployment/nginx-deploymentVerify the image:
kubectl get deployment nginx-deployment \
-o jsonpath='{.spec.template.spec.containers[0].image}'If the previous version was NGINX 1.27, the output should be:
nginx:1.27Roll back to a specific revision
You can also select a particular revision.
First, check the available history:
kubectl rollout history deployment/nginx-deploymentThen use a revision that exists in the history:
kubectl rollout undo deployment/nginx-deployment --to-revision=2Here, 2 is only an example. Check your actual history before running the command.
Important for this lab: Do not run the example command above. In the sequence used in this article, revision 2 represents the NGINX 1.28 template. Running it would restore NGINX 1.28 instead of keeping the rolled-back NGINX 1.27 version.
A rollback creates a new revision. Revision numbers may change after a rollback, and older revision numbers may disappear from the displayed history.
11. Understand YAML Drift
Let's understand an important situation that can happen when using both YAML files and kubectl commands.
Imagine you had updated your local YAML file to use NGINX 1.28, but later rolled back the live Deployment to NGINX 1.27.
Your configurations would look like this:
Local YAML file:
image: nginx:1.28Live Deployment:
image: nginx:1.27This difference is called configuration drift.
What happens if you apply the YAML file again?
kubectl apply -f nginx-deployment.yamlKubernetes will apply the configuration from the file. The image can change back to NGINX 1.28.
Do not apply this hypothetical example in our lab. Our YAML file still contains nginx:1.27, which matches the live Deployment after the rollback.
To avoid configuration drift, keep your YAML file updated whenever you intentionally change the Deployment configuration.
This is especially important when managing Kubernetes resources through Git and CI/CD pipelines.
12. Add a Readiness Probe
So far, Kubernetes has been checking whether the Pods are running.
But is a running container always ready to receive application traffic?
Not necessarily.
A container can be running while the application inside it is still starting.
A readiness probe helps Kubernetes determine whether a container is ready to receive traffic.
Let's add a readiness probe to our NGINX Deployment.
Update the complete nginx-deployment.yaml file with the following content:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.27
ports:
- containerPort: 80
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 5Let's understand the readiness probe settings:
| Field | Meaning |
|---|---|
readinessProbe | Defines the readiness check |
httpGet | Checks the application using an HTTP request |
path: / | Sends the request to the root path |
port: 80 | Uses port 80 |
initialDelaySeconds: 5 | Waits 5 seconds before the first check |
periodSeconds: 5 | Performs the check every 5 seconds |
Before applying the YAML, add a change-cause annotation:
kubectl annotate deployment nginx-deployment \
kubernetes.io/change-cause="Add readiness probe" \
--overwriteApply the updated YAML:
kubectl apply -f nginx-deployment.yamlCheck the rollout:
kubectl rollout status deployment/nginx-deploymentCheck the rollout history:
kubectl rollout history deployment/nginx-deploymentThe readiness probe changes the Pod template, so Kubernetes creates a new revision.
Verify the readiness probe:
kubectl get deployment nginx-deployment \
-o jsonpath='{.spec.template.spec.containers[0].readinessProbe}'You should see the HTTP GET configuration in the output.
Finally, check the Pods:
kubectl get pods -l app=nginxThe three Pods should show 1/1 under READY and Running under STATUS once they are ready.

Remember: A readiness probe controls whether a Pod is considered ready to receive traffic. A failed readiness probe does not restart the container. Liveness probes are used for checking whether a container should be restarted.
13. Troubleshooting: ImagePullBackOff
What happens if Kubernetes cannot download the container image?
For example, imagine you provide an image name that does not exist.
Let's create a separate namespace for troubleshooting.
kubectl create namespace deployment-troubleshootingCreate a Deployment with an incorrect image:
kubectl create deployment nginx-broken \
--image=nginx:does-not-exist \
-n deployment-troubleshootingCheck the Pods:
kubectl get pods -n deployment-troubleshootingYou may see:
NAME READY STATUS
nginx-broken-xxxxxxxxxx-xxxxx 0/1 ImagePullBackOffThe generated Pod name will be different in your cluster.
Sometimes ErrImagePull appears first. After repeated attempts, Kubernetes commonly changes the status to ImagePullBackOff.
To understand the problem, describe the Pod:
kubectl describe pod POD_NAME -n deployment-troubleshootingReplace POD_NAME with the actual Pod name from kubectl get pods.
Look at the Events section. You may find an error indicating that the image could not be found.
Fix the incorrect image
Update the Deployment with a valid image:
kubectl set image deployment/nginx-broken nginx=nginx:1.27 \
-n deployment-troubleshootingCheck the rollout:
kubectl rollout status deployment/nginx-broken \
-n deployment-troubleshootingVerify:
kubectl get pods -n deployment-troubleshootingThe new Pod should eventually become 1/1 Running.
14. Troubleshooting: CrashLoopBackOff
Another common problem is CrashLoopBackOff.
Imagine your application starts but exits with an error.
Kubernetes tries to restart the container, but the container keeps failing.
After repeated failures, Kubernetes uses an increasing delay between restart attempts. This is called back-off.
Let's create a Deployment that intentionally fails.
Create a file named crash-demo.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: crash-demo
namespace: deployment-troubleshooting
spec:
replicas: 1
selector:
matchLabels:
app: crash-demo
template:
metadata:
labels:
app: crash-demo
spec:
containers:
- name: busybox
image: busybox
command: ["sh", "-c"]
args:
- echo "Application started"; echo "Database connection failed"; exit 1This example uses BusyBox to print two messages and then exit with status code 1.
Exit code 1 indicates that the command failed.
Apply the YAML file:
kubectl apply -f crash-demo.yamlCheck the Pods:
kubectl get pods -n deployment-troubleshootingYou should eventually see CrashLoopBackOff in the STATUS column.
Describe the Pod
kubectl describe pod POD_NAME -n deployment-troubleshootingReplace POD_NAME with the actual Pod name.
Look for:
Last State
The container's Waiting reason
Exit Code
Restart Count
Events
You may see the container terminated with exit code 1 and a Waiting reason of CrashLoopBackOff.
Check container logs
kubectl logs POD_NAME -n deployment-troubleshootingThe output should contain:
Application started
Database connection failedTo view logs from the previous container instance:
kubectl logs POD_NAME --previous -n deployment-troubleshootingThe --previous option is useful when a container has restarted and you need to inspect its earlier logs.
Important: The Pod's STATUS column can show CrashLoopBackOff, while its Pod phase may still be Running. This is because the Pod exists, but its container is repeatedly failing and restarting.
15. Understand ProgressDeadlineExceeded
A Deployment can sometimes get stuck during an update.
For example:
New Pods cannot start.
Images cannot be downloaded.
Readiness checks keep failing.
New replicas do not become available.
Kubernetes monitors Deployment progress.
By default, progressDeadlineSeconds is 600 seconds.
If Kubernetes does not observe sufficient progress within the configured deadline, the Deployment reports a condition with the reason:
ProgressDeadlineExceeded
This does not mean Kubernetes automatically rolls back the Deployment.
You must inspect the problem and decide how to fix it or roll back.
Useful commands:
kubectl describe deployment nginx-deploymentkubectl get podskubectl get eventsThese commands help you investigate the Deployment, Pods and cluster events.
16. Important Kubernetes Deployment Commands
Here is a quick reference for the commands used in this article.
| Command | Purpose |
|---|---|
kubectl apply -f nginx-deployment.yaml | Create or update a Deployment using YAML |
kubectl get deployments | List Deployments |
kubectl get pods | List Pods |
kubectl get rs | List ReplicaSets |
kubectl describe deployment nginx-deployment | View Deployment details |
kubectl get deployment nginx-deployment -o yaml | View the Deployment YAML |
kubectl scale deployment nginx-deployment --replicas=5 | Change the replica count |
kubectl annotate deployment nginx-deployment kubernetes.io/change-cause="Update" --overwrite | Add or update a change-cause annotation |
kubectl set image deployment/nginx-deployment nginx=nginx:1.28 | Update the container image |
kubectl rollout status deployment/nginx-deployment | Check rollout progress |
kubectl rollout history deployment/nginx-deployment | View revision history |
kubectl rollout undo deployment/nginx-deployment | Roll back the latest rollout |
kubectl rollout undo deployment/nginx-deployment --to-revision=2 | Roll back to a selected revision (example; check history first) |
kubectl rollout restart deployment/nginx-deployment | Restart Pods managed by the Deployment |
kubectl rollout pause deployment/nginx-deployment | Pause a rollout |
kubectl rollout resume deployment/nginx-deployment | Resume a paused rollout |
kubectl create namespace deployment-troubleshooting | Create a troubleshooting namespace |
kubectl describe pod POD_NAME | Inspect a Pod |
kubectl logs POD_NAME | View container logs |
kubectl logs POD_NAME --previous | View logs from the previous container instance |
Replace example resource names and Pod names with the actual names in your cluster. Include the namespace option when working with resources outside the default namespace.
17. Clean Up the Resources
After completing the hands-on exercise, delete the resources created for this article.
Delete the main Deployment:
kubectl delete deployment nginx-deploymentDelete the troubleshooting namespace:
kubectl delete namespace deployment-troubleshootingDeleting the namespace also removes the resources created inside it, including the troubleshooting Deployments and their Pods.
The local YAML files remain on your computer. If you no longer need them, you can remove them separately:
rm nginx-deployment.yaml crash-demo.yamlNote: Do not delete resources that you still need for other labs.
18. What Did We Learn?
Let's quickly recap what we covered.
A Deployment manages application Pods.
A ReplicaSet maintains the desired number of Pods.
Scaling changes the number of replicas.
Rolling Updates gradually replace old Pods with new Pods.
Recreate removes old Pods before creating new ones.
Rollout history helps us inspect Deployment revisions.
Rollbacks help us return to a previous Pod template.
A readiness probe checks whether an application is ready to receive traffic.
ImagePullBackOffcommonly occurs when Kubernetes cannot download an image.CrashLoopBackOffoccurs when a container repeatedly fails and restarts.ProgressDeadlineExceededindicates that a Deployment has not made sufficient progress within its configured deadline.
One important point to remember: A rollback creates a new revision. It does not simply restore the old revision number.
Conclusion
Kubernetes Deployments make application management easier by handling Pod creation, scaling, updates and rollbacks.
Instead of manually replacing Pods whenever an application changes, we can define the desired state and let Kubernetes work towards it.
Understanding Deployments is an important step in learning Kubernetes because many real-world applications use Deployments to manage stateless workloads.
In the next article, we will learn about Kubernetes Services and understand how applications communicate with Pods even when Pod IP addresses change.
What's Next?
Now that we understand how Kubernetes Deployments manage ReplicaSets, update applications and roll back changes, let's move to the next concept: Kubernetes Services.
We will learn:
What a Kubernetes Service is and why we need it.
How a Service provides a stable way to access Pods.
The difference between ClusterIP, NodePort and LoadBalancer.
How to expose an application running inside a Kubernetes cluster.
How Services continue routing traffic when Pods are replaced.
Kubernetes Learning Series
Kubernetes Pods Explained: Architecture, Lifecycle and Practical Examples
Kubernetes ReplicaSets Explained: Maintaining the Desired State
Kubernetes Deployments Explained: Rolling Updates and Rollbacksย - You are here.
How Pods, ReplicaSets and Deployments Work Together - upcoming article.
Remember: Kubernetes helps us manage applications by maintaining the desired state, even when Pods change.
🛍️ Malathi Shetty's shelf
Courses, cohorts and more from the authorGet Malathi Shetty's next blog by email
One email a week when they publish. Add the weekly Best of ByteBlog too. No spam, unsubscribe with one click.
We email you once to confirm. By subscribing you agree to the privacy policy.
More from Malathi Shetty

Kubernetes Pods: Architecture, Lifecycle & Examples
Kubernetes is a powerful platform for managing containers, but understanding how it works can feel confusing when we encounter terms such as Pods, Nodes...
#cloud-native
Kubernetes ReplicaSets Explained: Maintaining the Desired State
Understand how Kubernetes ReplicaSets maintain the desired number of Pods, replace deleted Pods, and work with Deployments through practical examples.
#container-orchestration
Docker vs Kubernetes: Understanding Containers
Docker made it easier to package and run applications. But what happens when you need to manage hundreds of containers across multiple servers?
#cloudcomputing
Kubernetes Basics Through a Restaurant Kitchen
Have you ever opened a Kubernetes tutorial, seen words like Pod, Node, Control Plane, ReplicaSet and DaemonSet, and wondered how they all connect?

💬 Comments (0)
Top · NewestSign in to comment