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

10/24/2017

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.

-- djuarez
kubectl
kubernetes
volumes

2 Answers

10/24/2017

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.)

-- Janos Lenart
Source: StackOverflow

4/10/2018

Yes.

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

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

-- Bryan Larsen
Source: StackOverflow