docker - 持久存储 : How to mount a directory in Kubernetes?

标签 docker kubernetes docker-compose persistent-storage

我知道在 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

应该是documented here

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/

相关文章:

kubernetes - 如何在 Kubernetes 中跨所有节点均匀部署 Pod?

go - 如何获取集群外go Kubernetes客户端的当前命名空间?

docker - 执行docker-compose命令后获得错误yaml.scanner.ScannerError

jenkins - docker 组成和 Jenkins

docker - DOCKER_TLS_VERIFY 和 DOCKER_CERT_PATH 变量有什么作用?

docker - 安装 Couchbase 的特定 docker 镜像

windows - docker容器中的文件到底存储在宿主机的哪里

mysql - kubernetes 中的 HAProxy 连接 galera 集群

elasticsearch - 容器化WebApp的日志不会通过Serilog.Sinks.Elasticsearch发送到Elasticsearch

docker - Golang dep 不下载所有库文件