Skip to main content
In this lesson, we explore rolling updates and rollbacks, with a focus on rolling updates. We will demonstrate how to verify your environment and update your application while ensuring minimal downtime. For simplicity, we use an alias (k) for kubectl. The alias is confirmed to be set with the following output:

Checking the Application Deployment

We have deployed a simple web application. First, inspect the Pods:
Then, check the Deployment details:
Wait for the application to be fully deployed. Once it is ready, open the provided web app portal in your browser. The application displays the message “hello, front end moment.”

Q1: What Is the Current Color of the Web Application?

Recheck the Pods and Deployment information:
After running a test script that sends multiple requests, the output confirms the application color is blue:
This script simulates multiple users accessing the web application, confirming that all responses return the blue color. Additionally, the deployment details confirm that four Pods have been created as expected.

Q2: What Container Image Is Used to Deploy the Application?

To inspect the container image, first get the deployment details:
Then, describe the deployment to view the pod template:
The container image used is “kodekloud/web-app-color:v1”.

Q3: What Is the Current Deployment Strategy?

The deployment details show that a rolling update strategy is in use. With this strategy, Pods are replaced one at a time, ensuring continuous availability. Specifically, only 25% of Pods are allowed to be unavailable at any given moment, preventing complete downtime.
A rolling update strategy allows gradual replacement of Pods to ensure that some instances are always available during an upgrade.

Upgrading the Application to Version 2

To upgrade the application, update the image in the deployment to version 2 using the “kubectl set image” command. Our container name is “simple-webapp”. Run the following command:
After executing the command, verify that the image has been updated by describing the deployment again. You should now see version v2 in the container image field. Run the curl test (or your test script) again:
The output may initially show a mix of blue and green responses:
This indicates a gradual rollout where some Pods still run the older version (blue) and others have been updated (green). Eventually, all responses will reflect the new version.

Scaling Considerations During a Rollout

With the current rolling update settings (25% max unavailable) and a deployment of 4 replicas, only one Pod is taken down at a time. The following command confirms these updates and settings:

Changing the Deployment Strategy to Recreate

If you prefer to minimize complexities related to gradual updates, you can change the deployment strategy to “Recreate”. This strategy terminates all running Pods before creating new ones. To update the deployment strategy, use kubectl edit on the deployment and modify the strategy section as shown below:
After saving the changes, verify that the strategy has been updated to “Recreate”. Note that the recreate strategy does not support rolling update parameters.
Switching to the “Recreate” strategy may cause temporary downtime since all Pods are terminated before new ones are created.

Upgrading the Application to Version 3

Finally, upgrade the application by setting the deployment image to version 3:
Then, run your test script once again:
Since the deployment strategy is now set to “Recreate”, you might experience a brief period of downtime with failed requests (e.g., “Failed” messages or “bad gateway” errors) during the Pod replacement process. Once the new Pods are running, the output should stabilize to:
This confirms that the new version (v3) displaying red is fully deployed. That concludes the lesson on rolling updates and rollbacks.

Watch Video