Search code examples
kuberneteskubectl

Do pods share the filesystems, similar to how they share same network namespace?


I have created a pod with two containers. I know that different containers in a pod share same network namespace (i.e.,same IP and port space) and can also share a storage volume between them via configmaps. My question is do the pods also share same filesystem. For instance, in my case I have one container 'C1' that generates a dynamic file every 10 min in /var/targets.yml and I want the the other container 'C2' to read this file and perform its own independent action.

Is there a way to do this, may be some workaround via configmaps? or do I have to access these file via networking since each container have their own IP(But this may not be a good idea when it comes to POD restarts). Any suggestions or references please?


Solution

  • You can use an emptyDir for this:

    apiVersion: v1
    kind: Pod
    metadata:
      name: test-pd
    spec:
      containers:
      - image: gcr.io/google_containers/test-webserver
        name: generating-container
        volumeMounts:
        - mountPath: /cache
          name: cache-volume
      - image: gcr.io/google_containers/test-webserver
        name: consuming-container
        volumeMounts:
        - mountPath: /cache
          name: cache-volume
      volumes:
      - name: cache-volume
        emptyDir: {}
    

    But be aware, that the data isn't persistent during container recreations.