【问题标题】:Is there any way to have a Flex Volume inside a Persistent Volume Claim?有没有办法在持久卷声明中拥有一个弹性卷?
【发布时间】:2018-04-04 23:42:35
【问题描述】:

我目前正在使用 Kubernetes Executor for Gitlab CI,因为:

https://docs.gitlab.com/runner/executors/kubernetes.html:"目前支持hostPath、PVC、configMap、secret volume类型"。

我想知道是否有可能在 Kubernetes 中拥有一个具有持久卷声明的弹性卷。

【问题讨论】:

    标签: kubernetes kubectl volumes


    【解决方案1】:

    任何类型的 PV 都可以支持 PVC。您需要手动创建 PV,然后在 PVC 的.spec.volumeName 中指定名称(或使用带有标签的.spec.selector)。像这样:

    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: task-pv-claim
    spec:
      volumeName: task-pv-volume
      storageClassName: manual
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 3Gi
    

    作为参考,我使用了这个 PV(但 PV 的类型无关紧要):

    kind: PersistentVolume
    apiVersion: v1
    metadata:
      name: task-pv-volume
    spec:
      storageClassName: manual
      capacity:
        storage: 10Gi
      accessModes:
        - ReadWriteOnce
      hostPath:
        path: "/tmp/data"
    

    (或者,也可以使用您自己的存储类进行自动配置,但我想这不是您的用例。)

    【讨论】:

      【解决方案2】:

      是的。

      apiVersion: v1
      kind: PersistentVolume
      metadata:
        name: pv0001 
      spec:
        capacity:
          storage: 1Gi 
        accessModes:
          - ReadWriteOnce
        flexVolume:
          driver: openshift.com/foo 
          fsType: "ext4" 
          secretRef: foo-secret 
          readOnly: true 
          options: 
            fooServer: 192.168.0.1:1234
            fooVolumeName: bar
      

      参考:https://docs.openshift.org/latest/install_config/persistent_storage/persistent_storage_flex_volume.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-11
        相关资源
        最近更新 更多