How to create an upload folder for a web app in Kubernetes?

5/31/2019

we're experimenting Kubernetes and thinking about migrating our webapp, currently hosted in a classic public cloud with vps and load balancing.

I'd like to know how to manage an upload folder (with write/read privileged) inside our dockerized app in which files uploaded by our users are stored.

As we use lot of file uploading in our apps, would it be possible to have a persistent data storage in which the webapp can upload files in and manage them via webapp? Do I have to change the code of my app and save files to external object storages or there's a faster way to do it via local filesystem?

Thank you !

-- Ermanno Palmizio Salieri
docker
kubernetes
node.js

3 Answers

5/31/2019

I'm guessing that if you are running more than one pod, you'd want some sort of shared filesystem? So all uploaded documents are available in one location instead of scattered around several persistent volumes? If that's the case, you want some sort of distibuted file storage like Amazon S3. Even better, you could use a Kubernetes NFS so your code thinks it is using local filesystem but it is backed by a distributed file store.

Take a look at this example: https://github.com/kubernetes/examples/tree/master/staging/volumes/nfs. The NFS can use a persistent volume from GKE, Azure, or AWS.

-- frankd
Source: StackOverflow

5/31/2019

The persistent volume is the right way to go. You can read about it more in the link provided by Veerendra. For ease you can use some managed Kubernetes Engine like GKE/EKS/AKS as PV part is simplified there. You can find a good guide from GCP here.

About rewriting the application - probably there will be some small changes to do because you will need to use Pod level database. It will also be a more suitable solution as you will get an easy way to scale up and down with your app based on the load and couple of other features of Kubernetes.

I would not worry about LoadBalancer here. First you will dockerize your app then put it inside of a Pod which will be then a part of a Deployment then abstract the storage as PV. To get a grasp of how this all work you can start with this simple lab Deploying PHP Guestbook application with Redis. You can find another useful resource about using PV with Deployments and StatefulSets here.

-- aurelius
Source: StackOverflow

5/31/2019

As the comment mentions, persistent voulmes is an option. You can create a AWS volume, and attach it to the pod. This post describes how to do that.

However, there is a problem you might face. That you can't scale the number of instance. I think, kubernetes doesn't allow a single elb to be shared among replicas. This issue is highlighted here. As mentioned there, its better to switch to object storage like s3. Though it might require code changes, that would be the optimal solution.

-- Malathi
Source: StackOverflow