Kubernetes(k8s) - What are Pods?

Pods are Kubernetes Objects that are the basic unit for running our containers inside our Kubernetes cluster. In fact, Pods are the smallest object of the Kubernetes Model.


kubernetes-k8s-what-are-pods

Kubernetes uses pods to run an instance of our application and a single pod represents a single instance of that application. We can scale out our application horizontally by adding more Pod replicas.


Pods can contain a single or multiple containers as a group, that share the same resources within that Pod (storage, network resources, namespaces).


Pods are epheremeral resources, meaning that Pods can be terminated at any point and then restarted on another node within our Kubernetes cluster. They live and die, but Pods will never come back to life.


Pod containers will share the name network namespace and interface. Container processes need to bind to different ports within a Pod and ports can be reused by containers in separate containers. Pods do not span nodes within our Kubernetes cluster.



Single vs Multiple Container Pod(s)

Running a single container in a Pod is a common use case. Here, the Pod acts as a wrapper around the single container and Kubernetes manages the Pods rather than the containers directly.


We can also run multiple containers in a Pod. Here, the Pod wraps around an application that’s composed of multiple containers and share resources.


If we need to run multiple containers within a single Pod, it’s recommended that we only do this in cases where the containers are tightly coupled.



Creating Pods in Kubernetes

We can define Pods in Kubernetes using YAML files. Using these YAML files, we can create objects that interact with the Kubernetes API (Pods, Namespace, Deployments etc.). Under the hood, kubectl converts the information that we have defined in our YAML file to JSON, that makes the request to the Kubernetes API.


Let’s take a look at an example YAML definition for a Kubernetes Pod:

              
                ---
                           apiVersion: v1
                      kind: Pod
                      metadata:
                            name: nginx
                        labels:
                                name: nginx
                  spec:
                            containers:
                              - name: nginx
                                 image: nginx
              
              

Let’s take a look at following fields:


apiVersion — This defines the Kubernetes API version that we want to use in this YAML file.


kind — This defines what kind of Kubernetes object we want to create.


metadata — This is data that helps us uniquely identify the object that we want to create. Here we can provide a name for our app, as well as apply labels to our object.


spec — This defines the state that we want or our object. The format that we use for spec. For our Pod file, we have provided information about the containers that we want to host on our Pod.



kubectl - deploy and interact with Pods

kubectl, (kube-control, or as some people call it, kube-cuddle) is the Kubernetes command-line tool. It allows us to run commands against Kubernetes clusters.


With kubectl, we can create a Pod using our YAML definition file like so:


kubectl apply -f myyamlfile.yaml

We can list all of our Pods like so:


kubectl get pods



Summary and Conclusions


Pod(s) are most basic resource of Kubernetes and its very much beginning point in starting to learn Kubernetes.



Author


sagar-mehta

Sagar Mehta is Atgen Software Solutions Founder and a recognised expert in the field of Intelligent Automation, including Robotic Process Automation, Workload Automation, DevOps, SRE and Advanced Analytics. Sagar advocates a pragmatic approach to Automation, encouraging a policy of using ‘the best tool for the job’.


Prior to co-founding Atgen Software Solutions, Sagar worked in Senior Automation roles, architecting and delivering robust, scalable solutions for many of the world’s biggest banks and working with leading Automation vendors. He developed his first automated solution in 2006 and has continued to deliver robust, scalable and sophisticated Automation ever since.


Sagar is a regular guest speaker and panellist at Automation seminars, conferences and user group events.

Contact

Have a similar problem to solve, let's work together.

Our Address

#107, Tower B, Escon Arena, Zirakpur, Punjab, India - 140603

Email Us

info@atgensoft.com

Call Us

+91-8806666141