Skip to content

csi_test

Jaime Conchello edited this page Sep 3, 2025 · 3 revisions

Shared PVC Test

This example demonstrates how to deploy a Deployment with 2 replicas, where both Pods are scheduled on the same node and share a ReadWriteOnce PersistentVolumeClaim (PVC) provisioned via the opennebula-fs StorageClass.

Both Pods write to a shared file inside the volume, demonstrating that the PVC is accessible to multiple containers on the same node.

The test assumes that the CSI plugin has already been deployed on a CAPONE cluster.

Step 1: Create a PVC

The YAML below defines a PVC that requests 1Gi of storage:

# PersistentVolumeClaim definition
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: test-pvc-opennebula
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1024Mi
  storageClassName: opennebula-fs

Apply the PVC using:

kubectl apply -f pvc.yaml

Step 2: Create a Deployment Using the PVC

Next, define a Deployment with 2 replicas that mounts the PVC into each container.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: test-app
  template:
    metadata:
      labels:
        app: test-app
    spec:
      affinity:
        podAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchLabels:
                  app: test-app
              topologyKey: kubernetes.io/hostname
      containers:
        - name: test-container
          image: busybox
          command: ["sh", "-c", "echo $HOSTNAME >> /data/example && sleep infinity"]
          volumeMounts:
            - mountPath: /data
              name: test-volume
      volumes:
        - name: test-volume
          persistentVolumeClaim:
            claimName: test-pvc-opennebula

Where important settings are:

  • PVC Mount: mounts the test-pvc-opennebula volume at /data in each container.
  • Pod Affinity: ensures both Pods run on the same node so the ReadWriteOnce PVC can be shared.
  • Container Command: appends each Pod’s hostname to /data/example and keeps the container running with sleep infinity.

Apply the Deployment using:

kubectl apply -f deployment.yaml

Step 3: Verify PVC and Deployment

First, verify that the PVC has been bound:

$ kubectl get pvc
NAMESPACE   NAME                  STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS    VOLUMEATTRIBUTESCLASS   AGE
default     test-pvc-opennebula   Bound    pvc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx   1Gi        RWO            opennebula-fs   <unset>                 8s

Next, check that the Deployment pods are running:

$ kubectl get deployment
NAME              READY   UP-TO-DATE   AVAILABLE   AGE
test-deployment   2/2     2            2           29s

Verify that the volume is mounted correctly inside the pods:

$ kubectl exec -it deploy/test-deployment -- df -h /data
Filesystem                Size      Used Available Use% Mounted on
/dev/sda                973.4M     28.0K    906.2M   0% /data

Check that the pod writes data to the PVC correctly:

$ kubectl exec -it deploy/test-deployment -- cat /data/example
test-deployment-774cf96f74-rp7h4
test-deployment-774cf96f74-mfgnj

This confirms that the PVC is functioning as expected and the storage is available to the container.

Clone this wiki locally