I am migrating a docker-compose file for a tomcat + postgres application to kubernetes. My test environment is Dockers for Windows with Kubernetes enabled.
If I use an emptyDir volume for postgres, I am able to test my application successfully, but I am unable to persist postgres data.
volumes:
- name: "pgdata-vol"
emptyDir: {}
On MacOS, I am able to persist postgres data using a hostPath volume.
volumes:
- name: "pgdata-vol"
hostPath:
path: /tmp/vols/pgdata
Unfortunately, if I try the same solution on Windows, I encounter a permission error. This was discussed in a previous question. See Kubernetes (in Docker for Windows) Volume Configuration for Postgres.
I do not need to access my volumes through the host file system. I simply want my volume to persist from one run to the next. I am able to achieve this behavior when running docker-compose ... up
and docker-compose ... down
using the following volume definition.
volumes:
pgdata:
Volume reference
environment:
- PGDATA=/pgdata
volumes:
- pgdata:/pgdata
Is there a good name to use to describe this type of volume? Is there a way to translate this type of volume into kubernetes?
Empty dir is indeed for temporary data. If you need persistent data you have the choice between using a host path like in Docker, but if you have multiple nodes an a pod is scheduled for a different node the data will be missing.
A better solution is therefore to use a persistent volume. This must be provided by your infrastructure and is therefore specific to your environment.
See for details: https://kubernetes.io/docs/concepts/storage/volumes/
For the permission problem on Docker for Windows you might want to consider to use minikube instead.