Hello! Welcome to the final lesson of our CI/CD module.
In our last session, you implemented a crucial best practice by switching from the ambiguous :latest tag to an immutable versioning strategy using Git commit hashes. This ensures every Docker image we build is unique and traceable directly to its source code.
Today, we'll see this entire automated pipeline in action and verify one of its most critical production qualities. Our learning outcome is to verify a zero-downtime deployment by monitoring service availability during a rolling update. We will prove that our setup allows us to deploy new code without any user-facing interruptions, a cornerstone of modern software delivery.
The Theory of Zero-Downtime Deployments
In a production environment, deploying code isn't just about getting the new version running; it's about doing so without affecting active users. A user filling out a form or reading a blog post should not experience an error just because we pushed an update. Kubernetes helps us achieve this primarily through a strategy called Rolling Update.
A rolling update gradually replaces old versions of your application with the new version, one pod at a time. This ensures that there are always running, healthy instances of your application available to serve traffic.

In your MERN background, you might compare this to using a process manager like PM2 in cluster mode with its graceful_reload feature. PM2 restarts worker processes one by one. Kubernetes elevates this concept to the container and cluster level, orchestrating the rollout across potentially many machines, providing a much more robust and scalable solution.
For a rolling update to be truly zero-downtime, three key mechanisms must work together:
- Deployment Strategy: The way Kubernetes manages the replacement of old pods with new ones.
- Graceful Startup: Ensuring a new pod only receives traffic when it's fully initialized and ready.
- Graceful Shutdown: Allowing an old pod to finish processing its active requests before it is terminated.
Let's explore each of these.
1. The Rolling Update Strategy
This is configured in your Kubernetes Deployment manifest. The default strategy is RollingUpdate. You can fine-tune its behavior with two key parameters:
maxUnavailable: The maximum number of pods that can be unavailable during the update. This can be an absolute number (e.g.,1) or a percentage (e.g.,25%). Setting this to0(ifmaxSurgeis > 0) ensures you never drop below your desired replica count.maxSurge: The maximum number of new pods that can be created above the desired replica count. This can also be a number or a percentage. Setting this to1(or25%etc.) allows Kubernetes to create a new pod before taking down an old one.
A common configuration for ensuring 100% capacity is:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
This tells Kubernetes: "First, add one new pod (surge). Once it's ready, terminate one old pod. Never let the number of available pods drop below the desired replica count."
2. Graceful Startup with Health Probes
Just because a container is Running doesn't mean your Spring Boot application inside it is ready to handle traffic. It might still be initializing its database connection pool or warming up caches. Sending traffic too early results in errors.
To prevent this, we use Health Probes.

