Binding a PersistentVolumeClaim to a Pod resource

Bind a PersistentVolumeClaim to a Pod resource as a Ceph File Systems (CephFS).

Procedure

  1. Bind the Pod to the PVC file created in Creating a PersistentVolumeClaim (PVC).
    • Bind the Pod with FUSE mounting, similar to the following cephfs-pod-fuse.yaml file.
      kind: Pod
      metadata:
      name: cephfs-pod-fuse
      labels:
      app: cephfs-tester-fuse
      spec:
      containers:
      - name:  cephfs-container-fuse
      image: busybox
      command: ["/bin/sh"]
      args: ["-c", "while true; do echo 'Writing to CephFS'; dd if=/dev/zero of=/mnt/testfile bs=1M count=1024; sleep 10; done"]
      volumeMounts:
      - name: cephfs-volume-fuse
      - mountPath: /mnt/
      volumes:
      - name: cephfs-volume-fuse
      persistentVolumeClaim:
       claimName: cephfs-pvc-fuse
      restartPolicy: Always
      imagePullSecrets:
      - name: dockerhub-secret
    • Bind the Pod with kernel mounting.
      1. If needed, first create a docker secret.
        kubectl create secret docker-registry dockerhub-secret
         --docker-username=USERNAME
         --docker-password=PASSWORD
         --docker-email=EMAIL_ADDRESS
        For example,
        kubectl create secret docker-registry dockerhub-secret
          --docker-username=user01
          --docker-password=mypassword
          --docker-email=your-email@example.com
      2. Create a YAML file, similar to the following cephfs-pod-kernel.yaml file.
        kind: Pod
        metadata:
        name: cephfs-pod-kernel
        labels:
          app: cephfs-tester-kernel
        spec:
        containers:
        - name:  cephfs-container-kernel
          image: busybox
          command: ["/bin/sh"]
          args: ["-c", "while true; do echo 'Writing to CephFS'; dd if=/dev/zero of=/mnt/testfile bs=1M count=1024; sleep 10; done"]
          volumeMounts:
          - name: cephfs-volume-kernel
          - mountPath: /mnt/
        volumes:
        - name: cephfs-volume-kernel
          persistentVolumeClaim:
            claimName: cephfs-pvc-kernel
        restartPolicy: Always
        imagePullSecrets:
          - name: dockerhub-secret
  2. Apply the Pod, by using the kubectl apply command
    kubectl apply -f FILENAME.YAML
    The pod/POD_NAME created message is emitted.

What to do next

Verify that the pods are bound and data is being written to the CephFS volume.
  1. Verify that the pods are bound, by using the kubectl get pods command.
    For example,
    $ kubectl get pods
    NAME                READY   STATUS    RESTARTS   AGE
    cephfs-pod-fuse     1/1     Running   0          5h29m
    cephfs-pod-kernel   1/1     Running   0          4s
  2. Verify that the data is writing to the CephFS volume.
    ceph fs subvolume info
    For example,
    [root@host01 ceph]# ceph fs subvolume info
    cephfs csi-vol-ab1237a9-1fbd-43c1-8b41-0dfd9dc8dee9 csi
    {
       "atime": "2025-01-10 14:05:36",
       "bytes_pcent": "9.49",
       "bytes_quota": 10737418240,
       "bytes_used": 1019084800,
       "created_at": "2025-01-10 14:05:36",
       "ctime": "2025-01-10 14:14:54",
       "data_pool": "cephfs.cephfs.data",
       "earmark": "",
       "features": [
           "snapshot-clone",
           "snapshot-autoprotect",
           "snapshot-retention"
       ],
       "flavor": 2,
       "gid": 0,
       "mode": 16877,
       "mon_addrs": [
           "10.0.67.29:6789",
           "10.0.65.240:6789",
           "10.0.65.252:6789"
       ],
       "mtime": "2025-01-10 14:14:54",
       "path": "/volumes/csi/csi-vol-ab1237a9-1fbd-43c1-8b41-0dfd9dc8dee9/36070c5a-208e-4bc5-94f9-f24fe0afc71a",
       "pool_namespace": "",
       "state": "complete",
       "type": "subvolume",
       "uid": 0
    }