Skip to content

Volumes ​

General Information ​

KS provides zone-bound storage out-of-the box, similar to AWS EBS. Persistent volumes are provisioned dynamically via the KubeVirt CSI driver.

Additionally:

💡 Client Identifying Data (CID)

To enable support for Client Identifying Data (CID), set the following label on your PersistentVolumes (PVs) and PersistentVolumeClaims (PVCs):

cid_enabled: true

This label indicates that the volume may store CID-relevant data and can be used by automation or policy controllers to enforce specific handling, auditing, or isolation requirements.

Volume Modes ​

Kubernetes Service supports the following volume mode:

  • Filesystem: Mounts the volume as a file system inside the pod container (default).
  • Block: Exposes the raw block device directly to the container.

Storage Classes ​

The following StorageClasses are available within Kubernetes Service:

StorageClassDescription
kubevirt-san-kcsi-standard (default)Default storage class, zone-agnostic.
WaitForFirstConsumer
kubevirt-san-kcsi-standard-zhhZone-specific provisioning for zone zhh.
Immediate
kubevirt-san-kcsi-standard-oltZone-specific provisioning for zone olt.
Immediate
kubevirt-san-kcsi-standard-zoiZone-specific provisioning for zone zoi.
Immediate
kubevirt-san-kcsi-standard-bewZone-specific provisioning for zone bew.
Immediate

💡 Note

If you use the default StorageClass the volume is bound to the zone where the PVC was claimed first and can not be moved afterwards.

💡 ReadWriteMany storage

All the kubevirt-* StorageClasses only support ReadWriteOnce accessModes. If you require ReadWriteMany support, use the ESC File Service Kubernetes.

Replicated storage class ​

In addition to the zone-bound StorageClasses, Kubernetes Service also provides an optional multi-zone replicated StorageClass: kubevirt-san-kcsi-replicated.

This replicated class synchronously mirrors data across the two zones bew and zoi, providing enhanced availability and resilience against zone-level failures. While it is mountable from all three zones in the Region Central the performance is better from bew and zoi compared to olt.

💡 Note

This storage class is only available in the Region Central.

To enable it for your environment, you must create a service request via the Swisscom Service Portal.

Custom Storage Classes ​

You can install any additional CSI into your clusters as needed. However, make sure to not create any new storage classes for the csi.kubevirt.io provisioner.

🚨 csi.kubevirt.io Provisioner - WARNING 🚨

Do not create any storage classes on your own with the csi.kubevirt.io provisioner, or modify any of the existing storage classes in your clusters. This action is not supported and will lead to undefined and unpredictable behaviour in volumes that use such storage classes.

Swisscom does not provide any support or SLA for volumes provisioned with such a storage class!

Data loss is possible! 💣️💥

Volume Binding Modes ​

WaitForFirstConsumer

  • Volumes are created only when a pod is scheduled.
  • This ensures volume provisioning is aligned with pod scheduling in the correct zone.
  • Reduces the chance of scheduling failures in multi-zone clusters.

Immediate

  • Volumes are created as soon as the PVC is created, regardless of pod scheduling.
  • ⚠️ This may lead to scheduling errors if a pod is scheduled on a different zone or node.

Online volume expansion ​

To enable online volume expansion, it is necessary to patch the csidriver in your user-cluster.

Set the requireRepublish: true attribute on the csi.kubevirt.io csidriver in your user-cluster.

bash
kubectl patch csidriver csi.kubevirt.io --type merge -p '{"spec":{"requiresRepublish":true}}'

Scheduling Pods with PVCs ​

Using WaitForFirstConsumer

  • No special node selectors are required.
  • The scheduler will delay provisioning the volume until it selects a node for the pod.

Using Immediate

  • The volume is immediately bound and provisioned.
  • The choice of zone for the PV is explicitely decided by the user.
  • The user must ensure that the pod is scheduled to the same zone as the volume.

Example using a nodeSelector to ensure zone alignment:

yaml
spec:
  nodeSelector:
    topology.kubernetes.io/zone: olt

⚠️ Zone affinity - Pods and PVs

If you use one of the zone-specific StorageClasses for a PV you must ensure the pods using said PV are being scheduled on the same zone by using a nodeSelector. Otherwise the K8s scheduler of your cluster might not place the pod in the same zone as the PV and it will be stuck forever!

Filesystem-Mode: Create a PersistentVolumeClaim (PVC) ​

Option 1: Zone agnostic ​

A basic example of a PVC requesting 1Gi of storage. This uses the default storage class (WaitForFirstConsumer) and lets the scheduler pick the node automatically.

