要共享给另一个 Pod 的只读文件夹

dav*_*rez 0 volume kubernetes

我有一个需要创造大量就业机会的 Pod。我想共享一个只读文件夹。我该怎么做?

我可以想象的几个想法(我是 Kubernetes 的新手):

  • 临时卷似乎是一个不错的选择,但我读到它不能与另一个 Pod 共享。
  • 我认为 NFS 太过分了,无法满足我的需求。
  • 也许,我可以构建一个仅包含数据的 Docker 镜像,但这是 Docker 的一个已弃用的功能。
  • kubectl cp将基础 Pod 之间的数据复制到作业中的 Pod。

对此更好的解决方案是什么?

TAM*_*TAM 5

您可以使用 aPersistentVolume并将其安装为 pod 内的只读卷PersistentVolumeClaim。要安装只读卷,请设置.spec.containers[*].volumeMounts[*].readOnlytrue

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
    - name: myfrontend
      image: nginx
      volumeMounts:
      - mountPath: "/var/www/html"
        name: mypd
        readOnly: true
  volumes:
    - name: mypd
      persistentVolumeClaim:
        claimName: myclaim
Run Code Online (Sandbox Code Playgroud)

查看这些链接:

  1. https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims
  2. https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistent-volumes