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

# How to Create Kubernetes Deployment
- URL: https://scriptcrunch.com/kubernetes-object-deployment/
- Published: 2024-02-19T15:06:27.000Z
- Updated: 2026-06-23T08:55:55.000Z
- Author: Aswin Vijayan
- Tags: #Migrated-1758801465347, #wp, #wp-post, #Import 2025-09-25 11:57, Kubernetes Certifications

In this blog, we will explore [Kubernetes](https://scriptcrunch.com/tag/kubernetes/) object Deployment and how to deploy applications using both imperative and declarative methods.

## What is Deployment in Kubernetes?

Deployment is an object of Kubernetes that manages rollout and lifecyle of applications pod with the help of replicasets, it helps you to configure and deploy applications as you desire.

### We can create the deployment in two ways

You can create a Kubernetes deployment in two main ways:

1. **Imperative method -** Using direct `kubectl` commands
2. **Declarative method-** Using a `YAML` manifest file

## Imperative Method

This method uses the **kubectl** commands directly to create a deployment.

For example, lets create a deployment **nginx** using the **latest** **nginx** image with two replicas, the command from the deployment is given below

```bash
kubectl create deploy nginx --image=nginx:latest --replicas=2
```

If you don't specify the `--replicas` flag, it will create a single pod as default.

You can check the status of deployment using the following command

```bash
kubectl get deploy
```

![Kubernetes Object Deployment: Checking the status of deployment](https://storage.ghost.io/c/98/9f/989fb5e0-fca9-4938-afe7-999714e98540/content/images/2025/09/image-23.png)

And, you can see the number of pods running using the following command

```bash
kubectl get po
```

![Kubernetes Object Deployment: checking number of pods on deployment](https://storage.ghost.io/c/98/9f/989fb5e0-fca9-4938-afe7-999714e98540/content/images/2025/09/image-18.png)

## Declarative Method

This method uses a YAML file to create a deployment.

This method is important for the CKA exam.

The basic required file that should be in the YAML file is given below

1. **apiVerison** \- Here you have to specify the API version
2. **kind** \- Here you specify the object type, in our case it's deployment.
3. **metadata** \- Here we specify the name of the deployment and the namespace in which it needs to be deployed, if we don't specify the namespace it will deploy the application on the default namespace.
4. **spec** \- Here you have to specify the field in which you desire your application to deploy, such as replicas, selectors, and templates.
5. **replicas** \- Here you have to specify the number of pods you need, if not specified it will deploy one pod as default.
6. **selector** \- Here you have to give a label for the pod for identification.
7. **template** \- Here you have to specify the container image, volumes for the pod, etc.

First, create a YAML file using the following dry run command

```bash
kubectl create deploy nginx --image=nginx --replicas=3 --dry-run=client -o yaml > nginx.yaml
```

This command created a YAML file for deployment **nginx** using the **latest** **nginx** image with three replica as shown below

![Kubernetes Object Deployment: deployment YAML file](https://storage.ghost.io/c/98/9f/989fb5e0-fca9-4938-afe7-999714e98540/content/images/2025/09/image-21.png)

Run the following command to deploy it

```bash
kubectl apply -f nginx.yaml
```

List the pods using the following command

```bash
Kubectl get po
```

You can see three nginx pods running as given below

![Kubernetes Object Deployment: Checking pods of deployment](https://storage.ghost.io/c/98/9f/989fb5e0-fca9-4938-afe7-999714e98540/content/images/2025/09/image-22.png)

## Conclusion

These are the two methods to create a deployment in kubenetes, I belive this blog give you a decent understanding about Kubernetes Deployment.