# ☸kubernetes Deployment | Replicasets

Let's dive into the difference between a container, a pod, and a deployment.

Usually, we can create a container using any container platform like Docker. To run this container, we simply provide the specifications on the command line. For instance, in Docker, we use the command:

`docker run nameofimage`

Similarly, Kubernetes (K8s) provides a powerful way to manage containers at an enterprise level. Instead of typing out all the commands manually, we can simply write a YAML manifest.

In a YAML manifest, we can define all the commands and configurations needed to create a container.

A pod YAML manifest is basically a running specification for a Docker container. In a Pod, we can create one or more containers.

The cool thing about using a Pod is that it shares the same networking, so both containers can talk to each other using [`localhost`](http://localhost), and they can share the same volume or storage.

However, a pod can't do auto-healing or auto-scaling on its own.

A pod is just a YAML specification for running a container.

Kubernetes offers auto-scaling and auto-healing capabilities using Deployments.

If we want zero-downtime deployment or to use auto-scaling and auto-healing features, we should deploy applications using Deployments in Kubernetes instead of creating pods directly.

Deployments manage pods and provide auto-healing and auto-scaling functionalities.

We should create pods using Deployment resources, which automatically manage a ReplicaSet.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719766198676/866c3c41-98b7-469a-81f4-9e6bbee3441a.png align="center")

Why does a ReplicaSet exist within a Deployment? Well, the Deployment creates a certain number of pods.

In the Deployment manifest YAML, if we set a replica count, the ReplicaSet makes sure that if a pod is accidentally deleted, there's no need to worry.

When we submit a Deployment YAML manifest, it also creates a ReplicaSet, which enables auto-healing and auto-scaling features.

Kubernetes controllers always make sure that the desired state is maintained on the actual cluster.

There are default controllers in Kubernetes, as well as custom controllers like ArgoCD.

Now, let's do it practically!

`kubectl get all` is used to retrieve information about all resources of all types in the current Kubernetes namespace. This includes pods, services, deployments, replica sets, and other resources defined in the namespace.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719767945298/53a0e23b-521c-4cf4-8254-6b7a596b8d12.png align="center")

if we want all the namespace of all application in culser then we use

`kubectl get all -A`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719768203104/a64aa8aa-e523-43a3-a285-430ff34010e5.png align="center")

now let create an pod directly

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719896574203/ae3627ed-9d8a-44c8-8819-c3b683560e15.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719896613320/fc5fe97a-d8b8-4a76-84c1-12359655463f.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719896687415/8eaae0e1-32d3-4ebe-9056-ed884de234aa.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719896966069/549015e4-241a-4364-9f2b-a75747fb1506.png align="center")

`ssh -i /path/to/identity_file username@remote_host`

now we login to k8s cluster

`curl IPaddress`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719897142275/b9bd7b17-92b6-4a3a-9c02-66a9d1679129.png align="center")

lets delete this pod

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719897295319/d210d060-dea5-41c3-8e89-c8c0491a9b9d.png align="center")

We can see the pod has been deleted. Now the application will work.

There is no auto-healing.

Now let's create a pod using a deployment. Let's see the magic..

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719897620939/386edba7-8446-4dd9-9e41-0914f6af5a5b.png align="center")

To create a deployment in Kubernetes, refer to the Kubernetes documentation to see how to create a `deployment.yaml` file.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719897730367/39e3c04f-0a7a-463a-9694-ffd86d3d765b.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719898239108/e71b687a-28e6-4ad8-bc28-5d149f7a3ac2.png align="center")

Here, I have set my replicas to 1, which means it creates a pod. If that pod is deleted, the ReplicaSet will ensure that the pod is running.

lets see how it done

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719898535960/b22988e2-d46d-458f-847b-d3544fc06063.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719898554444/06a3a738-ab4e-4c4d-a820-edbeb74ff755.png align="center")

Now that we have a deployment, we can see that a pod is created by the deployment.

We can see that the pod is created automatically.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719898654246/b2080a7d-e575-4590-89d3-b1c81c7f7190.png align="center")

now lets delete an pods lets watch what well happens

`kuberctl get pods -w`

lets see another terminal

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719898881998/bb765578-9016-40ec-8ba1-39ad85a60814.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719899041191/1127b4d8-75d6-4947-a3db-88b33b374f98.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719899061700/0234c81a-62c7-411e-95f6-04dbd2bf6f20.png align="center")

When we delete the pod, it starts terminating but then it runs again.

Now let's set my replicas to 4.

Let's see.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719899252110/a714a65f-7a84-48e9-b625-9d0cf337ea73.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719899333319/8c950c01-6daf-4f47-813a-b4e45e83a332.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719899348814/89f63d82-5e44-4050-bfa0-713cc88dcce0.png align="center")

We can see that there are four pods running.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719899394290/447570b4-466b-4206-8031-38d6b6cbd609.png align="center")

Now let's delete two pods.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719899533064/148a749f-ba48-4c76-b3a8-04c6a078eded.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1719899597889/9637d610-b959-4dbb-82e1-7a850f7c9dbd.png align="center")

We have deleted two pods. Even though we deleted them, the ReplicaSet ensures the desired state we set, which is 4 pods, is maintained. It will make sure the pods are running.
