Skip to main content
In this lesson we demonstrate how Kubernetes performs rolling updates and how to switch to a recreate-style update. We’ll use the alias k for kubectl throughout (already configured in the environment). Key topics covered: inspecting Deployments, update strategies (RollingUpdate vs Recreate), updating images with kubectl set image, and observing behavior while traffic is served.
Make sure k is aliased to kubectl in your environment. This guide uses k for brevity.
Inspect your current aliases:
Inspect the running pods and the Deployment:
The application is exposed through the KodeKloud portal. Initially the frontend pods serve version v1 with a blue theme:
A plain blue webpage with centered white text at the top saying "Hello from frontend-5c74c57d95-xpwbt!". Below it is smaller text reading "Application Version: v1".
Simulate continuous traffic with the provided curl-test.sh script. While the app is serving v1 you will see output like:
Inspect the frontend Deployment to see the image and update strategy:
Key points from the Deployment:
  • Container image: kodekloud/webapp-color:v1
  • Update strategy: RollingUpdate with 25% maxUnavailable and 25% maxSurge
  • With 4 replicas and maxUnavailable: 25%, at most 1 pod (25% of 4) may be taken down at a time during a rolling update.

Perform a rolling update to v2

Update the Deployment’s image (this updates the pod template and triggers a rolling update):
As the Deployment updates, its revision increments and the controller gradually replaces old pods with new ones according to the RollingUpdate policy:
While the rolling update is in progress, run curl-test.sh to observe live traffic handling. You will typically see interleaved responses from v1 and v2 (blue and green):
This interleaving shows rolling updates replace pods gradually while the Service continues routing traffic.

Switching the Deployment strategy to Recreate

If you change the Deployment spec.strategy.type from RollingUpdate to Recreate, Kubernetes will terminate all existing pods before creating new ones. Edit the Deployment (for example, kubectl edit deployment frontend) and set type: Recreate. Example fragment:
Verify the strategy is now Recreate:

Perform a recreate-style update to v3

Now update the image to v3. With Recreate, Kubernetes will terminate all older pods first and then create the new set:
While the controller is terminating the old pods and before the new ones become ready, you may observe failed requests (e.g., HTTP 502 Bad Gateway from the ingress or load balancer) because no backend pods are available. Example of a temporary ingress failure during the recreate transition:
When the new pods are ready, the curl test will show the app serving v3 (red):
Recreate can cause downtime: all old pods are terminated before new pods are available. Avoid using Recreate if you require zero-downtime deployments, unless you have downstream buffering/load-balancing that can handle the outage.

Comparison: RollingUpdate vs Recreate

Useful commands reference

Summary

  • RollingUpdate upgrades pods a few at a time, following maxUnavailable and maxSurge, to minimize downtime.
  • With 4 replicas and maxUnavailable: 25%, only 1 pod can be unavailable at a time during a rolling update.
  • Recreate terminates all old pods before creating new ones and can cause a service outage during the update.
  • Use kubectl set image to change a Deployment’s image and kubectl describe deploy <name> to inspect the current strategy and pod template.

Further reading

Watch Video