How to share storage between Kubernetes pods?

Marco Lamina picture Marco Lamina · Jul 29, 2015 · Viewed 61k times · Source

I am evaluating Kubernetes as a platform for our new application. For now, it looks all very exciting! However, I’m running into a problem: I’m hosting my cluster on GCE and I need some mechanism to share storage between two pods - the continous integration server and my application server. What’s the best way for doing this with kubernetes? None of the volume types seems to fit my needs, since GCE disks can’t be shared if one pod needs to write to the disk. NFS would be perfect, but seems to require special build options for the kubernetes cluster?

EDIT: Sharing storage seems to be a problem that I have encountered multiple times now using Kubernetes. There are multiple use cases where I'd just like to have one volume and hook it up to multiple pods (with write access). I can only assume that this would be a common use case, no?

EDIT2: For example, this page describes how to set up an Elasticsearch cluster, but wiring it up with persistent storage is impossible (as described here), which kind of renders it pointless :(

Answer

Ian Belcher picture Ian Belcher · Apr 10, 2016

A bit late to answer this question but from my experience thus far of Kubernetes / MSA, the issue here is more in your design pattern. One of the fundamental design patterns that continues to come up quite often in MSA is the proper encapsulation of your services, which also includes its data.

Your service should look after the data that is related to its area of concern and, much like OOP, should allow access to this data to other services via an interface (an API, PUBSUB message etc). Multi-service access to data is an anti-pattern akin to global variables in OOP.

I assume that Google have the same opinion as well and this is why Kubernetes is set up in this fashion.

As an example, if you where looking to write logs, you should have a log service which each service can call with the relevant data it needs to log. Writing directly to a shared disk means that you'd need to update every container if you change your log directory structure etc or decided to add extra functionality like emails on errors.