What is the main reason to use multiple containers inside a single Kubernetes Pod?
Think about containers that need to work together closely and share storage or network.
Multi-container Pods are designed to run containers that are tightly coupled and share the same network and storage. They communicate via localhost and share volumes.
Given this Pod YAML with two containers, what will be the output of kubectl get pods mypod -o jsonpath='{.spec.containers[*].name}'?
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: app
image: busybox
command: ['sh', '-c', 'echo Hello from app']
- name: sidecar
image: busybox
command: ['sh', '-c', 'echo Hello from sidecar']The command lists container names inside the Pod spec.
The jsonpath expression extracts all container names from the Pod spec, so it lists both 'app' and 'sidecar'.
Which volume configuration allows two containers in the same Pod to share files?
apiVersion: v1
kind: Pod
metadata:
name: shared-pod
spec:
containers:
- name: container1
image: busybox
volumeMounts:
- name: shared-data
mountPath: /data
- name: container2
image: busybox
volumeMounts:
- name: shared-data
mountPath: /data
volumes:Look for a volume type that creates a temporary directory shared in Pod lifetime.
emptyDir creates a temporary directory shared between containers in the same Pod, perfect for sharing files.
You have a Pod with two containers, but one container cannot reach the other on localhost. What is the most likely cause?
Remember that containers in the same Pod share network, but different Pods do not.
Containers in the same Pod share the network namespace and can communicate via localhost. If they are in different Pods, they cannot use localhost to communicate.
Arrange the steps in the correct order to deploy a multi-container Pod and verify both containers are running.
Think about writing config first, then applying it, then checking status, then logs.
You first write the YAML, then apply it to create the Pod, check if Pod is running, then check logs of each container.