Kubernetes Rolling Updates Respect pod readiness before updating
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Kubernetes has become a cornerstone in the orchestration of containerized applications, enabling efficient and scalable deployment strategies. Among its myriad features, rolling updates stand out as a method to update applications with minimal downtime. However, a critical aspect often overlooked is respecting pod readiness, which ensures seamless transitions during these updates.
Understanding Rolling Updates
A rolling update in Kubernetes gradually replaces older versions of your application pods with the new ones, one or more at a time, ensuring that the application remains available throughout the process. The `Deployment` resource primarily handles this by managing the desired state, controlling the rollout of new replicas, and phasing out the old ones.
The primary advantage of rolling updates is reducing downtime. However, ensuring that each new pod is ready before terminating an old one is crucial. This process hinges on understanding and leveraging pod readiness probes.
Respecting Pod Readiness
Pod readiness is a concept that pertains to the operational state of a pod and is determined using readiness probes. Kubernetes makes use of the readiness probes to decide when a pod is ready to accept traffic. Only when a pod passes its readiness probe does it become eligible to serve client requests.
Deep Dive Into Pod Readiness Probes
Readiness probes can be configured in various ways:
- HTTP Probe: Sends an HTTP GET request to the specified path and port; the pod is considered ready if the response is a success (HTTP status 200-399).
- Command Probe: Executes a command within the pod's container; the pod is ready if the command exits with a status code of 0.
- TCP Socket Probe: Tries to establish a TCP connection on the specified port; success indicates the pod is ready.
Sample Readiness Probe Configuration
Let's consider the following Kubernetes manifest snippet with a readiness probe:
- name: myapp-container
- Waiting for 5 seconds (`initialDelaySeconds`) before initiating the first probe.
- Checking every 10 seconds (`periodSeconds`) to determine if the pod returns a satisfactory HTTP response at `/health`.
- `maxUnavailable`: The maximum number of pods that can be unavailable during the update. The default is 25% of the desired replicas.
- `maxSurge`: The maximum number of pods that can be created over the desired amount during the update. The default is also 25% of the desired replicas.

