---
title: "How to Add Persistent Storage to an Application"
canonical: "https://kb.uconn.edu/space/IKB/28730490884/How%20to%20Add%20Persistent%20Storage%20to%20an%20Application"
format: markdown
---
## Overview

By default, container storage is **ephemeral** — data is lost when a pod restarts. To persist data (databases, uploads, logs), you need to attach a **Persistent Volume Claim (PVC)**.

> **Important:** Without persistent storage, any data written inside a container will be lost whenever the pod restarts or reschedules.

---

## Create a PVC via CLI

```shell
# Create a PVC requesting 5Gi of storage
cat <<EOF | oc apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-app-data
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
EOF

# Check PVC status
oc get pvc
```

---

## Mount Storage to Your Deployment

```shell
# Add the PVC to your deployment
oc set volume deployment/my-app \
  --add --name=data-volume \
  --type=persistentVolumeClaim \
  --claim-name=my-app-data \
  --mount-path=/app/data
```

> **Tip:** Common mount paths include `/app/data` for application data, `/var/lib/mysql` for MySQL, and `/var/lib/postgresql/data` for PostgreSQL.

---

## Create a PVC via Web Console

1. Navigate to **Storage** → **PersistentVolumeClaims** in the sidebar.
2. Click **Create PersistentVolumeClaim**.
3. Fill in the name, access mode, and size.
4. Click **Create**.
5. Attach it to your deployment under **Workloads** → **Deployments** → your app → **Actions** → **Add Storage**.

---

## Access Modes

| Mode | Description | Use Case |
| --- | --- | --- |
| **ReadWriteOnce (RWO)** | Read/write by a single node | Databases, single-pod apps |
| **ReadWriteMany (RWX)** | Read/write by many nodes | Shared file storage across replicas |
| **ReadOnlyMany (ROX)** | Read-only by many nodes | Shared config or static content |

---

## Common Storage Scenarios

| Scenario | Recommended Mode | Suggested Size |
| --- | --- | --- |
| MySQL / PostgreSQL database | RWO | 10Gi - 50Gi |
| File uploads (user content) | RWO or RWX | 5Gi - 20Gi |
| Shared static assets | ROX | 1Gi - 5Gi |
| Application logs | RWO | 2Gi - 10Gi |

---

## Troubleshooting PVC Issues

| Symptom | Cause | Fix |
| --- | --- | --- |
| PVC stuck in **Pending** | No matching PV available | Contact the ITS Platform Team for storage provisioning |
| Pod won't start after adding PVC | Mount path conflict | Verify the mount path doesn't overwrite critical app files |
| Permission denied on mounted volume | Container running as wrong user | Add `fsGroup` to the pod security context |

---

*UConn ITS Infrastructure Services — OpenShift Knowledge Base*