Volume Support for Knative services

You can provide data storage for Knative Services by configuring different volumes types. Serving supports mounting the volume types: emptyDir, secret, configMap and projected. PersistentVolumes are supported but require a feature flag to be enabled.

Warning

Mounting large volumes may add considerable overhead to the application’s start up time.

Bellow there is an example of using a persistent volume claim with a Knative Service.

Prerequisites

Before you can configure PVCs for a Service, this feature must be enabled in the config-features ConfigMap as follows:

  1. kubectl patch --namespace knative-serving configmap/config-features \
  2. --type merge \
  3. --patch '{"data":{"kubernetes.podspec-persistent-volume-claim": "enabled", "kubernetes.podspec-persistent-volume-write": "enabled"}}'
  • The kubernetes.podspec-persistent-volume-claim extension controls whether persistent volumes (PVs) can be used with Knative Serving.
  • The kubernetes.podspec-persistent-volume-write extension controls whether PVs are available to Knative Serving with the write access.

Note

If you have installed Serving via the Knative operator then you need to set the above feature flags only at the corresponding Serving CR.

Procedure

  • Modify the PVC configuration for your Service:
  1. apiVersion: serving.knative.dev/v1
  2. kind: Service
  3. ...
  4. spec:
  5. template:
  6. spec:
  7. containers:
  8. ...
  9. volumeMounts:
  10. - mountPath: /data
  11. name: mydata
  12. readOnly: false
  13. volumes:
  14. - name: mydata
  15. persistentVolumeClaim:
  16. claimName: knative-pv-claim
  17. readOnly: false
  18. ---
  19. apiVersion: v1
  20. kind: PersistentVolumeClaim
  21. metadata:
  22. name: knative-pv-claim
  23. spec:
  24. accessModes:
  25. - ReadWriteOnce
  26. resources:
  27. requests:
  28. storage: 1Gi