Deploying an app on OpenShift Data Foundation
After you install the OpenShift Data Foundation add-on for your Red Hat® OpenShift® on IBM Cloud® cluster, you can use the ODF storage classes to create a persistent volume claim (PVC). Then, refer to the PVC in your deployment so that your app can save and use data from the underlying ODF storage device.
- Minimum required permissions
- Editor platform access role and the Writer service access role for the cluster in IBM Cloud Kubernetes Service.
Access your Red Hat OpenShift cluster.
-
List the ODF storage classes. For more information about ODF storage classes, see the Storage class reference.
oc get sc | grep openshift
Example output
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE Immediate true 9m19s ocs-storagecluster-ceph-rbd openshift-storage.rbd.csi.ceph.com Delete Immediate false 9m19s ocs-storagecluster-ceph-rgw openshift-storage.ceph.rook.io/bucket Delete Immediate false 18m ocs-storagecluster-cephfs openshift-storage.cephfs.csi.ceph.com Delete Immediate true 10m openshift-storage.noobaa.io openshift-storage.noobaa.io/obc Delete Immediate false 6m32s
-
Create a PVC that refers to the storage class that you want to use. Save and edit the following PVC configuration file to refer to the storage class that you want to use. If you enabled encryption with Hyper Protect Crypto Services, you can use the storage class
ocs-storagecluster-ceph-rbd-encrypted
which supports encryption. Example PVC for using theocs-storagecluster-cephfs
storage class.apiVersion: v1 kind: PersistentVolumeClaim metadata: name: odf-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 10Gi storageClassName: ocs-storagecluster-cephfs
-
Create the PVC in your cluster.
oc create -f <my-pvc.yaml>
-
Create a YAML configuration file for a pod that mounts the PVC that you created. The following example creates an
nginx
pod that writes the current date and time to atest.txt
file.apiVersion: v1 kind: Pod metadata: name: app spec: containers: - name: app image: nginx command: ["/bin/sh"] args: ["-c", "while true; do echo $(date -u) >> /test/test.txt; sleep 600; done"] volumeMounts: - name: persistent-storage mountPath: /test volumes: - name: persistent-storage persistentVolumeClaim: claimName: odf-pvc
-
Create the pod in your cluster.
oc apply -f pod.yaml
-
To verify that the pod is deployed, wait for your app to get into a
Running
status.oc get pods
Example output
NAME READY STATUS RESTARTS AGE app 1/1 Running 0 2m58s
-
Verify that the app can write data.
- Log in to your pod.
oc exec <app-pod-name> -it -- bash
- Display the contents of the
test.txt
file to confirm that your app can write data to your persistent storage.
Example outputcat /test/test.txt
Tue Mar 2 20:09:19 UTC 2021 Tue Mar 2 20:09:25 UTC 2021 Tue Mar 2 20:09:31 UTC 2021 Tue Mar 2 20:09:36 UTC 2021 Tue Mar 2 20:09:42 UTC 2021 Tue Mar 2 20:09:47 UTC 2021
- Exit the pod.
exit
- Log in to your pod.