In this section, we will execute a simple example of using persistent storage by creating a file that will be stored on a Persistent Volume in our cluster and then confirming that it will "persist" across pod failures and recreation.

Red Hat OpenShift Service on AWS (ROSA) supports both Elastic Block Store (EBS) and Elastic File System (EFS) for Persistent Volumes. For more information, see the following resources:

What will you learn?

  • Viewing persistent volume claims
  • Storing files within a pod
  • Checking for files after a pod crash

What do you need before starting?

  • Fully deployed application on OpenShift Service for AWS cluster

Steps for storing and managing files in OpenShift Service for AWS clusters

  1. Inside the OpenShift web UI click Storage in the left menu then Persistent Volume Claims
    • You will see a list of all persistent volume claims that our application has made. In this case, there is just one called "ostoy-pvc". If you click on it you will see other pertinent information such as whether it is bound or not, size, access mode, and storage class.
      Note: RWO (Read-Write-Once) means that the volume can only be mounted to one node, but the pod(s) can both read and write to that volume. This option for Persistent Volumes in OpenShift Service for AWS is backed by EBS; thus it only supports RWO.
  2. In the OSToy app, click Persistent Storage in the left menu.
  3. In the Filename field shown in Figure 14, enter a filename for the file you will create (e.g., test-pv.txt). Be sure to use a .txt extension so that the file will be visible in the browser.
  4. In the File Contents box, enter text to be stored in the file (e.g., "OpenShift is the greatest thing since sliced bread!" or "test"). Then click Create file.
The Persistent Storage screen in OSToy.
Figure 14. The Persistent Storage screen in OSToy.
  1. You will then see the file you created appear above, under "Existing files". Click on the file and you will see the filename and the contents you entered as shown in Figure 15.
List of existing files.
Figure 15. List of existing files.

Crash the pod and recover the file

  1. Click on Home in the left menu.
  2. Click on the Crash pod button. (You can enter a message if you'd like).
  3. Once the pod is back up, click Persistent Storage in the left menu.
  4. You will see the file you created is still there; you can open it to view its contents to confirm.

Confirm via the container

  1. Now let's confirm that it's actually there by using the CLI and checking if it is available to the container. If you looked inside the deployment YAML file, we mounted the directory /var/demo_files to our PVC. So get the name of your front-end pod through the following:
    oc get pods
  2. Then get an SSH session into the container:
    oc rsh <podname>
  3. Then enter the following:

    cd /var/demo_files
  4. If you enter ls, you can see all the files you created. Next, let's open the file we created and see the contents:

    cat test-pv.txt
  5. You should see the text you entered in the UI. The whole flow would look like the following:

    $ oc get pods
    NAME                                  READY     STATUS    RESTARTS   AGE
    ostoy-frontend-5fc8d486dc-wsw24       1/1       Running   0          18m
    ostoy-microservice-6cf764974f-hx4qm   1/1       Running   0          18m
    $ oc rsh ostoy-frontend-5fc8d486dc-wsw24
    $ cd /var/demo_files/
    $ ls
    lost+found   test-pv.txt
    $ cat test-pv.txt
    OpenShift is the greatest thing since sliced bread!
  6. Then exit the session by typing exit. You will then be in your CLI.

You are now ready to configure your application.

Get more support

More OpenShift resources