2018-03-16 08:32:12 -07:00
---
title : Direct Tools
2019-02-04 09:46:00 -08:00
weight : 11200
2018-03-16 08:32:12 -07:00
indent : true
---
# Direct Tools
2018-04-01 18:31:47 +02:00
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
2018-03-16 08:32:12 -07:00
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.
2019-12-03 03:48:29 +05:30
## Start the Direct Mount Pod
To test mounting your Ceph volumes, start a pod with the necessary mounts. An example is provided in the examples test directory:
```console
2021-09-22 10:37:07 +02:00
kubectl create -f deploy/examples/direct-mount.yaml
2019-12-03 03:48:29 +05:30
```
After the pod is started, connect to it like this:
```console
kubectl -n rook-ceph get pod -l app=rook-direct-mount
2021-02-18 18:24:22 +05:30
$ kubectl -n rook-ceph exec -it <pod> bash
2019-12-03 03:48:29 +05:30
```
2018-03-16 08:32:12 -07:00
## Block Storage Tools
2018-12-08 08:07:03 -07:00
After you have created a pool as described in the [Block Storage ](ceph-block.md ) topic, you can create a block image and mount it directly in a pod.
2019-12-03 03:48:29 +05:30
This example will show how the Ceph rbd volume can be mounted in the direct mount pod.
2018-03-16 08:32:12 -07:00
2019-12-03 03:48:29 +05:30
Create the [Direct Mount Pod ](direct-tools.md#Start-the-Direct-Mount-Pod ).
2018-03-16 08:32:12 -07:00
Create a volume image (10MB):
2019-10-25 09:25:07 +02:00
```console
2018-03-16 08:32:12 -07:00
rbd create replicapool/test --size 10
rbd info replicapool/test
# Disable the rbd features that are not in the kernel module
rbd feature disable replicapool/test fast-diff deep-flatten object-map
```
Map the block volume and format it and mount it:
2019-10-25 09:25:07 +02:00
```console
2019-12-03 03:48:29 +05:30
# Map the rbd device. If the Direct Mount Pod was started with "hostNetwork: false" this hangs and you have to stop it with Ctrl-C,
2018-08-14 22:01:31 +03:00
# however the command still succeeds; see https://github.com/rook/rook/issues/2021
2018-03-16 08:32:12 -07:00
rbd map replicapool/test
# Find the device name, such as rbd0
lsblk | grep rbd
# Format the volume ( only do this the first time or you will lose data)
mkfs.ext4 -m0 /dev/rbd0
# Mount the block device
mkdir /tmp/rook-volume
mount /dev/rbd0 /tmp/rook-volume
```
Write and read a file:
2019-10-25 09:25:07 +02:00
```console
2018-07-13 14:29:57 -06:00
echo "Hello Rook" > /tmp/rook-volume/hello
2018-03-16 08:32:12 -07:00
cat /tmp/rook-volume/hello
```
### Unmount the Block device
Unmount the volume and unmap the kernel device:
2019-10-25 09:25:07 +02:00
```console
2018-03-16 08:32:12 -07:00
umount /tmp/rook-volume
rbd unmap /dev/rbd0
```
## Shared Filesystem Tools
2019-10-25 09:25:07 +02:00
After you have created a filesystem as described in the [Shared Filesystem ](ceph-filesystem.md ) topic, you can mount the filesystem from multiple pods.
2019-12-03 03:48:29 +05:30
The the other topic you may have mounted the filesystem already in the registry pod. Now we will mount the same filesystem in the Direct Mount pod.
2019-10-25 09:25:07 +02:00
This is just a simple way to validate the Ceph filesystem and is not recommended for production Kubernetes pods.
2018-03-16 08:32:12 -07:00
2019-12-03 03:48:29 +05:30
Follow [Direct Mount Pod ](direct-tools.md#Start-the-Direct-Mount-Pod ) to start a pod with the necessary mounts and then proceed with the following commands after connecting to the pod.
2018-03-16 08:32:12 -07:00
2019-10-25 09:25:07 +02:00
```console
2018-03-16 08:32:12 -07:00
# Create the directory
mkdir /tmp/registry
# Detect the mon endpoints and the user secret for the connection
mon_endpoints=$(grep mon_host /etc/ceph/ceph.conf | awk '{print $3}')
my_secret=$(grep key /etc/ceph/keyring | awk '{print $3}')
2019-10-25 09:25:07 +02:00
# Mount the filesystem
2018-03-16 08:32:12 -07:00
mount -t ceph -o mds_namespace=myfs,name=admin,secret=$my_secret $mon_endpoints:/ /tmp/registry
2019-10-25 09:25:07 +02:00
# See your mounted filesystem
2018-03-16 08:32:12 -07:00
df -h
```
2019-10-25 09:25:07 +02:00
Now you should have a mounted filesystem. If you have pushed images to the registry you will see a directory called `docker` .
```console
2018-03-16 08:32:12 -07:00
ls /tmp/registry
```
2019-10-25 09:25:07 +02:00
Try writing and reading a file to the shared filesystem.
2018-03-16 08:32:12 -07:00
2019-10-25 09:25:07 +02:00
```console
2018-07-13 14:29:57 -06:00
echo "Hello Rook" > /tmp/registry/hello
2018-03-16 08:32:12 -07:00
cat /tmp/registry/hello
# delete the file when you' re done
rm -f /tmp/registry/hello
```
### Unmount the Filesystem
2019-12-03 03:48:29 +05:30
To unmount the shared filesystem from the Direct Mount Pod:
2019-10-25 09:25:07 +02:00
```console
2018-03-16 08:32:12 -07:00
umount /tmp/registry
rmdir /tmp/registry
```
2019-10-25 09:25:07 +02:00
No data will be deleted by unmounting the filesystem.