yaml
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: test-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: kubevirt-san-kcsi-standard

And here a basic deployment using the previously created pvc and mounts it to /data:

yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: pvc-test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: pvc-test
  template:
    metadata:
      labels:
        app: pvc-test
    spec:
      containers:
        - name: busybox
          image: busybox
          command:
            - sh
            - -c
            - |
              echo "Run started at $(date)" >> /data/log.txt
              echo "Contents so far:"
              cat /data/log.txt
              echo "Pod will now idle..."
              tail -f /dev/null
          volumeMounts:
            - mountPath: /data
              name: storage
      volumes:
        - name: storage
          persistentVolumeClaim:
            claimName: test-pvc

Option 2: Zone-bound PVC + Zone-specific Pod Deployment Example ​

In this example we assume the following:

  • Zone = zhh
  • StorageClass = kubevirt-san-kcsi-standard-zhh
  • Node label for zone = topology.kubernetes.io/zone=zhh

Manifest example for pvc-zhh.yaml:

yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: test-pvc-zhh
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: kubevirt-san-kcsi-standard-zhh

Manifest example for deployment-zhh.yaml:

yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: pvc-test-zhh
spec:
  replicas: 1
  selector:
    matchLabels:
      app: pvc-test-zhh
  template:
    metadata:
      labels:
        app: pvc-test-zhh
    spec:
      nodeSelector:
        topology.kubernetes.io/zone: zhh
      containers:
        - name: busybox
          image: busybox
          command:
            - sh
            - -c
            - |
              echo "Zone-aware run on $(hostname) at $(date)" >> /data/log.txt
              echo "Contents of the volume so far:"
              cat /data/log.txt
              echo "Pod is now idle..."
              tail -f /dev/null
          volumeMounts:
            - mountPath: /data
              name: storage
      volumes:
        - name: storage
          persistentVolumeClaim:
            claimName: test-pvc-zhh

How to test ​

Apply it:

bash
kubectl apply -f pvc-zhh.yaml
kubectl apply -f deploy-zhh.yaml

Wait for the pod to schedule. If it's stuck, run:

bash
kubectl describe pod -l app=pvc-test-zhh

Verify Correct Zone Placement Get pod and node info:

bash
kubectl get pods -o wide
kubectl get node --show-labels | grep zhh

You should see the pod scheduled on a node in the zhh zone, and PVC bound.

Block-Mode: Create a PersistentVolumeClaim (PVC) ​

Option 1: Zone agnostic ​

💡 Note

No hard zone constraints → volume is provisioned in the same zone as the first pod that consumes it.

What does this mean for block volumes? ​

If you're creating a volumeMode: Block PVC with this zone-agnostic class:
✅ CSI will defer scheduling of the volume until the consuming Pod is scheduled.
✅ The volume will be created in the same zone as the Pod's Node (to satisfy topology).

In the example below, the following steps will be executed:

  • The Pod mounts the block device provided by the PVC at /dev/blockdev.
  • It checks if the device is already formatted with a filesystem.
  • If not formatted, it formats the device as ext4.
  • The device is mounted at /mnt/volume.
  • A test file is written to confirm successful mount and write access.
  • The container runs indefinitely to allow manual inspection or further use.
  • Example of zone-agnostic PVC with volumeMode: Block
yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-block-default
spec:
  accessModes:
    - ReadWriteOnce
  volumeMode: Block
  storageClassName: kubevirt-san-kcsi-standard
  resources:
    requests:
      storage: 1Gi

Example of zone-agnostic Pod:

yaml
apiVersion: v1
kind: Pod
metadata:
  name: debian-block-pod
spec:
  containers:
    - name: debian
      image: debian:bookworm-slim
      securityContext:
        privileged: true
      command: ["/bin/sh", "-c"]
      args:
        - |
          mkdir -p /mnt/volume;
          mount /dev/blockdev /mnt/volume;
          echo "debian + block = PRODUCTION" > /mnt/volume/test.txt;
          sleep infinity;
      readinessProbe:
        exec:
          command: ["/bin/sh", "-c", "test -f /mnt/volume/test.txt"]
        initialDelaySeconds: 5
        periodSeconds: 10
      volumeDevices:
        - name: blockvol
          devicePath: /dev/blockdev
  initContainers:
    - name: init-format-block
      image: debian:bookworm-slim
      securityContext:
        privileged: true
      command: ["/bin/sh", "-c"]
      args:
        - |
          echo "[INIT] Checking if block device needs formatting...";
          if ! blkid /dev/blockdev; then
            echo "[INIT] Formatting /dev/blockdev as ext4...";
            mkfs.ext4 /dev/blockdev;
          else
            echo "[INIT] Already formatted.";
          fi
      volumeDevices:
        - name: blockvol
          devicePath: /dev/blockdev
  volumes:
    - name: blockvol
      persistentVolumeClaim:
        claimName: pvc-block-default

