Direct Tools

Rook is designed with Kubernetes design principles from the ground up. This topic is going to escape the bounds of Kubernetes storage and show you how to use block and file storage directly from a pod without any of the Kubernetes magic. The purpose of this topic is to help you quickly test a new configuration, although it is not meant to be used in production. All of the benefits of Kubernetes storage including failover, detach, and attach will not be available. If your pod dies, your mount will die with it.

Block Storage Tools

After you have created a pool as described in the Block Storage topic, you can create a block image and mount it directly in a pod. This example will show how the Ceph rbd volume can be mounted in the toolbox pod.

After you have started and connected to the Rook toolbox, proceed with the following commands in the toolbox.

Create a volume image (10MB):

  1. rbd create replicapool/test --size 10
  2. rbd info replicapool/test
  3. # Disable the rbd features that are not in the kernel module
  4. rbd feature disable replicapool/test fast-diff deep-flatten object-map

Map the block volume and format it and mount it:

  1. # Map the rbd device. If the toolbox was started with "hostNetwork: false" this hangs and you have to stop it with Ctrl-C,
  2. # however the command still succeeds; see https://github.com/rook/rook/issues/2021
  3. rbd map replicapool/test
  4. # Find the device name, such as rbd0
  5. lsblk | grep rbd
  6. # Format the volume (only do this the first time or you will lose data)
  7. mkfs.ext4 -m0 /dev/rbd0
  8. # Mount the block device
  9. mkdir /tmp/rook-volume
  10. mount /dev/rbd0 /tmp/rook-volume

Write and read a file:

  1. echo "Hello Rook" > /tmp/rook-volume/hello
  2. cat /tmp/rook-volume/hello

Unmount the Block device

Unmount the volume and unmap the kernel device:

  1. umount /tmp/rook-volume
  2. rbd unmap /dev/rbd0

Shared Filesystem Tools

After you have created a file system as described in the Shared Filesystem topic, you can mount the filesystem from multiple pods. The the other topic you may have mounted the filesystem already in the registry pod. Now we will mount the same file system in the toolbox pod. This is just a simple way to validate the Ceph file system and is not recommended for production Kubernetes pods.

After you have started and connected to the Rook toolbox, proceed with the following commands in the toolbox.

  1. # Create the directory
  2. mkdir /tmp/registry
  3. # Detect the mon endpoints and the user secret for the connection
  4. mon_endpoints=$(grep mon_host /etc/ceph/ceph.conf | awk '{print $3}')
  5. my_secret=$(grep key /etc/ceph/keyring | awk '{print $3}')
  6. # Mount the file system
  7. mount -t ceph -o mds_namespace=myfs,name=admin,secret=$my_secret $mon_endpoints:/ /tmp/registry
  8. # See your mounted file system
  9. df -h

Now you should have a mounted file system. If you have pushed images to the registry you will see a directory called docker.

  1. ls /tmp/registry

Try writing and reading a file to the shared file system.

  1. echo "Hello Rook" > /tmp/registry/hello
  2. cat /tmp/registry/hello
  3. # delete the file when you're done
  4. rm -f /tmp/registry/hello

Unmount the Filesystem

To unmount the shared file system from the toolbox pod:

  1. umount /tmp/registry
  2. rmdir /tmp/registry

No data will be deleted by unmounting the file system.