KUBERNETES: FROM ZERO TO HERO (PART 5) - DEPLOYMENT AND PODS 💥🔥
Tags: beginners, tutorial, devops, kubernetes
Published: 2022-12-25 08:11:14

In part 2 of this series, we learnt that there are worker nodes and master nodes or control plane. We learnt that nodes are the physical machines or virtual machines that kubernetes runs on. And a kubernetes cluster is only a group of two or more nodes. Today we are going to learn more about the resources we discussed about in part 1 of this series. We are going to learn more about pods and deployment. So are you with me? Let's get started.

## DEPLOYMENT

In Kubernetes, a deployment is a resource that represents a set of replicas of a pod. It provides a way to update the pods in a rolling fashion, ensuring that the desired number of replicas are available at all times.

A deployment consists of a set of desired properties, including the number of replicas, the labels and selectors used to identify the pods, and the container image and command to run in the pods. It also has a set of actual properties, including the current number of replicas and the status of the pods.

When you create a deployment, Kubernetes will create the desired number of replicas of the pod and ensure that they are running on the worker nodes. If a pod goes down, the deployment will create a new one to replace it. You can also update the deployment by changing the desired properties, such as the container image or the number of replicas. Kubernetes will then update the pods in a rolling fashion, ensuring that the desired number of replicas are available at all times.

Here is an example deployment configuration file for Kubernetes in YAML format:

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-container
        image: my-container-image:latest
        command: ["/bin/bash", "-c"]
        args: ["echo hello world"]

```
This configuration file creates a deployment called my-deployment with three replicas of a pod. The pod contains a single container, my-container, which is based on the my-container-image:latest image and runs the echo hello world command.

The replicas field specifies the desired number of replicas of the pod, and the selector field specifies the labels and selectors used to identify the pods. The template field specifies the template for the pods, including the labels, the container image and command, and any other desired properties.

Overall, deployments are a useful resource in Kubernetes for managing the replicas of a pod and ensuring that the desired number of replicas are available at all times. They provide a way to update the pods in a rolling fashion, making it easy to deploy and manage applications in a cluster.

## Pods
A pod is the basic unit of deployment. It is a logical host for one or more containers, and it represents the smallest deployable unit in the cluster. Pods are usually managed by higher-level abstractions such as deployments or stateful sets, which handle the details of scaling and self-healing. 

In very simple language, pods are like little houses for containers. Containers are like really small computers that can run different types of programs. Pods are like houses because they have a place for the containers to live and they keep the containers safe. Pods can have one or more containers inside them, depending on how big the program is that the containers are running.

A pod configuration file is a file that describes the desired state of a pod or set of pods. It specifies the details of the pod or pods, such as the containers that should be run, the resources they should consume, and the volumes they should mount.

Here is an example configuration file for creating a pod in Kubernetes:

```yaml
apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
  - name: my-container
    image: nginx:latest
    ports:
    - containerPort: 80
  volumes:
  - name: my-volume
    emptyDir: {}
```
This configuration file creates a pod named `my-pod` with a single container running the nginx image. The container exposes port 80, and the pod mounts an empty volume named my-volume.

To create the pod in the cluster, you can use the kubectl create -f command, passing the configuration file as an argument:
```bash
kubectl create -f pod.yaml

```
This will create the pod in the cluster, and you can verify it by running the kubectl get pods command.

🌟 🔥 If you want to switch your career into tech and you are considering DevOps, you can join our online community [here](https://chat.whatsapp.com/LARpsS1xhYi75TdJYh8TMa) for live classes and FREE tutorial videos.