Skip to main content

Overview

Deployments provide declarative updates for Pods and ReplicaSets. The Deployment 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 the scale_replicas() method to change the number of replicas:

Scale Down

Use wait_for_replicas() after scaling to ensure all replicas are updated and available before proceeding.

Waiting for Deployment Readiness

The wait_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

If wait_for_replicas() times out, check for resource constraints or pod scheduling issues.

Best Practices

  1. Use Rolling Updates: Prefer rolling updates for zero-downtime deployments
  2. Set Resource Limits: Always define CPU and memory limits
  3. Configure Health Checks: Add readiness and liveness probes
  4. Use Labels: Apply consistent labels for querying and management
  5. Wait for Readiness: Always use wait_for_replicas() after changes
  6. Monitor Status: Check deployment conditions and replica counts
  7. Set Progress Deadlines: Define reasonable progress deadlines