Skip to main content
Welcome to this demo showing how to add persistent storage to an OpenShift 4 application. This lesson covers creating a PersistentVolumeClaim (PVC) from the OpenShift web console, mounting it into your DeploymentConfig, and verifying the application can read and update files stored on the mounted volume. This demo is part of the OpenShift 4 course.

Goal

Add persistent storage to an application so the app can read a file at /data/testfile.txt from within the container and reflect updates across replicas when the underlying storage supports shared mounts.

Application used in this demo

I updated a simple Flask application so it reads a file and displays its contents on the /read_file route. The app expects the file at /data/testfile.txt. Here is the simplified Flask app used for this demo:

Reproducing the issue (before adding storage)

If you try to open /read_file before adding storage, the app returns an error because /data/testfile.txt (or even the /data directory) does not exist inside the pod. A quick way to confirm this is to open a terminal into the pod (from the OpenShift web console, select the pod and click Terminal) and list the root filesystem and mounts. The terminal is a useful tool for inspections and debugging. Example terminal session showing the root filesystem inside the pod:

Add persistent storage (PVC) via OpenShift web console

To persist the file across pod restarts and share it between replicas (when supported), create a PersistentVolumeClaim (PVC). From the OpenShift web console:
  • Navigate to Storage → Create PersistentVolumeClaim.
  • Provide a claim name, requested size, and select the appropriate access mode (for example RWO or RWX depending on your storage backend).
A screenshot of the OpenShift Origin web console showing the "Create Storage" form, with fields for a storage claim name, access mode (RWO/RWX/ROX) and size. The left navigation pane highlights Storage and Create/Cancel buttons are visible at the bottom.
Once the PVC is created, edit your application’s DeploymentConfig and click Add Storage under Volumes. Set the mount path inside the container to /data (this matches the Flask app’s expected path). After updating the DeploymentConfig, redeploy or let OpenShift rollout the new pods. Then open a terminal into one of the new pods and verify /data is now a mounted volume:
Create testfile.txt in the mounted volume and add some content:
Now access the application at /read_file. The UI should display the text from /data/testfile.txt. If you append more text to /data/testfile.txt and refresh the browser, the application will show the updated contents.

Multiple replicas and shared storage

If you scale the application, new replicas will mount the same PVC. Whether multiple pods can read or write to that volume concurrently depends on the PVC’s access mode and the underlying storage provider. Use the appropriate access mode when creating your PVC depending on whether replicas need simultaneous write access.
If multiple replicas require simultaneous read/write access, make sure your storage class and PersistentVolume support ReadWriteMany (RWX). Many backend volumes only support ReadWriteOnce (RWO), which restricts writable mounts to a single node.

Quick verification checklist

  • PVC created in OpenShift and bound to a PV.
  • DeploymentConfig updated to mount the PVC at /data.
  • New pods show /data as a mounted filesystem.
  • testfile.txt created at /data/testfile.txt.
  • Accessing /read_file in the app displays the file contents.
  • If running multiple replicas, confirm the storage supports the chosen access mode (RWX vs RWO).

Watch Video