|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * serverless/admin_guide/serverless-configuration.adoc |
| 4 | + |
| 5 | +:_content-type: PROCEDURE |
| 6 | +[id="serverless-enabling-pvc-support_{context}"] |
| 7 | += Enabling PVC support |
| 8 | + |
| 9 | +Some serverless applications need permanent data storage. To achieve this, you can configure persistent volume claims (PVCs) for your Knative services. |
| 10 | + |
| 11 | +.Procedure |
| 12 | + |
| 13 | +. To enable Knative Serving to use PVCs and write to them, modify the `KnativeServing` custom resource (CR) to include the following YAML: |
| 14 | ++ |
| 15 | +.Enabling PVCs with write access |
| 16 | +[source,yaml] |
| 17 | +---- |
| 18 | +... |
| 19 | +spec: |
| 20 | + config: |
| 21 | + features: |
| 22 | + "kubernetes.podspec-persistent-volume-claim": enabled |
| 23 | + "kubernetes.podspec-persistent-volume-write": enabled |
| 24 | +... |
| 25 | +---- |
| 26 | ++ |
| 27 | +* The `kubernetes.podspec-persistent-volume-claim` extension controls whether persistent volumes (PVs) can be used with Knative Serving. |
| 28 | +* The `kubernetes.podspec-persistent-volume-write` extension controls whether PVs are available to Knative Serving with the write access. |
| 29 | +
|
| 30 | +. To claim a PV, modify your service to include the PV configuration. For example, you might have a persistent volume claim with the following configuration: |
| 31 | ++ |
| 32 | +[NOTE] |
| 33 | +==== |
| 34 | +Use the storage class that supports the access mode that you are requesting. For example, you can the `ocs-storagecluster-cephfs` class for the `ReadWriteMany` access mode. |
| 35 | +==== |
| 36 | ++ |
| 37 | +.PersistentVolumeClaim configuration |
| 38 | +[source,yaml] |
| 39 | +---- |
| 40 | +apiVersion: v1 |
| 41 | +kind: PersistentVolumeClaim |
| 42 | +metadata: |
| 43 | + name: example-pv-claim |
| 44 | + namespace: my-ns |
| 45 | +spec: |
| 46 | + accessModes: |
| 47 | + - ReadWriteMany |
| 48 | + storageClassName: ocs-storagecluster-cephfs |
| 49 | + resources: |
| 50 | + requests: |
| 51 | + storage: 1Gi |
| 52 | +---- |
| 53 | ++ |
| 54 | +In this case, to claim a PV with write access, modify your service as follows: |
| 55 | ++ |
| 56 | +.Knative service PVC configuration |
| 57 | +[source,yaml] |
| 58 | +---- |
| 59 | +apiVersion: serving.knative.dev/v1 |
| 60 | +kind: Service |
| 61 | +metadata: |
| 62 | + namespace: my-ns |
| 63 | +... |
| 64 | +spec: |
| 65 | + template: |
| 66 | + spec: |
| 67 | + containers: |
| 68 | + ... |
| 69 | + volumeMounts: <1> |
| 70 | + - mountPath: /data |
| 71 | + name: mydata |
| 72 | + readOnly: false |
| 73 | + volumes: |
| 74 | + - name: mydata |
| 75 | + persistentVolumeClaim: <2> |
| 76 | + claimName: example-pv-claim |
| 77 | + readOnly: false <3> |
| 78 | +---- |
| 79 | +<1> Volume mount specification. |
| 80 | +<2> Persistent volume claim specification. |
| 81 | +<3> Flag that enables read-only access. |
| 82 | ++ |
| 83 | +[NOTE] |
| 84 | +==== |
| 85 | +To successfully use persistent storage in Knative services, you need additional configuration, such as the user permissions for the Knative container user. |
| 86 | +==== |
0 commit comments