Search code examples
kuberneteskubectlvolumes

Is there any way to have a Flex Volume inside a Persistent Volume Claim?


I am currently using the Kubernetes Executor for Gitlab CI and since:

https://docs.gitlab.com/runner/executors/kubernetes.html:"At this time hostPath, PVC, configMap, and secret volume types are supported".

I was wondering if there is a possibility to have a Flex Volume with a Persistent Volume Claim in Kubernetes.


Solution

  • Any type of PV can back a PVC. You need to create the PV by hand and then specify the name in .spec.volumeName of the PVC (or use .spec.selector with labels). Like so:

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

    As a reference I used this PV (but the type of the PV does not matter):

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

    (Alternatively, automatic provisioning with your own storageclass is also possible, but I guess this is not your use case.)