how to make two docker containers share sqllite db on kubernetes?

3/22/2017

I am trying to build an application which in essence consists of two parts.

  1. Django based api
  2. SQLite database.

Api interacts with the SQLite database, but has only read only access. However, the SQLite database needs to be updated every N minutes. So my plan was to make two docker container. First one, for the api. The second one, for the script which is executed every N minutes using CRON (Ubuntu) to update the database.

I am using Kubernetes to serve my applications. So I was wondering if there is a way to achieve what I want here?

I've researched about Persistent Volumes in Kubernetes, but still do not see how I can make it work.

EDIT:

So I have figured that I can use one pod two share two containers on Kubernetes and this way make use of the emptyDir. My question is then, how do I define the path to this directory in my python files?

Thanks, Lukas

-- TruniTr
docker
kubernetes

1 Answer

3/25/2017

Take into account that emptyDir is erased every time the pod is stopped/killed (you do a deployment, a node crash, etc.). See the doc for more details: https://kubernetes.io/docs/concepts/storage/volumes/#emptydir

Taking that into account, if that solves your problem, then you just need to put the mountPath to the directory you want, as in the link above shows the example.

Take into account that the whole directory will be empty, so if you have other things there they won't be visible if you set up and emptyDir (just typical unix mount semantics, nothing k8s specific here)

-- rata
Source: StackOverflow