Multi-Container Pods
A Kubernetes Pod can have one or more containers. A Pod with more than one container is a Multi-Container Pod.
In a multi-container Pod, the containers share resources such as network and storage. They can interact with one another, working together to provide functionality.
Best Practice tip: Always keep containers in a separate Pods unless they need to share resources
An example of a Multi-Container Pod use case can be:
The User have an application that is hard-coded to write log output to a file on disk.
Now in this case, the user can add a secondary container to the pod (also called as a sidecar) that reads the log file from a shared volume & prints it to the console, so the log output will appear in the container log.
Lets try to understand through a demo:
- Create a pod definition
2. Check the pod:
3. Now create another pod(sidecar)
After every five seconds, the busybox application will log data into output.log.
The second container, sidecar will read the data(output.log) from the /input dir.
Now, if we closely observe, both the containers are using same shared volume. And this allows both the containers to interact with each other by modifying the same files. Now if we create this pod:
So the first container is writing the data to a file & the second container is reading the data from the file.
This was pretty much about the Multi-Container pods. In the next post we will discuss about the init containers.
Thank You!