An open API service indexing awesome lists of open source software.

https://github.com/freedomben/pvc-volume-tester

Simple app to help test PVC volumes
https://github.com/freedomben/pvc-volume-tester

Last synced: 9 months ago
JSON representation

Simple app to help test PVC volumes

Awesome Lists containing this project

README

          

# volume-tester

This volume tester is a simple web app will help you verify persistent storage is working correctly in your OpenShift or Kubernetes cluster. It just reads/writes to a file on the volume and tells you whether it is reading/writing and persisting properly.

There are a few endpoints you can use to control it (made to be easy with curl). It can read/write to a file on the volume and thus determine whether your storage is persisting across pods and has working permissions.

The only configuration required for the app is to tell it where the test file will be. For security reasons this must be an environment variable rather than specified as a post or query param to the app. Set the env var `VOLUME_TEST_FILE` to point at the file that should be used for testing.

## Quick/High-level Usage

More detailed steps are [available below](#to-test-your-pvc):

1. Create a PVC to claim a volume from your storage solution.
1. Deploy this project's image with a Deployment, Service, and Route. Set the environment variable `VOLUME_TEST_FILE` to a file path inside the volume you mount. Image: `quay.io/freedomben/volume-tester:latest`
1. Get the route for the image, and replace `` below with it: `oc get route`
1. Test basic reading/writing: `curl http:///readwrite`
1. Write the test string to a file: `curl http:///write`
1. Delete the Pod (the Deployment will recreate it and attach the PVC which should contain the persisted file)
1. Read the file and verify the contents persisted: `curl http:///read`

## To test your PVC

### 1. Create a PVC and Deploy this Image to the cluster

Setting up your storage backend and StorageClass is outside the scope of this tool. Please see the vendor documentation for your solution of choice. You should either have dynamic provisioning set up, or statically create the PVs required to satisfy the PVC claims.

#### A. Create the PVC

If you have dynamic provisioning set up via a StorageClass, creating the PVC should be enough to get the PV created (Note that some CSI providers don't provision the PV until it's actually needed).

Example PVC:

```yaml
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
labels:
app: pvc-volume-test
name: pvc-test-volume-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
# This storageClassName must be correct for your cluster storage solution
storageClassName: gp2
```

#### B. Create the Deployment, Service, and Route:

```yaml
apiVersion: v1
kind: List
metadata: {}
items:
- apiVersion: v1
kind: Service
metadata:
labels:
app: pvc-volume-test
name: pvc-volume-test
spec:
ports:
- name: 8080-tcp
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: pvc-volume-test
- apiVersion: route.openshift.io/v1
kind: Route
metadata:
labels:
app: pvc-volume-test
name: pvc-volume-test
spec:
port:
targetPort: 8080-tcp
to:
kind: Service
name: pvc-volume-test
weight: 100
wildcardPolicy: None
- apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: pvc-volume-test
name: pvc-volume-test
spec:
replicas: 1
selector:
matchLabels:
app: pvc-volume-test
template:
metadata:
labels:
app: pvc-volume-test
spec:
containers:
- image: quay.io/freedomben/volume-tester:latest
name: pvc-volume-test-container
imagePullPolicy: Always
ports:
- containerPort: 8080
protocol: TCP
env:
- name: VOLUME_TEST_FILE
value: '/mnt/some/directory/volume-test-file.txt'
volumeMounts:
- mountPath: "/mnt/some/directory"
name: pvc-test-volume
# Change this Volumes section to match a PVC you created for your storage backend
volumes:
- name: pvc-test-volume
persistentVolumeClaim:
claimName: pvc-test-volume-claim
```

### 2. Test basic reading/writing to the volume

1. To test basic reading/writing: `curl http:///readwrite`

```
$ curl http:///readwrite
Read/Write: OK - Test contents: f2cc50f83a071bf8d0be551c09ea8eb6
```

Your test contents will be different. The string is randomly generated on each request.

### 3. Test Persistence

1. First make sure the read test fails: `curl http:///read`

```bash
$ curl http:///read
Read: Failed - File contents: f2cc50f83a071bf8d0be551c09ea8eb6 - Expected: ABCDEFGHIJKLMNOPQRSTUVWXYZ.
If you have not written the file yet, curl /write, delete and recreate the Pod, and try /read again
```

1. Now write the test string to a file: `curl http:///write`

```bash
$ curl http:///write
Wrote 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' to file '/mnt/volume-test/temp.txt'. Delete and re-create this Pod and curl /read to verify the string persisted
```

1. Delete and recreate the Pod (so that the volume gets detached and reattached by your storage solution). Don't delete the PVC otherwise your storage backend may delete the corresponding volume, throwing away the persistence we are testing.

```bash
oc delete pod # Hint: Tab-complete this if oc autocomplete is configured
```

1. Read the file and verify contents persisted: `curl http:///read`

```bash
$ curl http:///read
Read: OK - File contents: ABCDEFGHIJKLMNOPQRSTUVWXYZ - Expected: ABCDEFGHIJKLMNOPQRSTUVWXYZ.
```

1. You can clear the test file contents for repeated testing: `curl http:///clear`

```bash
$ curl http:///clear
Wrote empty string to file '/mnt/volume-test/temp.txt'. Use /write to write test string
```

### 4. Clean up

To clean up all of the resources created above, you can use:

```bash
oc delete all -l app=pvc-volume-test
```

## Endpoints Reference (RPC-style):

* `/readwrite`: Writes and then reads a string to the file. This can determine if there are any permission issues in place.
* `/write`: Writes a static test string to the file which can be checked with `/read`
* `/read`: Checks that the test file has the static test string as it's contents
* `/clear`: Writes an empty string to the test file