What this example Pod yaml does
Init Container (init-format-block):

  • Checks if the block device is already formatted.
  • If not, formats it as ext4.

💡 Note

Using an init container for formatting the block device ensures the volume is properly prepared before the main application starts, preventing potential race conditions and simplifying container startup logic.

Main Container:

  • Mounts the device at /mnt/volume.
  • Writes a test file.
  • Sleeps indefinitely.

Readiness Probe:

  • Waits until the test file is present before marking the container as "Ready".

How to test ​

  1. Deploy the PVC and Pod:
bash
kubectl apply -f <pvc>
kubectl apply -f <pod>
  1. Check the Pod status:
bash
kubectl get pods <pod>
  1. Exec into the Pod:
bash
kubectl exec -it <pod> -- /bin/sh
  1. Verify the block device and filesystem:
bash
root@debian-block-pod:/# lsblk
blkid /dev/blockdev
mount | grep /mnt/volume
cat /mnt/volume/test.txt
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
loop0     7:0    0 63.7M  1 loop 
loop1     7:1    0 44.4M  1 loop 
loop2     7:2    0 89.4M  1 loop 
loop3     7:3    0    1G  0 loop 
sda       8:0    0    1G  0 disk /mnt/volume
vda     252:0    0  9.3G  0 disk 
|-vda1  252:1    0  9.2G  0 part /etc/resolv.conf
|                                /etc/hostname
|                                /dev/termination-log
|                                /etc/hosts
|-vda14 252:14   0    4M  0 part 
`-vda15 252:15   0  106M  0 part 
vdb     252:16   0    1M  0 disk 
/dev/blockdev: UUID="0707381d-4e37-4080-8ea0-28e0ee01a62e" BLOCK_SIZE="4096" TYPE="ext4"
/dev/blockdev on /mnt/volume type ext4 (rw,relatime)
debian + block = OK
  1. The output of the last command should be:
bash
debian + block = OK

Option 2: Zone-bound PVC + Zone-specific Pod Deployment Example ​

When using zone-bound StorageClass resources, volumes are provisioned immediately in a specific zone. This is useful for:

  • Pre-provisioning volumes for stateful apps.
  • Running workloads in a known failure domain (e.g., for latency reasons).
  • Avoiding topology delays (Immediate binding skips scheduling deferral).

Example pvc-zone.yaml:

yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-block-zone
spec:
  accessModes:
  - ReadWriteOnce
  volumeMode: Block
  storageClassName: kubevirt-san-kcsi-standard-zoi # Bind to zone 'zoi'
  resources:
    requests:
      storage: 1Gi

Example pod-zone.yaml

yaml
apiVersion: v1
kind: Pod
metadata:
  name: debian-block-pod-zoi
spec:
  nodeSelector:
    topology.kubernetes.io/zone: zoi  # Ensures zone match
  containers:
    - name: debian
      image: debian:bookworm-slim
      securityContext:
        privileged: true
      command: ["/bin/sh", "-c"]
      args:
        - |
          mkdir -p /mnt/volume;
          mount /dev/blockdev /mnt/volume;
          echo "zone-bound block = OK" > /mnt/volume/test.txt;
          sleep infinity;
      readinessProbe:
        exec:
          command: ["/bin/sh", "-c", "test -f /mnt/volume/test.txt"]
        initialDelaySeconds: 5
        periodSeconds: 10
      volumeDevices:
        - name: blockvol
          devicePath: /dev/blockdev
  initContainers:
    - name: init-format-block
      image: debian:bookworm-slim
      securityContext:
        privileged: true
      command: ["/bin/sh", "-c"]
      args:
        - |
          echo "[INIT] Checking device...";
          if ! blkid /dev/blockdev; then
            echo "[INIT] Formatting /dev/blockdev as ext4...";
            mkfs.ext4 /dev/blockdev;
          else
            echo "[INIT] Already formatted.";
          fi
      volumeDevices:
        - name: blockvol
          devicePath: /dev/blockdev
  volumes:
    - name: blockvol
      persistentVolumeClaim:
        claimName: pvc-block-zone

Key considerations

TopicDetails
Immediate BindingVolume is provisioned as soon as the PVC is created
nodeSelectorRequired - must match the zone of the PVC
privileged ModeRequired to access and format raw block devices
volumeMode: BlockExposes the raw block device directly to the container

How to test ​

  1. Apply the manifest files:
bash
kubectl apply -f pvc-zone.yaml
kubectl apply -f pod-zone.yaml

kubectl exec -it debian-block-pod-zoi -- cat /mnt/volume/test.txt
  1. Verify - expected output:
bash
zone-bound block = OK

Option 3: StatefulSet with block volumes (per-replica disks) ​

This example demonstrates how to use volumeMode: Block PersistentVolumeClaims with a StatefulSet, provisioning one dedicated block device per replica using the KubeVirt CSI driver.

Why Use Block Volumes in a StatefulSet? ​

  • High-performance raw I/O access (e.g., databases, message queues).
  • Per-replica persistent disks.
  • Full control over formatting and mounting.
  • Combine with zone-specific StorageClasses to colocate replicas.

Key Components ​

  • volumeClaimTemplates define one PVC per replica.
  • Each PVC uses volumeMode: Block.
  • Optional: Use nodeSelector or affinity to match PVC zone.
  • A container mounts the device, formats if needed, and writes test data.

PVC Handling ​

  • When using volumeClaimTemplates in a StatefulSet, you do NOT need to create PersistentVolumeClaims manually.
  • The StatefulSet controller automatically creates one PVC per replica based on the template.
  • Each PVC will be named as: <volumeClaimTemplate-name>-<statefulset-name>-<replica-index>

For example, for the template named block-vol and StatefulSet block-ss, the PVCs created will be:

  • block-vol-block-ss-0
  • block-vol-block-ss-1
    ... and so forth, matching the number of replicas.

These PVCs are dynamically created and bound at Pod creation time, enabling per-replica persistent storage management.

Example of statefulset-block.yaml:

yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: block-ss
spec:
  serviceName: "block-ss"
  replicas: 2
  selector:
    matchLabels:
      app: block-ss
  template:
    metadata:
      labels:
        app: block-ss
    spec:
      nodeSelector:
        topology.kubernetes.io/zone: zoi  # match PVC zone
      initContainers:
        - name: init-format
          image: remote-docker.artifactory.swisscom.com/debian:bookworm-slim
          securityContext:
            privileged: true
          command: ["/bin/sh", "-c"]
          args:
            - |
              echo "[init] Checking block device...";
              if ! blkid /dev/blockdev; then
                echo "[init] Formatting device as ext4...";
                mkfs.ext4 /dev/blockdev;
              fi
          volumeDevices:
            - name: block-vol
              devicePath: /dev/blockdev
      containers:
        - name: debian
          image: remote-docker.artifactory.swisscom.com/debian:bookworm-slim
          securityContext:
            privileged: true
          command: ["/bin/sh", "-c"]
          args:
            - |
              mkdir -p /mnt/volume;
              mount /dev/blockdev /mnt/volume;
              echo "statefulset-block = OK" > /mnt/volume/test.txt;
              sleep infinity;
          volumeDevices:
            - name: block-vol
              devicePath: /dev/blockdev
  volumeClaimTemplates:
    - metadata:
        name: block-vol
      spec:
        accessModes: ["ReadWriteOnce"]
        volumeMode: Block
        storageClassName: kubevirt-san-kcsi-standard-zoi
        resources:
          requests:
            storage: 1Gi

How to test ​

  1. Apply the StatefulSet:
bash
kubectl apply -f statefulset-block.yaml
  1. Wait for the Pods to be ready:
bash
kubectl get pods -l app=block-ss --watch

You should see pods like block-ss-0, block-ss-1, etc., reach Running status.

  1. Check that the PVCs are created and bound:
bash
kubectl get pvc
NAME                   STATUS    VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS                     VOLUMEATTRIBUTESCLASS   AGE
block-vol-block-ss-0   Bound     pvc-1b760435-f4d4-4de2-8368-7f9d13842ba5   1Gi        RWO            kubevirt-san-kcsi-standard-zoi   <unset>                 2m9s
block-vol-block-ss-1   Bound     pvc-e21af548-d8e4-43da-8a31-bab379310ca4   1Gi        RWO            kubevirt-san-kcsi-standard-zoi   <unset>                 99s

Option 4: Pod with topologySpreadConstraints + block volume ​

This example demonstrates how to deploy Pods that use block-mode PersistentVolumeClaims while leveraging Kubernetes’ topologySpreadConstraints to distribute Pods evenly across failure domains (zones or nodes).

Why use topologySpreadConstraints? ​

  • Ensure Pods are spread evenly across zones or nodes.
  • Increase availability by avoiding concentration of Pods in one zone.
  • Works well with zone-bound StorageClasses and block volumes to improve fault tolerance.

Example PVC:

yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-block-spread
spec:
  accessModes:
    - ReadWriteOnce
  volumeMode: Block
  storageClassName: kubevirt-san-kcsi-standard
  resources:
    requests:
      storage: 1Gi

Example Pod Deployment:

yaml
apiVersion: v1
kind: Pod
metadata:
  name: block-pod-spread
  labels:
    app: block-pod-spread
spec:
  containers:
    - name: debian
      image: debian:bookworm-slim
      securityContext:
        privileged: true
      command: ["/bin/sh", "-c"]
      args:
        - |
          echo "[INFO] Checking device...";
          if ! blkid /dev/blockdev; then
            echo "[INFO] Formatting as ext4...";
            mkfs.ext4 /dev/blockdev;
          fi
          mkdir -p /mnt/volume;
          mount /dev/blockdev /mnt/volume;
          echo "topologySpread + block = OK" > /mnt/volume/test.txt;
          sleep infinity;
      volumeDevices:
        - name: blockvol
          devicePath: /dev/blockdev
  volumes:
    - name: blockvol
      persistentVolumeClaim:
        claimName: pvc-block-spread
  topologySpreadConstraints:
    - maxSkew: 1
      topologyKey: topology.kubernetes.io/zone
      whenUnsatisfiable: DoNotSchedule
      labelSelector:
        matchLabels:
          app: block-pod-spread
  nodeSelector:
    # optional, to limit nodes if desired

How it works ​

  • Pod scheduling is constrained to spread Pods across zones by topologySpreadConstraints.
  • Since the PVC uses a zone-agnostic StorageClass with WaitForFirstConsumer, volume provisioning is deferred until Pod scheduling.
  • The volume is created in the same zone as the Pod's node, satisfying topology.
  • The container safely formats and mounts the block device.
  • The Pod writes a test file to verify successful mount and write access.

How to test ​

  1. Apply the manifests:
bash
kubectl apply -f pvc-block-spread.yaml
kubectl apply -f pod-block-spread.yaml
kubectl get pods -l app=block-pod-spread -w
  1. Once the Pod is running, verify the test file:
bash
kubectl exec -it block-pod-spread -- cat /mnt/volume/test.txt
  1. Expected Output:
bash
topologySpread + block = OK

Common Issues and Pitfalls ​

  • Pod cannot be scheduled: May indicate a mismatch between volume zone and pod node.
  • RWX access not working: Only ReadWriteOnce is supported for zone-bound volumes.

Debug steps: ​

  1. Check pod status
bash
kubectl get pods -l app=pvc-test

If the pod status is Pending, it likely means:

  • The PVC hasn't been bound yet, or
  • The PVC is zone-bound and the scheduler can't find a matching node
  1. This will reveal why it's not scheduled:
bash
kubectl describe pod <pod-name>

Look for messages like:

bash
0/3 nodes are available: 3 node(s) didn't match Pod's node affinity

or

bash
persistentvolumeclaim "test-pvc" is not bound
  1. Check the PVC
bash
kubectl get pvc test-pvc
kubectl describe pvc test-pvc

You're looking for:

  • Status: Bound
  • Matching StorageClass
  • No events like failed to provision volume
  1. Check the PV
bash
kubectl get pv
kubectl describe pv <pv-name>

If the volume exists but is in the wrong zone, and you're using the Immediate volume binding mode, this causes a mismatch.

Case 1: StorageClass uses Immediate binding ​

Your kubevirt-san-kcsi-standard is typically set to WaitForFirstConsumer, but if you used a zone-specific StorageClass, it may use Immediate.

In that case:

  • The PV gets created before the pod is scheduled.
  • If the PV is in zone A, but the scheduler tries zone B → no matching node → pod can't schedule.

Fix: Either use a nodeSelector or use kubevirt-san-kcsi-standard (default, with WaitForFirstConsumer).

Case 2: No matching nodes (taints, affinity, etc.) ​

Check if:

  • All nodes are cordoned/unschedulable
  • Taints are applied (and your pod doesn't tolerate them)
bash
kubectl get nodes
kubectl describe node <node-name>

Quick Recovery Tip ​

To confirm it’s a scheduling problem related to PVC binding:

  1. Delete the PVC and Deployment:
bash
kubectl delete deploy pvc-test
kubectl delete pvc test-pvc
  1. Recreate the PVC using kubevirt-san-kcsi-standard (not zone-specific):
yaml
storageClassName: kubevirt-san-kcsi-standard
  1. Reapply the Deployment with no nodeSelector and let the scheduler decide.