我知道在 Kubernetes 中您不想将 pod“绑定(bind)”到主机,但在某些情况下您可能需要这样做。
在我的特殊情况下,我有一个位于 block 存储上的数据库,该 block 存储安装在特定主机上。
我试图用 Kubernetes 完成的是相当于 Docker 中的绑定(bind)挂载。我想在pod中指定我需要挂载的host上的目录,类似这样:
/mnt/BTC_2:/root/.bitcoin:rw
如何指定我希望持久存储在节点/主机上的位置?这会是一个如下所示的 hostPath
卷吗:
volumeMounts:
- mountPath: /root/.bitcoin
name: test-volume
volumes:
- name: test-volume
hostPath:
# directory location on host
path: /mnt/BTC_2
最佳答案
I want to specify the directory on the host that I need mounted in the pod
A hostPath volume mounts a file or directory from the host node’s filesystem into your pod. This is not something that most Pods will need, but it offers a powerful escape hatch for some applications.
警告:
The files or directories created on the underlying hosts are only writable by root. You either need to run your process as root in a privileged container or modify the file permissions on the host to be able to write to a hostPath volume
volumes:
- name: test-volume
hostPath:
# directory location on host
path: /data
# this field is optional
type: Directory
关于docker - 持久存储 : How to mount a directory in Kubernetes?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49312463/