Saturday 11 July 2020

Kubernetes: pods

Pod is a basic unit in Kubernetes. Kubernetes do not deploy containers directly on worker nodes. Containers are encapsulated into a Kubernetes object called pod. Ideally, a pod represents a single instance of an application.

What if the number of requests to your application is increasing and the current pod unable to handle?

Kubernetes spin up another pod for your application and this pod ideally deployed in different node to achieve high availability.

When more requests are coming, new pods will get added by Kubernetes. When fewer requests coming, Kubernetes maintains sufficient pods by deleting some of the existing pods.

 

Can a single pod encapsulate multiple containers?

Yes, a pod can run multiple containers within a single namespace and exposed by the same IP address.

You may need to encapsulate multiple containers into single Pod, when you have an application with one main process and one or more complementary processes.

 

For example, you have a user-service that takes care of user authentication, and manage user roles etc., and there is a user-audit container that exposes an API to store user audit data like when user logged in, logged out, login failure attempts etc.,

 

Assume there is one-to-one relationship between this user container and user-audit container.

 

If we can’t put these two containers in the same Pod, we need to design like below.

When a User container spin up, another user-audit container should spin up to maintain one-to-one mapping. When a User container stopped, corresponding user-audit container should get stopped.


Since ‘User Container’ and ‘User Audit Container’ are in two different pods.

a.   We need to establish communication between User and User-Audit containers explicitly.

b.   We need to create sharable volumes among user and user-audit containers. If they are in same pod, we no need to do this explicitly.

c.    When a user container stopped, we need to stop user audit container explicitly.

d.   When new user container spin up, we need to start user-audit container explicitly.


But, if the containers keep in the same Pod, both get created and destroyed together

Since the containers are in the same pod, they can share common resources like network space, Persistent Storage volumes and they can communicate directly. Containers in the same pod can access the same storage.

 

How is it possible for containers within a Pod to share resources?

Kubernetes configure Docker to run all the containers of a Pod to share the same Linux Namespace.


Is Kubernetes horizontally scale Containers?

No, Kubernetes scale the Pods horizontally.

 

Note

a.   Usually, you will not directly interact with pods, you create a deployment which will create pods.

b.   If a Pod encapsulates more than one container, then all the containers always run on a single worker node.

c. In most of the user cases, a pod contain a single container.

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment