I've been trying to get a sample mongo project working on Kubernetes minikube but for the life of me i can't get the volume to persist
anyone have any suggestions
kubectl create -f https://raw.githubusercontent.com/brianbruff/kubernetesPlayground/master/mongo.yaml
what i notice is that the /data folder appears to be mounted and if i create files on the node they appear in the single pod (and vice versa)
but for some reason i'm having no luck with mongo /data/db files it's as if the db subfolder of the volume is not mounted
any suggestions appreciated
Solution: ok this is embarrassing... my persistence test was create a db and then see if it was persisted
but mongo doesn't save/persist a db unless there is a collection or document in it!
yes i feel embarrassed...
The reason is even though you are mounting /data
from host to /data
in Pod, the /data/db
in container is mounted from somewhere else.
As suggested on https://hub.docker.com/_/mongo/ you should mount /data
on host to /data/db
on container.
If you go to minikube ssh
and see all the volumes mounted for mongo db docker inspect <mongo-db-container>
container, you will see that two of the following Mounts (among others):
{
"Type": "volume",
"Name": "af5f765585b153526dd7eab75a9ee4b62a0fb59d3482a23dc97b8fd23267557d",
"Source": "/var/lib/docker/volumes/af5f765585b153526dd7eab75a9ee4b62a0fb59d3482a23dc97b8fd23267557d/_data",
"Destination": "/data/db",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
},
{
"Type": "bind",
"Source": "/data",
"Destination": "/data",
"Mode": "rslave",
"RW": true,
"Propagation": "rslave"
},