In the previous post we’ve looked into Kubernetes Pods which are essentially one of the smallest units or workloads that exist on the Kubernetes platform.

This time we’ll take Pods to the next level where we’ll consider concepts such declarative updates, rollouts, scaling and a notion of desired & actual states with Kubernetes Deployments. At the end of the day, why would you want to manage your Pods directly one-by-one if you can wrap them into the Deployment and manage these Pods as one package.

More details: Kubernetes Deployments

Create Deployment

Let’s start with creating Deployment workloads. You can generally do this either by adopting Imperative or Declarative syntax with the kubectl create command.

More Details: kubectl create


kubectl create deployment [DEPLOYMENT NAME]


kubectl apply -f [DEPLOYMENT TEMPLATE].yaml


apiVersion: apps/v1
kind: Deployment
    app: my-app
  replicas: 3
      app: my-app
        app: my-app
      - name: my-app
        image: nginx
        - containerPort: 80

List Deployments

To find out what Deployments are deployed and in which Namespaces you’ll probably want to use some of these kubectl get deployments commands.

More Details: kubectl get

List All Deployments in Namespace

kubectl get deployments -n [NAMESPACE]

List All Deployments in All Namespaces

kubectl get deployments --all-namespaces

List All Deployments with Labels

kubectl get deployments --all-namespaces --show-labels

Deployment Details

These commands will allow you to look deeper into your chosen Deployment where you’ll find out all the Deployment details, labels, Pods specification in either YAML or Wide output.

More Details: kubectl describe

Get Deployment

kubectl get deployment [DEPLOYMENT NAME] -n [NAMESPACE]

Get Deployment – Wide Output

kubectl get deployment [DEPLOYMENT NAME] -n [NAMESPACE] -o wide

Get Deployment – YAML Output

kubectl get deployment [DEPLOYMENT NAME] -n [NAMESPACE] -o yaml

Export Deployment – YAML Output to File

kubectl get deployment [DEPLOYMENT NAME] -n [NAMESPACE] -o yaml --export > [FILE NAME].yaml

Describe Deployment

kubectl describe deployment [DEPLOYMENT NAME] -n [NAMESPACE]

Patch Deployment

To modify an existing Deployment directly on the Kubernetes data plane use the kubectl patch command.

More Details: kubectl patch

Patch Deployment with bash

kubectl patch deployment [DEPLOYMENT NAME] -n [NAMESPACE] -p "$(cat [DEPLOYMENT TEMPLATE].yaml)"

Patch Deployment with Powershell

kubectl patch deployment [DEPLOYMENT NAME] -n [NAMESPACE] -p $(Get-Content [DEPLOYMENT TEMPLATE].yaml -Raw)

Scale Deployment

To change a number Pods running under the Deployment you can sue the kubectl scale command.

More Details: kubectl scale

kubectl scale deployment.v1.apps/[DEPLOYMENT NAME] -n [NAMESPACE] --replicas=[NUMBER OF PODS]

Rollout Deployment

This is probably the most common Deployment command which you will use while working with deployments the imperative way. With the kubectl rollout command you can essentially manage the lifecycle of your Kubernetes Deployment.

More Details: kubectl rollout

View Deployment History

kubectl rollout history deployment.v1.apps/[DEPLOYMENT NAME] -n [NAMESPACE]

View Deployment Rollout Status

kubectl rollout status deployment.v1.apps/[DEPLOYMENT NAME] -n [NAMESPACE]

Rollback Deployment to Previous Version

kubectl rollout undo deployment.v1.apps/[DEPLOYMENT NAME] -n [NAMESPACE]

Rollback to Specific Revision

kubectl rollout undo deployment.v1.apps/[DEPLOYMENT NAME] -n [NAMESPACE] --to-revision=[REVISION NUMBER]

Delete Deployment

Finally, to dispose of a Deployment simply use the kubectl delete command allowing you to target single Deployment or even filter on labels or namespaces.

More Details: kubectl delete


Delete Deployment By Name

kubectl delete deployment [DEPLOYMENT NAME] -n [NAMESPACE]

Delete Deployment By Label

kubectl delete deployments -l name=[LABEL] -n [NAMESPACE]


kubectl delete -f [DEPLOYMENT TEMPLATE].yaml

<< Kubernetes Pods | Kubernetes Deployments | Kubernetes Services >>

Marcin Narloch

Marcin Narloch

Creative and out-of-the-box thinker with strong interests and knowledge in technology and innovation.
Docker Building Blocks Previous post Kubernetes Services
Docker Building Blocks Next post Kubernetes Pods

Leave a Reply

Your email address will not be published. Required fields are marked *