Skip to main content

Overview

The Deployment class represents a Kubernetes Deployment, which enables declarative updates for Pods and ReplicaSets. Deployments provide features like rolling updates, rollbacks, and scaling.

Class Definition

API Group: apps

Constructor

Deployment accepts all parameters from NamespacedResource, plus:
dict[str, Any]
required
Label selector for pods. The result of matchLabels and matchExpressions are ANDed. An empty label selector matches all objects.
dict[str, Any]
required
Pod template describing the pods that will be created. Must include metadata and spec.
int | None
Minimum number of seconds for which a newly created pod should be ready without any container crashing for it to be considered available. Defaults to 0.
bool | None
Indicates that the deployment is paused
int | None
Maximum time in seconds for a deployment to make progress before it is considered failed. Defaults to 600s.
int | None
Number of desired pods. Defaults to 1.
int | None
Number of old ReplicaSets to retain for rollback. Defaults to 10.
dict[str, Any] | None
Deployment strategy describing how to replace existing pods with new ones. Types include RollingUpdate and Recreate.

Methods

scale_replicas

Update the number of replicas in the deployment.
int
required
Number of replicas to scale to
Returns: Result of the update operation

wait_for_replicas

Wait until all replicas are updated and available.
bool
default:"True"
True to wait for replicas to be deployed, False to wait for no replicas
int
default:"TIMEOUT_4MINUTES"
Time to wait for the deployment in seconds
Raises: TimeoutExpiredError if replicas are not ready within timeout

Inherited Methods

Deployment inherits all methods from NamespacedResource and Resource.

Examples

Creating a Basic Deployment

Creating a Deployment with Rolling Update Strategy

Scaling a Deployment

Scaling Down to Zero

Deployment with Resource Limits

Waiting for Deployment to be Available

Using Context Manager

Creating from YAML

Listing All Deployments

Updating Deployment Image

See Also