24

What's the benefit of having multiple containers in a pod versus having standalone containers?

3 Answers 3

34

If you have multiple containers in the same pod, they can speak to each other as localhost and can share mounted volumes.

If you have multiple pods of one container each, you can restart one without restarting the other. Assuming they're controlled by deployments, you can add additional replicas of one without necessarily scaling the other. If the version or some other characteristic of one of them changes, you're not forced to restart the other. You'd need to set up a service to talk from one to the other, and they can't communicate via a filesystem.

The general approach I've always seen is to always have one container per pod within a deployment, unless you have a specific reason to need an additional container. Usually this is some kind of special-purpose "sidecar" that talks to a credentials service, or manages logging, or runs a network proxy, or something else that's secondary to the main thing the pod does (and isn't a separate service in its own right).

2
  • 1
    Is it possible to have multiple containers in one deployment file? Oct 11, 2019 at 18:56
  • 2
    @AlexejMagura Yes, you can. In the .spec.template.spec.containers section of the Deployment Config you can list multiple containers.
    – Ciaodown
    Aug 31, 2020 at 16:53
10

Apart from the points pointed out , the CPU and Memory(under technical preview) are associated with a POD so if we have a single container in a POD it is easy to understand and implement the application resourcerequirement inside the POD with more than one container inside the POD we could face issues/challenges when we want to do a horizontal scale

Secondly the deployments (Blue/Green,Canary,A/B) are also more aligned with the approach of single container/POD

6

From the Kubernetes documentation

A Pod might encapsulate an application composed of multiple co-located containers that are tightly coupled and need to share resources. These co-located containers might form a single cohesive unit of service–one container serving files from a shared volume to the public, while a separate “sidecar” container refreshes or updates those files. The Pod wraps these containers and storage resources together as a single manageable entity.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.