VolumeClaimTemplates with subPath

时间:2018-05-18 10:06:11

标签: kubernetes

在Kubernetes集群中,我需要将 StatefulSet 绑定到一个卷(图中的卷0 ),并且对于每个副本,它应该声明一个子路径文件夹(文件夹node0上的replica1,文件夹node1上的副本2,...)。

enter image description here

我不能做这样的事情。有什么建议吗?

我认为有可能指示statefulset使用subPath。 像这个例子:

[statefulset.yml]

  ...
  volumeClaimTemplates:
  - metadata:
      name: my-claim
    spec:
      resources:
        requests:
          storage: 1Gi
      accessModes:
      - ReadWriteMany
      storageClassName: volume-0
      subPath: node

有人有这样的用例吗?

1 个答案:

答案 0 :(得分:0)

您应该在subPath子句中使用VolumeMounts

例如:

apiVersion: v1
kind: Pod
metadata:
  name: my-lamp-site
spec:
    containers:
    - name: apachephp
      image: php:7.0-apache
      volumeMounts:
      - mountPath: /var/www/html
        name: apachephp-data
        subPath: html
      - mountPath: /var/www/upload
        name: apachephp-data
        subPath: upload
    volumes:
    - name: apachephp-data
      persistentVolumeClaim:
        claimName: apachephp-claim-data

volumeMounts.subPath属性可用于在引用的卷中指定子路径,而不是其根。 为了清楚起见,我建议使用subPath子句为多个Pod共享一个卷,甚至在一个Pod中共享多个卷。