First Pod with YAML

First Pod with YAML

Now, the first question that arises is, What are pods?

So, going straight Into Kubernetes, a pod is the smallest deployable unit that represents a single instance of a running process in the cluster. A pod can contain one or more containers, which share the same network namespace and can access the same storage volumes, but if I have two Python containers in the same pod , that wouldn't work here!

Pods are used to host containerized applications in Kubernetes. They provide an isolated environment for the application to run in, with its own set of resources such as networking and storage. Pods are also used for scaling and load balancing, as multiple pods can be created to handle increased traffic or workload.

When a pod is created, Kubernetes assigns it a unique IP address and a hostname. This allows other pods in the cluster to communicate with the pod using its IP address or hostname.

Pods can be managed and deployed using Kubernetes deployments, which provide a declarative way to define and manage the desired state of the application. Deployments can specify the number of replicas of a pod that should be running, and Kubernetes will automatically manage the creation, scaling, and deletion of pods to match the desired state.

Overall, pods are a fundamental building block in Kubernetes that provide an abstraction layer for running containerized applications in a distributed environment.

Pods are ephemeral by design, which means that they are disposable and can be replaced or recreated at any time. This is because Kubernetes is designed to handle failures and recover from them automatically.

Each pod in Kubernetes has its own set of Linux namespaces, which provide isolation between the processes running inside the pod and the host system. This includes namespaces for networking, filesystem, and process IDs.

now to make a pod manually you can simply run

kubectl run my-nginx --image nginx

pod/my-nginx created

To see the running pods

kubectl get pods

NAME READY STATUS RESTARTS AGE

my-nginx 1/1 Running 0 2m 55s

your pod is created and is running too!

Congrats 🎊

Going with the YAML file:

Firstly create a pod-definition.yml file

apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
    type: frontend
spec:
  containers:
  - name: nginx-container
    image: nginx

here, apiVersion is the version of k8s object being used.

these are the kind and apiVersion you are using for your object, In our case we are making a pod, So v1.

kind just defines the object with a simple version.

metadata is the data that is above the object and is in the form of a dictionary.

The two dividends are name and label, you can add your tags too, but that should be inside the CRI guidelines

The subtype type simplifies choosing the pods by their working and type.

spec as the name suggests specification and it's an array in which dictionaries are sub labelled.

As we first discussed that a pod can have many containers so the dictionary will contain the list of containers to a limit.

kubectl create -f pod-definition.yml

This command created your pod and you can view it again by

kubectl get pods

You can choose which one is better, manually or through YAML. But at the end pods are just pods :)

k8s->peace❤️