Overview
Deployments provide declarative updates for Pods and ReplicaSets. TheDeployment class allows you to manage application lifecycle, including scaling, rolling updates, and rollbacks.
Creating a Deployment
Basic Deployment
Create a simple deployment with required fields:Both
selector and template are required parameters. If not provided, a MissingRequiredArgumentError will be raised.Deployment with Resource Limits
Create a deployment with resource requests and limits:Using Context Managers
Automatic deployment and cleanup with context managers:Scaling Deployments
Scale Replicas
Use thescale_replicas() method to change the number of replicas:
Scale Down
Waiting for Deployment Readiness
Thewait_for_replicas() method waits until all replicas are updated and available:
Understanding Replica States
Monitor different replica counts:Deployment Strategies
Rolling Update Strategy
Recreate Strategy
Updating Deployments
Update Container Image
Update Environment Variables
Querying Deployments
List All Deployments
Advanced Configuration
Revision History Limit
Control the number of old ReplicaSets to retain:Progress Deadline
Set a deadline for deployment progress:Min Ready Seconds
Pausing and Resuming Deployments
Troubleshooting
Deployment Not Progressing
Replicas Not Scaling
Best Practices
- Use Rolling Updates: Prefer rolling updates for zero-downtime deployments
- Set Resource Limits: Always define CPU and memory limits
- Configure Health Checks: Add readiness and liveness probes
- Use Labels: Apply consistent labels for querying and management
- Wait for Readiness: Always use
wait_for_replicas()after changes - Monitor Status: Check deployment conditions and replica counts
- Set Progress Deadlines: Define reasonable progress deadlines