Kubernetes Rolling Update: Strategies for Zero Downtime

Learn how to implement Kubernetes rolling updates to achieve zero downtime during application deployments.

Overview

Kubernetes Rolling Updates is a deployment strategy that enables you to update your applications without downtime by incrementally replacing instances of your application with new ones. This approach ensures that some instances of the application are always available, which is crucial for maintaining service reliability in production environments.

How it works

In a Rolling Update, Kubernetes gradually updates pods with the new version of an application while keeping some of the old instances running until the new ones are live. This method is advantageous because it effectively manages application availability during the update. Below is a simple YAML configuration that represents a Deployment using the Rolling Update strategy:

apiVersion: apps/v1  
kind: Deployment  
metadata:  
  name: my-app  
spec:  
  replicas: 5  
  strategy:  
    type: RollingUpdate  
    rollingUpdate:  
      maxUnavailable: 1  
      maxSurge: 1  
  selector:  
    matchLabels:  
      app: my-app  
  template:  
    metadata:  
      labels:  
        app: my-app  
    spec:  
      containers:  
      - name: my-app  
        image: my-app:latest  
        ports:  
        - containerPort: 8080

Key Parameters

Parameter Description
maxUnavailable The maximum number of pods that can be unavailable during the update.
maxSurge The maximum number of pods that can be created over the desired number of pods.
replicas The number of instances of the application to run.
containers List of containers and their configurations to run in each pod.

In the above example, during a rolling update, if one pod is being updated (leading to a temporary unavailability), at least four pods will remain available due to the maxUnavailable setting.

Common Mistakes

  • Setting maxUnavailable too high: This may lead to more downtime than intended.
  • Ignoring readiness probes: Not defining readiness probes can cause traffic to be routed to still initializing pods.
  • Not testing updates in staging: Failing to validate the new version before deployment can lead to unexpected failures in production.
  • Neglecting to monitor: During a rolling update, it's essential to observe application performance and logs in real-time to spot issues early.

FAQ

Q: What strategy should you choose to ensure zero downtime updates in Kubernetes?
A: The Rolling Update strategy allows for incremental updates while maintaining application availability.

Q: How does Kubernetes ensure that some versions of the application remain live during updates?
A: By gradually replacing older pods with newer versions and adhering to the configured maxUnavailable parameter.

Q: What happens if a new pod fails during a rolling update?
A: If a pod fails to become ready, Kubernetes will not proceed to update the next pod until the current one is successfully running.

Q: Can we roll back to a previous version if something goes wrong?
A: Yes, you can easily rollback to a previous version using the command kubectl rollout undo deployment/my-app.

References

Practice

Ready to practice kubernetes-rolling-update?

Answer real questions, get instant feedback, and watch your skill score climb — free. Practice is in English, like real tech interviews.

Try one 👇

ReactHooksMid
0 XP
When does useEffect run by default?

↑ Go ahead — pick an answer. This is Skillpato.

Kubernetes Rolling Update: Strategies for Zero Downtime · Skillpato