- Readiness Probe: Tells the Kubernetes
Servicewhether a pod is ready to be added to the load-balancing pool. During a deployment, traffic is not sent to a new pod until its readiness probe passes. - Liveness Probe: Checks if the application is still healthy. If it fails, Kubernetes will restart the container.
- Startup Probe: (Optional but recommended for slow-starting apps like Java) Disables liveness and readiness probes until it passes, giving the application ample time to start up without being killed prematurely.
Spring Boot Actuator makes this easy by providing endpoints for these probes. You can enable them in application.yml:
management:
endpoint:
health:
probes:
enabled: true
This exposes /actuator/health/readiness and /actuator/health/liveness, which you then configure in your deployment.yaml.
3. Graceful Shutdown
When Kubernetes decides to terminate an old pod during a rolling update, it sends a SIGTERM signal to the container. The application should catch this signal and:
- Immediately stop accepting new requests.
- Finish processing any in-flight requests.
- Shut down cleanly.
The terminationGracePeriodSeconds field in your pod spec tells Kubernetes how long to wait for this process before forcefully killing the container with SIGKILL.
Spring Boot makes this straightforward. Add this to your application.yml:
server:
shutdown: graceful
spring:
lifecycle:
timeout-per-shutdown-phase: 30s # Should be slightly less than terminationGracePeriodSeconds
This configures the embedded web server (like Tomcat) to perform a graceful shutdown when it receives the SIGTERM signal.
To deepen your understanding of these interconnected concepts, the following video provides an excellent practical walkthrough.
Zero Downtime Deployments in Kubernetes Explained
Watch the following video from 'That DevOps Guy' to see a detailed explanation and demonstration of how these components work together. Pay close attention to how rolling updates, readiness probes, and termination grace periods prevent downtime.
Please watch these three segments: The basics of rolling updates (04:24 - 10:01). The role of Kubernetes Services in routing traffic during updates (10:01 - 13:26). The concept of graceful startup using readiness probes (32:29 - 38:09).
Your Task: Verifying Zero Downtime
Now, let's put this theory into practice. You will generate continuous traffic to your blog service, trigger a new deployment via your CI/CD pipeline, and monitor the traffic to confirm no requests are dropped.
Step 1: Set Up Your Monitoring Client
First, we need a way to constantly hit our service endpoint and report any failures. We'll deploy a simple client pod inside your EKS cluster for this.
-
Launch a client pod: Open your terminal configured with
kubectlaccess to your EKS cluster. Run the following command to create a simpleubuntupod we can use as a testing client.kubectl run traffic-generator --image=ubuntu -- bash -c "while true; do sleep 3600; done" -n <your-namespace>Replace
<your-namespace>with the namespace your blog service is in. This command creates a pod that simply sleeps, waiting for you to connect. -
Access the client pod: Once the pod is in the
Runningstate, open a shell into it:kubectl exec -it traffic-generator -n <your-namespace> -- bash -
Install
curl: Inside the pod's shell, you'll need a tool to make HTTP requests.apt-get update && apt-get install -y curl -
Start generating traffic: Now, run a loop that continuously sends requests to your service. You'll need the internal DNS name of your API Gateway's service. This is typically
<service-name>.<namespace>.svc.cluster.local.# Replace <gateway-service-name> and <your-namespace> while true; do curl -s -o /dev/null -w "%{http_code}\n" http://<gateway-service-name>.<your-namespace>.svc.cluster.local/api/posts sleep 0.5 doneThis script will continuously print the HTTP status code of the response from your
/api/postsendpoint. You should see a steady stream of200. Leave this terminal running.
Step 2: Trigger a New Deployment
With your monitoring client running, it's time to trigger a deployment.
- Make a small code change: In your local editor, open a file in your
blog-serviceproject. Make a trivial change, such as modifying a log message or adding a comment. - Commit and push: Commit the change and push it to your
mainbranch.git add . git commit -m "feat: Trigger deployment to verify zero downtime" git push origin main
Step 3: Observe the Rolling Update
Now, watch the magic happen. You should have three terminals open:
- The one running the
curlloop. - A new terminal where you'll watch the pods.
- Your web browser open to your GitHub Actions workflow run.
In the second terminal, run:
kubectl get pods -n <your-namespace> --watch
As you watch your GitHub Actions workflow progress, you will eventually see the deployment step execute. At that moment, you will observe the following in your kubectl watch terminal:
- A new pod for your
blog-servicewill appear with the statusPending, thenContainerCreating. - Once the image is pulled, it will become
Running, but itsREADYstatus will be0/1. This is because the readiness probe has not yet passed. - After a short delay (for your app to start up), the
READYstatus will become1/1. - Only then will one of the old pods change its status to
Terminating. - This process will repeat until all old pods are replaced by new ones tagged with the new Git commit hash.
The Moment of Truth:
Look at your first terminal—the one running the curl loop. If everything is configured correctly, you should see an uninterrupted stream of 200 status codes. There should be no "connection refused," no timeouts, and no 5xx errors. This is the proof of a successful zero-downtime deployment.
Conclusion
Congratulations on completing the CI/CD and deployment module! You have successfully built and verified a production-grade, automated deployment system.
Key Takeaways:
- Zero-downtime deployments are achieved by the synergy between the orchestrator (Kubernetes) and the application (Spring Boot).
- The Kubernetes Rolling Update strategy, combined with
maxSurgeandmaxUnavailable, ensures continuous availability at the infrastructure level. - Readiness Probes are essential for
Graceful Startup, preventing traffic from hitting uninitialized application instances. - Graceful Shutdown in Spring Boot, paired with
terminationGracePeriodSecondsin Kubernetes, ensures in-flight requests are completed before a pod is terminated. - Active monitoring during a deployment is the only way to truly verify that your configuration is working as expected.
Preview of the Next Lesson:
Our pipeline can now securely and reliably deploy code to production without downtime. But how do we ensure the code itself is high quality? In our final module, "Testing and Integrating the Full System," we'll shift our focus from infrastructure to code quality. You'll start by learning to write unit tests for your service layer using JUnit 5 and Mockito, a fundamental skill for any backend developer.