Skip to main content
Welcome — this demo covers the basics of using storage in an OpenShift cluster. You will see how a simple Flask app can read a file from a mounted volume at /data/testfile.txt, how to inspect pod filesystems, and how to create and mount a PersistentVolumeClaim (PVC) via the OpenShift web console.
A presentation-style slide titled "Red Hat OpenShift Demo" with the heading "Storage." A vertical photo inset shows a person typing at a keyboard with code visible on a monitor.

What this app does

  • Renders a home page (/) that shows the pod hostname and a selected color.
  • Changes the displayed color via the route /color/<new_color>.
  • Reads and displays the contents of /data/testfile.txt when a user visits /read_file.
If the file /data/testfile.txt is not present (e.g., because no volume is mounted at /data), the /read_file route returns a clear error message. This is useful for verifying whether a PVC is correctly mounted into a pod.

Flask application (complete example)

Below is the corrected Flask application used in this demo. It implements the routes described above and uses with open(...) for safe file handling.

Color mapping quick reference

Inspecting the pod filesystem

If /data is not mounted or the file does not exist, you can open a terminal for the pod in the OpenShift web console and inspect the root filesystem and mounts. Example root directory listing from inside a container:
If /data is missing or empty, /read_file will fail with the FileNotFound error message returned by the app.

Add persistent storage with the OpenShift web console

To mount persistent storage at /data so the app can read /data/testfile.txt, follow these steps in the OpenShift web console:
  1. Go to the Storage section and click Create Storage.
  2. Create a PersistentVolumeClaim (PVC): provide a name and the requested size.
  3. Open your DeploymentConfig (or Deployment) and click Add Storage under Volumes.
  4. Select the PVC you created and set the Container Mount Path to /data.
  5. Redeploy the workload so the pod mounts the PVC.
After redeploying, open the pod terminal and verify /data is present and writable. Example commands you can run inside the pod to create and verify the test file:
Now visit http://<route-or-pod>/read_file in your browser — the app will read /data/testfile.txt and display its contents. If you edit the file inside the pod and refresh the page, the new contents will be displayed.

Behavior when scaling replicas

  • If you scale your application (increase replica count), each replica that mounts the same PVC at /data will see the same testfile.txt.
  • Whether multiple pods can mount the same PVC concurrently depends on the storage class/provisioner and the PVC access mode (e.g., ReadWriteOnce vs ReadWriteMany).
Make sure your storage class and PVC support the desired access mode (for example, ReadWriteMany if you need multiple pods to concurrently mount the same volume). Check the storage class documentation or your cloud provider’s guidance when configuring shared storage.

Troubleshooting checklist

  • Confirm the pod shows the PVC mounted at /data.
  • Verify the file permissions allow the container user to read /data/testfile.txt.
  • If FileNotFoundError appears, ensure the PVC is bound and the mount path is correct.
  • Check pod events and deployment rollout logs for volume-related errors.
Thanks for following this demo — you should now be able to mount a PVC into an OpenShift pod and serve file contents from /data/testfile.txt in your application.

Watch Video