简体   繁体   English

Kubernetes 和 Mongo 卷

[英]Kubernetes and Mongo Volume

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我一直在尝试让一个示例 mongo 项目在 Kubernetes minikube 上工作,但在我的一生中,我无法让音量保持不变

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)我注意到 /data 文件夹似乎已挂载,如果我在节点上创建文件,它们会出现在单个 pod 中(反之亦然)

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但由于某种原因,我对 mongo /data/db 文件没有运气,就好像卷的 db 子文件夹没有安装一样

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!但是 mongo 不会保存/保留数据库,除非其中有集合或文档!

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.原因是即使您安装/data从主机/data在波德,在/data/db在容器从别的地方安装。

As suggested on https://hub.docker.com/_/mongo/ you should mount /data on host to /data/db on container.作为上建议https://hub.docker.com/_/mongo/应安装/data在主机/data/db的容器。

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):如果您转到minikube ssh并查看为 mongo db docker inspect <mongo-db-container>容器挂载的所有卷,您将看到以下两个挂载(以及其他):

        {
            "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"
        },

I also faced same issue.我也面临同样的问题。 But after making a small change, It worked fine for me.但是做了一个小的改变后,它对我来说很好。

volumeMounts:
        - name: <pvc-name>
          mountPath: "/data/db/"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM