maxUnavailable is a configuration option used in the RollingUpdate deployment strategy in Kubernetes. It defines the maximum number of Pods that can be unavailable while a new version of an application is being deployed. This helps ensure that the application remains available to users during updates by limiting how many Pods are taken offline at the same time.
By default, if maxUnavailable is not specified, Kubernetes uses 25% of the desired number of replicas.
Why Is maxUnavailable Important?
When updating an application, Kubernetes replaces old Pods with new ones gradually instead of stopping all Pods at once. The maxUnavailable setting controls how many Pods can be unavailable during this process, helping to reduce downtime and maintain service availability.
This is especially important for production environments where uninterrupted access to applications is essential.
How Does maxUnavailable Work?
The value of maxUnavailable can be specified in two ways:
- As a fixed number, such as
1 or 2
- As a percentage, such as
25% or 50%
For example:
- If a Deployment has 4 replicas and
maxUnavailable is set to 1, Kubernetes ensures that no more than one Pod is unavailable during the update.
- If a Deployment has 10 replicas and
maxUnavailable is set to 20%, Kubernetes allows up to two Pods to be unavailable while the remaining Pods continue serving requests.
This controlled approach ensures a smooth rollout without significantly affecting application availability.
Example Configuration
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
In this example:
- Only one Pod can be unavailable at any given time.
- Kubernetes can create one extra Pod above the desired replica count using
maxSurge.
- The deployment progresses gradually, ensuring users experience minimal disruption.
Benefits of Using maxUnavailable
Using maxUnavailable provides several advantages:
- Reduces application downtime during updates.
- Maintains high availability throughout the deployment process.
- Controls the pace of rolling updates.
- Minimizes the impact of deployment failures.
- Improves the reliability of production deployments.
Best Practices
To get the most out of maxUnavailable, consider these best practices:
- Use a low value for mission-critical applications to maximize availability.
- Configure it alongside
maxSurge for balanced and efficient updates.
- Implement readiness and liveness probes to ensure only healthy Pods receive traffic.
- Test deployment strategies in a staging environment before deploying to production.
- Choose a value based on your application's traffic, redundancy, and availability requirements.
Conclusion
maxUnavailable is an essential setting in Kubernetes RollingUpdate deployments that determines how many Pods can be unavailable during an application update. It helps maintain service availability, reduces downtime, and ensures updates are performed safely and efficiently. By configuring maxUnavailable appropriately, DevOps teams can achieve smooth, reliable deployments while delivering a better experience for users.