Welcome to the Linux Foundation Forum!

Communicate Between Containers in the Same Pod Using a Shared Volume

Hi experts.

I want more details about this

https://kubernetes.io/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/#creating-a-pod-that-runs-two-containers

so it is 'Notice that the second container writes the index.html file in the root directory of the nginx server.'

from last two lines

command: ["/bin/sh"]
args: ["-c", "echo Hello from the debian container > **_/pod-data/index.html_**"]

it says create a index.html file to mountedPath /poo-data/index.html
but how and why this index.html gets created on root directory?? so that nginx container can see it?

Best Answer

  • chrispokorni
    chrispokorni Posts: 2,343
    Answer ✓

    Hi @dockerlander,

    The onemorelevel/test.html of the debian container will be accessible by the nginx container at /usr/share/nginx/html/onemorelevel/test.html.

    Regards,
    -Chris

Answers

  • chrispokorni
    chrispokorni Posts: 2,343

    Hi @docklander,

    The debian container can mount the volume on any mountPath on its file system - its file system and the mountPath are only visible to the debian container.

    The nginx container has no visibility into the debian container's file system - this level of isolation is desired and implemented by containers. The nginx container can only see its own file system and its own mountPath.

    The volume resource defined in the pod, creates a shareable object that can be accessed by both containers simultaneously, only after each container mounted the volume on their respective mountPaths.

    Regards,
    -Chris

  • Thanks Chris,
    So if I put this way. Nginx container could access to any files in debian /pod-data/ directory from nginx root directory.
    is that right to say? what if I create a file in debian container sub-directory of /pod-data/onemorelevel/test.html
    so this test.html will be also accessable from nginx root directory?

Categories

Upcoming Training