From e8a4e6a1fdb977551390aa6f5b0cfba048a56e9f Mon Sep 17 00:00:00 2001 From: Humble Chirammal Date: Thu, 28 Oct 2021 11:22:42 +0530 Subject: [PATCH] ceph: support ephemeral volumes with Ceph CSI RBD and CephFS driver This commit make required changes for ceph csi drivers to work with ephemeral volume support. With ephemeral volume support a user can specify ephemeral volumes in its pod spec and tie the lifecycle of the PVC with the POD. An example POD spec looks like this: ``` kind: Pod apiVersion: v1 metadata: name: csi-rbd-demo-ephemeral-pod spec: containers: - name: web-server image: docker.io/library/nginx:latest volumeMounts: - mountPath: "/myspace" name: mypvc volumes: - name: mypvc ephemeral: volumeClaimTemplate: spec: accessModes: ["ReadWriteOnce"] storageClassName: "rook-ceph-block" resources: requests: storage: 1Gi ``` Signed-off-by: Humble Chirammal --- Documentation/ceph-csi-drivers.md | 46 +++++++++++++++++++ .../ceph/csi/cephfs/pod-ephemeral.yaml | 21 +++++++++ .../ceph/csi/rbd/pod-ephemeral.yaml | 21 +++++++++ 3 files changed, 88 insertions(+) create mode 100644 cluster/examples/kubernetes/ceph/csi/cephfs/pod-ephemeral.yaml create mode 100644 cluster/examples/kubernetes/ceph/csi/rbd/pod-ephemeral.yaml diff --git a/Documentation/ceph-csi-drivers.md b/Documentation/ceph-csi-drivers.md index 8c312e44a6c81..d3eb984df2973 100644 --- a/Documentation/ceph-csi-drivers.md +++ b/Documentation/ceph-csi-drivers.md @@ -92,3 +92,49 @@ kubectl create -f https://raw.githubusercontent.com/csi-addons/volume-replicatio 2. Enable the volume replication controller: - For Helm deployments see the [csi.volumeReplication.enabled setting](helm-operator.md#configuration). - For non-Helm deployments set `CSI_ENABLE_VOLUME_REPLICATION: "true"` in operator.yaml + +## generic ephemeral volume support + +The generic ephemeral volume feature adds support for specifying PVCs in the +`volumes` field to indicate a user would like to create a Volume as part of the pod spec. +This feature requires the GenericEphemeralVolume feature gate to be enabled. +Because this is a beta feature, it is enabled by default in kubernetes versions >=1.21. + +For example: + +```yaml +kind: Pod +apiVersion: v1 +metadata: + name: csi-rbd-demo-ephemeral-pod +spec: + containers: + - name: web-server + image: docker.io/library/nginx:latest + volumeMounts: + - mountPath: "/myspace" + name: mypvc + volumes: + - name: mypvc + ephemeral: + volumeClaimTemplate: + spec: + accessModes: ["ReadWriteOnce"] + storageClassName: "rook-ceph-block" + resources: + requests: + storage: 1Gi +``` + +A volume claim template is defined inside the pod spec which refers to a volume +provisioned and used by the pod with its lifecycle. The volumes are provisioned +when pod get spawned and destroyed at time of pod delete. + +Refer to [ephemeral-doc]( https://kubernetes.io/docs/concepts/storage/ephemeral-volumes/#generic-ephemeral-volumes ) +for more info. + +### Prerequisites +1. Requires Kubernetes v1.21+ which supports ephemeral volume. +2. In [pod-ephemeral](https://github.com/rook/rook/tree/{{ branchName }}/cluster/examples/kubernetes/ceph/csi/rbd/pod-ephemeral.yaml), +`storageclass` should be the name of the `storageclass` which is already available for the RBD +provisioning to work. \ No newline at end of file diff --git a/cluster/examples/kubernetes/ceph/csi/cephfs/pod-ephemeral.yaml b/cluster/examples/kubernetes/ceph/csi/cephfs/pod-ephemeral.yaml new file mode 100644 index 0000000000000..d5035e792ff00 --- /dev/null +++ b/cluster/examples/kubernetes/ceph/csi/cephfs/pod-ephemeral.yaml @@ -0,0 +1,21 @@ +kind: Pod +apiVersion: v1 +metadata: + name: csi-cephfs-demo-ephemeral-pod +spec: + containers: + - name: web-server + image: docker.io/library/nginx:latest + volumeMounts: + - mountPath: "/myspace" + name: mypvc + volumes: + - name: mypvc + ephemeral: + volumeClaimTemplate: + spec: + accessModes: ["ReadWriteMany"] + storageClassName: "rook-cephfs" + resources: + requests: + storage: 1Gi diff --git a/cluster/examples/kubernetes/ceph/csi/rbd/pod-ephemeral.yaml b/cluster/examples/kubernetes/ceph/csi/rbd/pod-ephemeral.yaml new file mode 100644 index 0000000000000..bd752470b76cc --- /dev/null +++ b/cluster/examples/kubernetes/ceph/csi/rbd/pod-ephemeral.yaml @@ -0,0 +1,21 @@ +kind: Pod +apiVersion: v1 +metadata: + name: csi-rbd-demo-ephemeral-pod +spec: + containers: + - name: web-server + image: docker.io/library/nginx:latest + volumeMounts: + - mountPath: "/myspace" + name: mypvc + volumes: + - name: mypvc + ephemeral: + volumeClaimTemplate: + spec: + accessModes: ["ReadWriteOnce"] + storageClassName: "rook-ceph-block" + resources: + requests: + storage: 1Gi