What's the benefit of having multiple containers in a pod versus having standalone containers?
Remember that every container in a pod runs on the same node, and you can't independently stop or restart containers; usual best practice is to run one container in a pod, with additional containers only for things like an Istio network-proxy sidecar.
Containers require less system resources than traditional or hardware virtual machine environments because they don't include operating system images. Applications running in containers can be deployed easily to multiple different operating systems and hardware platforms.
All the containers in the pod share the same network namespace which means all containers can communicate with each other on the localhost. For example, We have two containers in the same pod listening on ports 3000 and 3001 respectively. container 1 can talk to container 2 on localhost:3000.
0.1 . It means containers can't use the same port. It's very easy to achieve this with the help of docker run or docker-compose , by using 8001:80 for the first container and 8002:80 for the second container.
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).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With