Hello, readers! In this article, we will be focusing on Kubernetes Pods, in detail.
So, let us begin!! 🙂
What are Pods in Kubernetes?
Pods are the smallest deployment or deployable units in Kubernetes within which we can deploy the workloads. To be precise, a Pod is a group of one or more containers that run the applications that we host on them. They share the storage resources between them as well as the network resources that define the path on the way to run the containers within the Pods.
The contents of a Pod are always deployed and they run on a shared context with storage and resources. To note, they are ephemeral in nature. So, the applications that are packaged in the containers run within a Pod and its lifecycle. Thus, a Pod isolates the application through the containers that reside within it.
1. Usage of Pods
For usage, we usually create Pods through the Workloads or Deployments for our applications.
In kubernetes, we can create Pods in two ways–
- Single Container Pods: This kind of Pods are the most common of its kind. They reside in a single container within them and provides isolation from other containers and workloads. Further, it acts as a wrapper class for this single container.
- Multi Container Pods: The multiple containers occupying different workloads of the application are combined together and framed into a single unit under Multi Container Pod. It wraps up the shared storage, resources, network rules together into it. Thus, we can say that in a multi-container Pod, containers run as a sidecar parallel to other containers serving specific functions by utilizing the shared resources.
2. Communication between Pods
As soon as a Pod gets created in Kubernetes cluster, a unique IP address is assigned to it. Multiple containers within pods communicate with each other using localhost. All the communication that needs to happen outside the boundary of the Pod needs a service that will expose a port for the same.
Within the cluster, k8 assigned cluster private IP address to be pods due to which these pods can communicate with each other without the need for Network Address Translation.
Single Container Pods reside a single container within them. They wrap up the storage and resources around the single container and isolates them in a separate environment.
Template for Single Container Kubernetes Pod –
apiVersion: v1 kind: Pod metadata: name: app spec: containers: - name: hello-world-app image: hello-world ports: containerPort: 80 imagePullPolicy: Always
In a multi container pods, containers run as sidecar against each other. The resources and storage is shared between the containers. The containers within the pod communicate through localhost.
Template for Multi-Container Kubernetes Pod–
apiVersion: v1 kind: Pod metadata: name: app spec: containers: - name: hello-world-app image: hello-world ports: containerPort: 80 imagePullPolicy: Always - name: sql-app Image: mysql Ports: containerPort: 3600 imagePullPolicy: Always
Storage in k8 Pods
Pods allows the facility of shared volumes in them. By this, we mean that the containers can use this volume space for storage of data within the pods. But, it needs to be noted that this volume within the pod is ephemeral in nature.
- Pods are the smallest deployed units in Kubernetes.
- They allow the containers to share the storage space within them in the form of volumes.
- Pods host single or multiple containers in them.
- They share the network as well as storage resources.
- As soon as a pod gets created, a unique IP address is assigned to it.
- Multiple containers within pods communicate with each other using localhost
By this, we have come to the end of this topic. Feel free to comment below, in case you come across any questions. For more such posts related to Kubernetes, Stay tuned with us.
Till then, Happy learning!! 🙂