Skip to main content
Welcome to this comprehensive guide on managing deployments in Kubernetes. In this article, you’ll learn how to perform rolling updates, roll back changes, and effectively manage deployment revisions. When you create a deployment, Kubernetes automatically triggers a rollout, establishing your initial deployment revision (revision one). Later, when you upgrade your application (for example, by updating the container image version), a new rollout is triggered and a new deployment revision (revision two) is created.
The image illustrates a rollout and versioning process, showing two revisions of Nginx versions 1.7.0 and 1.7.1, each with multiple instances.
This revision history lets you track changes and enables you to roll back to a previous version if necessary. You can monitor the status of a rollout by running:
The output might be similar to:
To view the deployment’s revision history, use:

Deployment Strategies

There are two primary deployment strategies to consider when updating your application:
  1. Recreate Strategy:
    In this approach, all existing replicas are terminated before new ones are created. Although this creates a completely fresh environment, it results in downtime due to the gap between terminating the old pods and starting the new ones.
  2. Rolling Update Strategy:
    This strategy updates instances incrementally. Kubernetes gradually terminates old pods while simultaneously starting new ones, ensuring continuous application availability. Rolling updates are applied by default unless a different strategy is specified during deployment creation.
The image illustrates two deployment strategies, "Recreate" and "Rolling Update," showing version transitions of nginx with corresponding application downtime and uptime indicators.
Kubernetes defaults to the rolling update strategy to minimize downtime during deployments.

Updating a Deployment

There are several ways to update a deployment, such as changing your container image, modifying labels, or adjusting the replica count. If you maintain a deployment configuration file, you can modify it directly. For example:
After updating the file, apply the changes using:
This command initiates a new rollout and creates a new deployment revision. Alternatively, update the container image directly with:
The kubectl set image command edits the live deployment configuration. This modification may not be reflected in your deployment definition file, so use it with care if you plan to maintain consistency through file-based updates.

Examining Deployment Details

To inspect detailed information about a deployment—including its strategy—run:
When using the recreate strategy, you will see that the old replica set is scaled down to zero before the new replica set is scaled up. For example:
For rolling updates, the output shows a gradual transition:
These examples clearly illustrate the differences between the recreate and rolling update strategies.

How Upgrades Work Under the Hood

When a deployment is initially created (for example, deploying five replicas), Kubernetes automatically creates a replica set that spawns the required pods. During an upgrade, a new replica set is generated for the updated containers while the pods from the previous replica set are gradually terminated according to the rolling update strategy.
The image shows a Kubernetes deployment diagram with five pods in a replica set, labeled "Upgrades."
You can verify the changes by listing the replica sets:
Before the upgrade, the old replica set displays the active pods, and after updating, you will see the new replica set with updated pod counts.

Rolling Back an Update

If you encounter issues with a new release, Kubernetes allows you to roll back to a previous deployment revision. To perform a rollback, simply execute:
The output will confirm the rollback:
Before executing the rollback, the new replica set might show all pods (for instance, five replicas) while the old replica set shows none. After the rollback, these counts are reversed.

Summary of Essential Commands

Below is a summary table of commands that are crucial for managing your deployments: These commands empower you to create, update, monitor, and roll back deployments efficiently, ensuring minimal downtime and a smooth upgrade process. For further insights, consider reviewing the Kubernetes Documentation.

Watch Video