I'm trying to convert a django(with gnunicorn)/nginx/postgres docker-compose environment (using docker-compose) to kubernetes on GCP. I've got everything running smoothly except for serving MEDIA content. In django this is any user uploaded content. Say a user uploads a profile picture, or a zipped document, etc...

The problem is, I've created a PVC (Persistent Volume Claim) definition and need it to be writable. I set the following accessModes: ReadWriteOnce and ReadOnlyMany on the claim. I know that only one container can mount a volume in ReadWrite mode at a time.

I was hoping to have the django container bind to the PV (Persistent Volume) in ReadWrite mode, and have the nginx container bind the same PV in ReadOnly mode. Nginx only needs read access. However, this does not appear to be allowed in GCP as only one container can bind a PV at a time. When I apply the config, one container mounts it (the nginx container in RO mode) and the other (django) fails to mount and gets stuck in "ContainerCreating" status indefinitely.

So my question is, how does one serve user uploaded content (which django stores in /media/*) on GCP/Kubernetes? Is there some magic search words I should use, or any documents I can read? There's many guides to run django on GCP/kubernetes, but none of them deal with this issue that I have found.

In the docker-compose environment, both the django container and the nginx container have the same volume mounted. So in the nginx config, I just create an alias for /media to point to the volume mount.

The static content is fine, as I have a solution for that. It's just the dynamic user uploads that's an issue. Right now, only the django container has that volume mounted. So a user can upload a file, but I can't display it as nginx can't link to it.

Any help would be appreciated.



You need a Shared Volume between two containers. You can do the job with a pod definition that contains both containers and the Shared Volume.

Your deployment should be like that:

apiVersion: v1
kind: Pod
  name: two-containers

  restartPolicy: Never

  - name: shared-data
        claimName: myclaim


  - name: nginx-container
    image: nginx
    - name: shared-data
      mountPath: /usr/share/nginx/html

  - name: django-container
    image: django
    - name: shared-data
      mountPath: /media

  • I knew I was missing something! This is perfect, thanks for the help! May 4 '20 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.