> ## Content Index
> Fetch the complete content index at: https://comtechies.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Create a Kubernetes Deployment & Perform Rolling Update
- URL: https://comtechies.com/create-kubernetes-deployment/
- Published: 2024-02-23T01:02:00.000Z
- Updated: 2025-08-18T09:42:26.000Z
- Author: Arun Lal
- Tags: CKA EXAM, kubernetes, #Migrated-1755084814468, #wp, #wp-post, #Import 2025-08-13 11:34

In this blog, we will look at how we can create a Deployment using imperative and declarative ways.

We will also look at Deployment rolling updates and rollback strategies.

Why do we need a Deployment?

We can create multiple Pod Objects on Kubernetes to deploy our application, but what if a Pod fails, we will have to create them manually.

But we have a requirement that whatever happens, the desired number of Pods has to always run, and also want to perform deployment strategies, then we will use the Deployment Object.

The deployment object manages the pods using [replicasets](https://comtechies.com/how-to-create-a-replicaset-on-kubernetes/).

Let's look at it practically.

## Method 1: Imperative way to create a Deployment Object

```
kubectl create deployment test-deployment --image nginx:1.16 --replicas 3
```

To list the Deployment objects, use the following command.

```
kubectl get deployment
```

![list deployments](https://storage.ghost.io/c/98/17/98179ffe-00c9-4599-8b4a-1f5f7ba0565b/content/images/2025/08/image-856.png)

The Deployment Controller will always watch these Pods to manage the lifecycle of these Pods.

```
kubectl get pods
```

![list pods](https://storage.ghost.io/c/98/17/98179ffe-00c9-4599-8b4a-1f5f7ba0565b/content/images/2025/08/image-857.png)

## Method 2: Declarative way to create a Deployment object

Create a Deployment YAML manifest

```
cat << EOF > deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: test-deployment
  name: test-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: test-deployment
  template:
    metadata:
      labels:
        app: test-deployment
    spec:
      containers:
      - image: nginx:1.16
        name: nginx
EOF
```

This way we will get more flexible to configure the Deployment object.

```
kubectl apply -f deployment.yaml
```

`spec.replicas` is where we mention the desired number of Pods to run, and when we deploy a Deployment object, a ReplicaSet Object will also be deployed.

```
kubectl get replicaset
```

![list deployment](https://storage.ghost.io/c/98/17/98179ffe-00c9-4599-8b4a-1f5f7ba0565b/content/images/2025/08/image-858.png)

`spec.selector.matchLabels` is indicating that any Pod with these labels will be part of this Deployment.

For example, if you already have two Pods with the labels `app: test-deployment`, if you deploy the same manifest then only one Pod will be created.

## Deployment Rolling Update

You can ask why we have to use the Deployment Object instead of ReplicaSet Object because In ReplicaSet we cannot perform Deployment strategies such as Rolling update or Recreate.

With the help of Deployment Object, we can push the new version of the application without downtime.

First, we describe and see the current version of the container.

```
kubectl describe deployment test-deployment
```

![](https://storage.ghost.io/c/98/17/98179ffe-00c9-4599-8b4a-1f5f7ba0565b/content/images/2025/08/image-859.png)

Here, you can see that the default strategy is `RollingUpdate`, this means that if you are updating the nginx version 1.16 to 1.17, it will not terminate all the old Pods suddenly instead remove and add new pods simultaneously.

```
kubectl set image deployment test-deployment nginx=nginx:1.17
```

![list pods](https://storage.ghost.io/c/98/17/98179ffe-00c9-4599-8b4a-1f5f7ba0565b/content/images/2025/08/image-860.png)

In this method, users will not get interrupted during the updation of the application.

![describe deployment](https://storage.ghost.io/c/98/17/98179ffe-00c9-4599-8b4a-1f5f7ba0565b/content/images/2025/08/image-861.png)

## How to Rollback the Deployment

We can go back to the previous update if necessary and that also will not affect the user experience.

```
kubectl rollout undo deployment test-deployment --to-revision 1
```

Let's describe and see the changes on the Deployment.

```
kubectl describe deployment test-deployment
```

![describe deployment](https://storage.ghost.io/c/98/17/98179ffe-00c9-4599-8b4a-1f5f7ba0565b/content/images/2025/08/image-862.png)

## Conclusion

Creating deployments and performing rolling updates and rollbacks is an important topic in CKA certification.

We have looked at those scenarios practically.

If you are preparing for CKA certification, you can make use of the [Linux Foundation coupons](https://comtechies.com/linux-foundation-coupon/) to save up to 50% on certification registration.