how to scale nginx but share same volume

1/17/2020

I'm new at k8s, what's the solution when you need to scale horizontally a container in different hosts, but share the same volume, for example nginx static content.

-- Alessandro
docker
kubernetes

2 Answers

1/17/2020

Create a persistent volume with ReadOnlyMany access mode. That volume can be mounted read-only by many pods. Then, create a persistent volume claim and mount that into your pods.

https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes

https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims

-- Burak Serdar
Source: StackOverflow

1/17/2020

Typically you should rearchitect the container to not need shared storage. In the case of something like static assets, you can COPY them into your image in a Dockerfile. Another good option is to store them somewhere totally outside of Kubernetes; in AWS, you can serve them directly out of an S3 bucket, for example.

While Kubernetes lets you declare a volume is attached to a pod, you need to tell it if shared storage is attached to just one pod or to many, and if it's read/write or read-only. There's a table in the Persistent Volumes documentation that describes the options. If you only have options like AWSElasticBlockStore or HostPath nodes available to you, neither of these are shareable across multiple nodes.

-- David Maze
Source: StackOverflow