What Is a Deployment? A K8s object that defines a desired state for a ReplicaSet (a set of replica Pods). The Deployment Controller seeks to maintain the desired state by creating, deleting, and replacing Pods with new configurations.

A Deployment's Desired State Includes:

  1. The number of replica Pods the Deployment will seek to maintain - replicas.
  2. A label selector used to identify the replica Pods managed by the Deployment - selector.
  3. A template Pod definition used to create replica Pods - template.

Use Cases There are many use cases for Deployments, such as:

Note: Update the replicas under spec, not status in the manifest file.

Kubernetes automatically manages the status based on actual state. The spec defines desired state, and Kubernetes handles scaling to match it.


kubectl scale

kubectl scale --replicas=3 deployment/demo-deployment

Executing this command will adjust the deployment called demo-deployment so it has three running replicas. You can target a different kind of resource by substituting its name instead of deployment:

# ReplicaSet
$ kubectl scale --replicas=3 rs/demo-replicaset

# ReplicationController
$ kubectl scale --replicas=3 rc/demo-replicationcontroller

# StatefulSet
$ kubectl scale --replicas=3 sts/demo-statefulset

Managing Rolling Updates With Deployments

  1. Edit the deployment spec, changing the image version to 1.19.2.Edit:

    kubectl edit deploy my-deployment
    
    spec:
      containers:
      - name: nginx
        image: nginx:1.19.2
    
  2. Check the rollout status, deployment status, and pods.

    kubectl rollout status deploy/my-deployment
    kubectl get deploy my-deployment
    kubectl get po