Demonstrates Kubernetes Deployment RollingUpdate versus Recreate strategies by upgrading a sample app to show how rolling updates preserve availability while Recreate causes downtime
In this hands-on demo you’ll see the practical difference between the RollingUpdate and Recreate deployment strategies in Kubernetes. We’ll deploy a small HTTP app that returns its version (v1 or v2) and observe behavior during an upgrade. This shows how each strategy affects availability and rollout behavior.What you’ll learn:
How to deploy a simple Deployment and Service
How RollingUpdate preserves availability during updates
How Recreate causes downtime by terminating all pods before creating new ones
Note: The manifest above omits a strategy section. Kubernetes defaults to the RollingUpdate strategy when strategy is not specified.
If you require zero-downtime updates, RollingUpdate is the default and preferred choice. The Recreate strategy will terminate all existing pods before creating new ones, which causes an interruption in service.
Because RollingUpdate is the default strategy, updating the Deployment image will perform a rolling upgrade: new pods are created and traffic shifts gradually from old pods to new pods.Update the image to v2 using kubectl set image:
Copy
kubectl -n rolling-recreate set image deployment/app app=siddharth67/app:v2
kubectl will respond:
Copy
deployment.apps/app image updated
Sample polling output (shows continuous responses transitioning from v1 to v2 without downtime):
Explanation: RollingUpdate creates new pods running v2 while terminating old v1 pods in a controlled manner, maintaining service availability during the rollout.
To demonstrate downtime, change the Deployment strategy to Recreate. Edit the deployment:
Copy
kubectl -n rolling-recreate edit deployment app
Add or modify the strategy section in the spec:
Copy
strategy: type: Recreate
Save the edit. Confirm the deployment now uses Recreate:
Copy
kubectl -n rolling-recreate get deploy app -o yaml
You should see:
Copy
spec: replicas: 5 strategy: type: Recreate
Now update the image again (flip it back to v1 to see downtime):
Copy
kubectl -n rolling-recreate set image deployment/app app=siddharth67/app:v1
kubectl will report:
Copy
deployment.apps/app image updated
Behavior: With Recreate, Kubernetes terminates all existing pods immediately and only then creates the new pods. During the gap between pod termination and the new pods becoming Ready, the Service has no ready endpoints and will return timeouts or errors.Example polling output showing downtime:
Using the Recreate strategy will cause downtime because all old pods are terminated before new pods are created. Use Recreate only when you must avoid running multiple versions concurrently and can tolerate interruptions.