docker - Kubernetes PVC卷装

标签 docker kubernetes

我在k8s上运行应用程序。

我的docker文件就像:

FROM python:3.5 AS python-build
ADD . /test
WORKDIR /test

在测试目录中,我正在执行此测试文件夹中所有文件的操作。

当我进入pod并检查文件结构时,就像/var /usr /test /bin
所以我想在pvc中添加整个文件夹测试

在测试文件的结构就像/app /data /history
所以我可以使用mountpath将添加文件夹附加到pvc中吗?

有可能两个mountpath但一个pvc吗?

最佳答案

据我了解,您希望将测试目录作为安装路径包括在PVC中。要回答该问题,是的,您可以通过在主机路径而不是安装路径中提供它来实现。如文档中所述:

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 location in pod where the volume should be mounted.



因此,如果要从主机系统挂载\ test文件夹,则需要在pv中提供它,如下所示
kind: PersistentVolume
apiVersion: v1
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/test"

并且您可以使用该PV通过pvc声明一个卷,并使用 mountPath 将该卷安装到您的Pod中。

要回答第二个问题,是的,单个PVC可以有多个安装路径。一个有效的例子是:
    "containers": [
    {
        ...,
        "volumeMounts": [
         {
             "mountPath": "/mnt/1",
             "name": "v1",
             "subPath": "data/1"
         },
         {
             "mountPath": "/mnt/2",
             "name": "v1",
             "subPath": "data/2"
         }
       ]
    }
   ],
   ...,
   "volumes": [
       {
           "name": "v1",
           "persistentVolumeClaim": {
                "claimName": "testvolume"
           }
       }
     ]
  }
}

关于docker - Kubernetes PVC卷装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56269478/

相关文章:

java - 我们是否应该在 kubernetes 容器中设置 -Xmx(最大 Java 堆大小)

docker - Kubernetes Kubelet无权访问Docker

生产中 Pod 的 Kubernetes 持久卷

windows - `Failed to solve with frontend dockerfile.v0...` 如何解决?

macos - 链接 docker 容器时 Ubuntu 无法访问主机

mysql - NodeJS 无法连接到 Docker 容器内的 MYSQL

kubernetes - NodePort 类型服务在集群外部不可访问

amazon-ec2 - 使用 Ansible (+Docker ?) 进行持续部署和 AWS 自动扩展

python - docker-从更新的代码执行文件

docker - Kubelet 错误地认为磁盘已满