How To Mount A Rook CephFs Based PVC In a Kubernetes Environment From Your Host Machine

Caglar Gonul
2 min readDec 19, 2020
Cephfs-Rook-Kubernetes

I think it’s nice to have a ritual before starting a job. Now take a deep breath through your nose and exhale through your mouth. Feel the warmth of the breath coming out of your mouth a few times. If you think you are relaxed, start reading.

You have a Kubernetes cluster. You decided to use Rook with Ceph. You choose a Shared File System for the type of your storage exposed by Rook and you want to mount your PVC to your host machine. You have your reasons. Maybe you need a backup mechanism or maybe you want to access the files from your storage without kubectl cp.

You need three things to mount your PVC to your host machine.

  1. The file system name which will be your mds_namespace.
  2. A secret key for accessing Ceph.
  3. The path of your subvolume which will be the final path of your PVC.

Let’s construct a sh file step by step.

STEP-1 Switch Your Namespace

I will use kubens command to switch between namespaces. So at the end of this command, your namespace will switch into <your_kubernetes_namespace> Kubens is a useful tool. You can find the details from this link: https://github.com/ahmetb/kubectx

STEP-2 Get Mon-Endpoint And The Secret

We first get the rook-ceph-tools pod name into a variable. We use this pod name to get the mon_endpoints and the secret.

STEP-3 Get Sub Volume Path

We get the pvc_<uid> from the pvc definition which is the related pv.

.spec.csi.volumeAttributes.subvolumeName is the name of the subvolume name which we can extract it from PV definition. More information can be found here: https://docs.ceph.com/en/latest/cephfs/fs-volumes/

STEP-4 Mount Sub Volume To The Host

So, in the end, we mount the subvolume to the host machine. Here are the final sh scripts you can use. You should run this sh script with sudo in order to use mount command, since only the root user can use “- -options” option.

You can easily unmount the folder with the following command

sudo umount <your_target_path_of_month>

If everything goes well, you will get an output like this.

Thanks for reading.

Photo by mahdis mousavi on Unsplash

--

--

Caglar Gonul
0 Followers

Java developer by day, DevOps by night, secretly admire JavaScript developers