Kubernetes is an open-source container orchestration platform. It eliminates the manual processes associated with deploying and scaling containerized applications. Furthermore, this system allows you to manage and coordinate containerized applications on a cluster of machines through small units called pods. A pod typically includes several containers, which together form a functional unit.
In this article, we'll learn the difference between a pod and a container in Kubernetes.
Containers are standardized executable components that combine application source code with operating system libraries. A container could be a database, a web application, or a backend service…
In Kubernetes, each container is isolated from other processes and runs on a computer, physical server, or virtual machine. Furthermore, containers are pretty lightweight, fast, and portable because, unlike a virtual machine, containers do not need to include an operating system in each instance and can instead leverage the functionalities and resources of the host machine's operating system.
The pod is one of the fundamentals of Kubernetes because it's the primary component that developers may manipulate. It represents a set of processes running within a cluster node. A pod is, therefore, a basic execution unit of a Kubernetes application. It is the smallest and simplest object model. a pod within a node has:
- A local IP address.
- One or more Linux containers. For instance, Docker is commonly used as a container runtime.
- One or more volumes that are associated with these containers are persistent storage resources.
4. What’s the Difference Between a Pod and a Container?
Because we're not supposed to pack multiple processes into a single container, we need a higher-level structure that will allow us to tie and wrap containers together and manage them as a single unit. This is the reasoning behind the pods. Simply put, a Kubernetes pod is a collection of containers.
Furthermore, a container pod allows it to run closely related processes together. And provides them with almost the same environment, as if they were all running in a single container while keeping them virtually isolated. This way, we can get the best of both worlds. We can take advantage of all the functionality containers provide while giving processes the illusion of working together.
Pods provide two types of shared resources for their containers: network and storage.
Each pod in Kubernetes is identified by a unique IP address. Furthermore, All Pod containers share the same network namespace including IP address and network ports.
To communicate inside the pod, containers can simply exchange using localhost. However, when pod containers communicate with components outside the pod, they must share how to use network resources such as ports.
We can instantiate a set of shared storage volumes for a pod that will be accessible by all of its containers. This feature allows containers to share data efficiently. Also, storage volumes allow the pod's persistent data to survive in case one of the containers has problems.
5. Pods and Containers Life Cycle
Kubernetes automatically manages the lifecycle of containers and distributes them across the entire hosting infrastructure. Also, it has the ability to restart containers automatically whenever they fail. Kubernetes provides this feature through Restart Policies, which allow the user to define when a pod’s containers should be restarted.
Let's see the different states of a pod in relation to the containers:
- The Pending state: the very first thing that happens when a pod is created is that it enters a state called pending. In this state, the pod is ready to run but has not yet been assigned to a server. There are probably several machines that are ready to receive this pod. It's the role of the scheduler to examine the resource needs of the pod (CPU capacity, memory, etc.) and to assign it to a particular machine
- The Running state: a pod reaches this state when it has been assigned to a machine, the images of the containers that make up the pod have been downloaded, and all the containers have been started
- The Succeeded state: this state occurs when all containers in the pod have been successfully stopped and are not going to be restarted
- The Failed state: this state is reached when all containers in the pod are stopped, and at least one of the containers has terminated with an error
- The Unknown state: This mainly occurs when the pod fails to communicate with the node it is supposed to be running on. In this case, it's impossible to know the pod status.
In this article, we first learned about pods and containers. Second, we discussed the difference between a pod and a container in Kubernetes. And finally, we explained the life cycle of pods and containers and also the different states of a pod, which is directly impacted by the state of the containers it holds.
res – REST with Spring (eBook) (everywhere)