You can have more than one container per pod. Ok, what is a multi-container pod.
Why Multi-container pods: You can now have the main container not have network / cross cutting logic such as log handling etc., and have other other container in the same pod having these logic. This way, the developer can only concentrate on the business logic while the other container acts as a proxy and handle other things.
How can containers in the pod communicate to each other:
#How to create multiple container.
The above yml container 1 runs on port 80 and the other container can access the other container using localhost 80 port.
# What is multi-container pods:
- Pods that has more than one container.
- Should not have totally unrelated pods, must be related in some way to provide a unit of work.
Why Multi-container pods: You can now have the main container not have network / cross cutting logic such as log handling etc., and have other other container in the same pod having these logic. This way, the developer can only concentrate on the business logic while the other container acts as a proxy and handle other things.
How can containers in the pod communicate to each other:
1
| shared network space: conatainer can interact with another container using localhost |
|
2
|
Shared storage volume
Can have one container writing to a shared storage
volume while the other container read from the
shared storage volume
|
|
3
|
Shared process namespace
Containers can interact with one another containers process using shared process namespace
|
|
#How to create multiple container.
apiVersion: v1
kind: Pod
metadata:
name: multi-container-pod
spec:
containers:
- name: nginx
image: nginx:1.15.8
ports:
- containerPort: 80
- name: busybox-sidecar
image: busybox
command: ['sh', '-c', 'while true; do sleep 30; done;']
The above yml container 1 runs on port 80 and the other container can access the other container using localhost 80 port.