Bird
0
0

To configure a logging sidecar container that shares a volume with the main application container in a Pod, which YAML snippet correctly defines the shared volume and mounts it in both containers?

hard📝 Workflow Q8 of 15
Kubernetes - Pods
To configure a logging sidecar container that shares a volume with the main application container in a Pod, which YAML snippet correctly defines the shared volume and mounts it in both containers?
Aspec: volumes: - name: shared-logs emptyDir: {} containers: - name: app image: myapp volumeMounts: - name: shared-logs mountPath: /var/log/app - name: logger image: busybox volumeMounts: - name: shared-logs mountPath: /var/log/app
Bspec: containers: - name: app image: myapp volumeMounts: - name: shared-logs mountPath: /var/log/app - name: logger image: busybox volumeMounts: - name: shared-logs mountPath: /var/log/app
Cspec: volumes: - name: shared-logs hostPath: path: /var/log/app containers: - name: app image: myapp - name: logger image: busybox
Dspec: volumes: - name: shared-logs emptyDir: {} containers: - name: app image: myapp - name: logger image: busybox
Step-by-Step Solution
Solution:
  1. Step 1: Define a shared volume

    Use 'emptyDir' volume under 'volumes' to share data between containers.
  2. Step 2: Mount the volume in both containers

    Each container must have 'volumeMounts' referencing the shared volume name and mount path.
  3. Final Answer:

    spec: volumes: - name: shared-logs emptyDir: {} containers: - name: app image: myapp volumeMounts: - name: shared-logs mountPath: /var/log/app - name: logger image: busybox volumeMounts: - name: shared-logs mountPath: /var/log/app correctly defines the shared volume and mounts it in both containers.
  4. Quick Check:

    Shared volumes require explicit 'volumes' and 'volumeMounts' [OK]
Quick Trick: Define volume and mount it in all containers [OK]
Common Mistakes:
  • Omitting the 'volumes' section
  • Not mounting the volume in both containers
  • Using 'hostPath' without proper permissions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kubernetes Quizzes