gqli
gqli

Reputation: 1045

What's the difference between pod and container from container runtime's perspective?

Kubernetes documentation describes pod as a wrapper around one or more containers. containers running inside of a pod share a set of namespaces (e.g. network) which makes me think namespaces are nested (I kind doubt that). What is the wrapper here from container runtime's perspective?

Since containers are just processes constrained by namespaces, Cgroups e.g. Perhaps, pod is just the first container launched by Kubelet and the rest of containers are started and grouped by namespaces.

Upvotes: 14

Views: 15903

Answers (4)

gndps
gndps

Reputation: 821

Pods are often confused with containers. And sometimes thought to be the same. I will try to clarify it using simple facts here:

  • Deployment is a list of pods.
  • Pod is a list of containers.
  • Each Deployment can contain multiple pods.
  • Each pod in a deployment will look alike.
  • Each container in a pod can be different
  • Pods are never defined in a deployment.yaml
  • A list containers are defined in a deployment.yaml
  • Each list of containers in a deployment.yaml is 1 pod
  • This 1 pod can be scaled to multiple pods using replicas or replicasets.
  • Purpose of Pod:
    1. be an atomic unit
    2. be scalable

Examples:

if replicas = 1, then

Deployment1: [
 Pod1: [container-a, container-b],
]

if replicas = 3, then

Deployment2: [
 Pod1: [container-x, container-y],
 Pod2: [container-x-copy, container-y-copy],
 Pod3: [container-x-copy, container-y-copy]
]

Upvotes: 0

Gaju
Gaju

Reputation: 21

Analogy : Think of pod as your apartment. Your apartment has different rooms for different stuff like kitchen for cooking, bedroom for sleep etc. These different rooms are containers within your pod (apartment) targeted to provide different services.

Naturally all rooms (containers) within your apartment (pod) will share the same network aka living space / walking space to go from one room to another.

That makes your apartment kind of wrapper for your rooms.

Upvotes: 2

acid_fuji
acid_fuji

Reputation: 6853

Pod is just a co-located group of container and an Kubernetes object. Instead of deploying them separate you can do deploy a pod of containers.

Best practices is that you should not actually run multiple processes via single container and here is the place where pod idea comes to a place. So with running pods you are grouping containers together and orchestrate them as single object.

Containers in a pod runs the same Network namespace (ip address and port space) so you have to be careful no to have the same port space used by two processes. This differs for example when it comes to filesystem, since the containers fs comes from the image fs. The file systems are isolated unless they will share one Volume.

Upvotes: 4

coderanger
coderanger

Reputation: 54211

The main difference is networking, the network namespace is shared by all containers in the same Pod. Optionally, the process (pid) namespace can also be shared. That means containers in the same Pod all see the same localhost network (which is otherwise hidden from everything else, like normal for localhost) and optionally can send signals to processes in other containers.

The idea is the Pods are groups of related containers, not really a wrapper per se but a set of containers that should always deploy together for whatever reason. Usually that's a primary container and then some sidecars providing support services (mesh routing, log collection, etc).

Upvotes: 18

Related Questions