/data/testfile.txt, how to inspect pod filesystems, and how to create and mount a PersistentVolumeClaim (PVC) via the OpenShift web console.

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.txtwhen a user visits/read_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 useswith 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:
/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:
- Go to the Storage section and click Create Storage.
- Create a PersistentVolumeClaim (PVC): provide a name and the requested size.
- Open your DeploymentConfig (or Deployment) and click Add Storage under Volumes.
- Select the PVC you created and set the Container Mount Path to
/data. - Redeploy the workload so the pod mounts the PVC.
/data is present and writable.
Example commands you can run inside the pod to create and verify the test file:
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
/datawill see the sametestfile.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
FileNotFoundErrorappears, ensure the PVC is bound and the mount path is correct. - Check pod events and deployment rollout logs for volume-related errors.
Links and references
- OpenShift Storage concepts: https://docs.openshift.com/ (search “OpenShift persistent storage” in the docs)
- Kubernetes Persistent Volumes and PersistentVolumeClaims: https://kubernetes.io/docs/concepts/storage/persistent-volumes/
- Storage class access modes (ReadWriteOnce, ReadWriteMany): https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes
/data/testfile.txt in your application.