⎈ k8s knowledge compiler

Deployments [page]deterministic

A Deployment manages a set of Pods to run an application workload, usually one that doesn't maintain state.

concepts

A _Deployment_ provides declarative updates for [Pods](#gloss:pod) and [ReplicaSets](#gloss:replica-set).

You describe a _desired state_ in a Deployment, and the Deployment [controller](#gloss:controller) changes the actual state to the desired state at a controlled rate. You can define Deployments to create new ReplicaSets, or to remove existing Deployments and adopt all their resources with new Deployments.

> Note: Do not manage ReplicaSets owned by a Deployment. Consider opening an issue in the main Kubernetes repository if your use case is not covered below.

## Use Case

The following are typical use cases for Deployments:

* [Create a Deployment to rollout a ReplicaSet](#creating-a-deployment). The ReplicaSet creates Pods in the background. Check the status of the rollout to see if it succeeds or not. * [Declare the new state of the Pods](#updating-a-deployment) by updating the PodTemplateSpec of the Deployment. A new ReplicaSet is created, and the Deployment gradually scales it up while scaling down the old ReplicaSet, ensuring Pods are replaced at a controlled rate. Each new ReplicaSet updates the revision of the Deployment. * [Rollback to an earlier Deployment revision](#rolling-back-a-deployment) if the current state of the Deployment is not stable. Each rollback updates the revision of the Deployment. * [Scale up the Deployment to facilitate more load](#scaling-a-deployment). * [Pause the rollout of a Deployment](#pausing-and-resuming-a-deployment) to apply multiple fixes to its PodTemplateSpec and then resume it to start a new rollout. * [Use the status of the Deployment](#deployment-status) as an indicator that a rollout has stuck. * [Clean up older ReplicaSets](#clean-up-policy) that you don't need anymore.

## Creating a Deployment

The following is an example of a Deployment. It creates a ReplicaSet to bring up three `nginx` Pods:

In this example:

* A Deployment named `nginx-deployment` is created, indicated by the `.metadata.name` field. This name will become the basis for the ReplicaSets and Pods which are created later. See [Writing a Deployment Spec](#writing-a-deployment-spec) for more details. * The Deployment creates a ReplicaSet that creates three replicated Pods, indicated by the `.spec.replicas` field. * The `.spec.selector` field defines how the created ReplicaSet finds which Pods to manage. In this case, you select a label that is defined in the Pod template (`app: nginx`). However, more sophisticated selection rules are possible, as long as the Pod template itself satisfies the rule.

> Note: The `.spec.selector.matchLabels` field is a map of {key,value} pairs. A single {key,value} in the `matchLabels` map is equivalent to an element of `matchExpressions`, whose `key` field is "key", the `operator` is "In", and the `values` array contains only "value". All of the requirements, from both `matchLabels` and `matchExpressions`, must be satisfied in order to match.

* The `.spec.template` field contains the following sub-fields: * The Pods are labeled `app: nginx`using the `.metadata.labels` field. * The Pod template's specification, or `.spec` field, indicates that the Pods run one container, `nginx`, which runs the `nginx` [Docker Hub](https://hub.docker.com/) image at version 1.14.2. * Create one container and name it `nginx` using the `.spec.containers[0].name` field.

Before you begin, make sure your Kubernetes cluster is up and running. Follow the steps given below to create the above Deployment:

1. Create the Deployment by running the following command:

```shell kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml ```

2. Run `kubectl get deployments` to check if the Deployment was created.

If the Deployment is still being created, the output is similar to the following: ``` NAME READY UP-TO-DATE AVAILABLE AGE nginx-deployment 0/3 0 0 1s ``` Wh …(trimmed)

Sources

concepts/workloads/controllers/deployment.md · docDeployments

Related (25)

references PodPods conf=1
references ReplicaSetReplicaSets conf=1
references Controllercontroller conf=1
references WatchWatch conf=1
references Control Planecontrol plane conf=1
part_of Use Casedescribes conf=1
part_of Creating a Deploymentdescribes conf=1
part_of Updating a Deploymentdescribes conf=1
part_of Rolling Back a Deploymentdescribes conf=1
part_of Scaling a Deploymentdescribes conf=1
part_of Deployment statusdescribes conf=1
part_of Clean up Policydescribes conf=1
part_of Canary Deploymentdescribes conf=1
part_of Writing a Deployment Specdescribes conf=1
part_of {{% heading "whatsnext" %}}describes conf=1
part_of Pod-template-hash labeldescribes conf=1
part_of Rollover (aka multiple updates in-flight)describes conf=1
part_of Label selector updatesdescribes conf=1
part_of Checking Rollout History of a Deploymentdescribes conf=1
part_of Rolling Back to a Previous Revisiondescribes conf=1
part_of Proportional scalingdescribes conf=1
part_of Progressing Deploymentdescribes conf=1
part_of Complete Deploymentdescribes conf=1
part_of Failed Deploymentdescribes conf=1

← all Docs