Merge pull request #10758 from rook/mergify/bp/release-1.10/pr-10725

docs: add examples for CephClient CRD use & libcephsqlite (backport #10725)
This commit is contained in:
Travis Nielsen authored and GitHub committed 2022-08-22 22:22:25 -06:00
commit 042377276a
2 files changed
+293 -15

No files matched your search

+115 -15
View File
@@ -5,39 +5,139 @@ title: Client CRD
Rook allows creation and updating clients through the custom resource definitions (CRDs).
For more information about user management and capabilities see the [Ceph docs](https://docs.ceph.com/docs/master/rados/operations/user-management/).
## Use Case
## Use Case: Connecting to Ceph
Use Client CRD in case you want to integrate Rook with applications that are using LibRBD directly.
For example for OpenStack deployment with Ceph backend use Client CRD to create OpenStack services users.
The Client CRD is not needed for Flex or CSI driver users. The drivers create the needed users automatically.
## Creating Ceph User
### Prerequisites
This guide assumes you have created a Rook cluster as explained in the main [Quickstart guide](../Getting-Started/quickstart.md).
### 1. Creating Ceph User
To get you started, here is a simple example of a CRD to configure a Ceph client with capabilities.
```yaml
apiVersion: ceph.rook.io/v1
kind: CephClient
metadata:
name: glance
namespace: rook-ceph
spec:
caps:
mon: 'profile rbd'
osd: 'profile rbd pool=images'
---
apiVersion: ceph.rook.io/v1
kind: CephClient
metadata:
name: cinder
name: example
namespace: rook-ceph
spec:
caps:
mon: 'profile rbd'
mon: 'profile rbd, allow r'
osd: 'profile rbd pool=volumes, profile rbd pool=vms, profile rbd-read-only pool=images'
```
### Prerequisites
To use `CephClient` to connect to a Ceph cluster:
This guide assumes you have created a Rook cluster as explained in the main [Quickstart guide](../Getting-Started/quickstart.md).
### 2. Find the generated secret for the `CephClient`
Once your `CephClient` has been processed by Rook, it will be updated to include your secret:
```console
kubectl -n rook-ceph get cephclient example -o jsonpath='{.status.info.secretName}'
```
### 3. Extract Ceph cluster credentials from the generated secret
Extract Ceph cluster credentials from the generated secret (note that the subkey will be your original client name):
```console
kubectl --namespace rook-ceph get secret rook-ceph-client-example -o jsonpath="{.data.example}" | base64 -d
```
The base64 encoded value that is returned *is* the password for your ceph client.
### 4. Retrieve the mon endpoints
To send writes to the cluster, you must retrieve the mons in use:
```console
kubectl --namespace rook-ceph get configmap rook-ceph-mon-endpoints -o jsonpath='{.data.data}' | sed 's/.=//g'`
```
This command *should* produce a line that looks somewhat like this:
```
10.107.72.122:6789,10.103.244.218:6789,10.99.33.227:6789
```
### 5. (optional) Generate Ceph configuration files
If you choose to generate files for Ceph to use you will need to generate the following files:
- General configuration file (ex. `ceph.conf`)
- Keyring file (ex. `ceph.keyring`)
Examples of the files follow:
`ceph.conf`
```ini
[global]
mon_host=10.107.72.122:6789,10.103.244.218:6789,10.99.33.227:6789
log file = /tmp/ceph-$pid.log
```
`ceph.keyring`
```ini
[client.example]
key = < key, decoded from k8s secret>
# The caps below are for a rbd workload -- you may need to edit/modify these capabilities for other workloads
# see https://docs.ceph.com/en/latest/cephfs/capabilities
caps mon = 'allow r'
caps osd = 'profile rbd pool=<your pool>, profile rb pool=<another pool>'
```
### 6. Connect to the Ceph cluster with your given client ID
With the files we've created, you should be able to query the cluster by setting Ceph ENV variables and running `ceph status`:
```
export CEPH_CONF=/libsqliteceph/ceph.conf;
export CEPH_KEYRING=/libsqliteceph/ceph.keyring;
export CEPH_ARGS=--id example;
ceph status
```
With this config, the ceph tools (`ceph` CLI, in-program access, etc) can connect to and utilize the Ceph cluster.
## Use Case: SQLite
The Ceph project contains a [SQLite VFS][sqlite-vfs] that interacts with RBD directly, called [`libcephsqlite`][libcephsqlite].
First, on your workload ensure that you have the appropriate packages installed that make `libcephsqlite.so` available:
- [`ceph` on Alpine](https://pkgs.alpinelinux.org/package/edge/community/x86_64/ceph)
- [`libsqlite3-mod-ceph` on Ubuntu](https://pkgs.alpinelinux.org/package/edge/community/x86_64/ceph)
- [`libcephsqlite` on Fedora](https://pkgs.org/search/?q=libcephsqlite)
- [`ceph` on CentOS](https://cbs.centos.org/koji/packageinfo?packageID=534)
Without the appropriate package (or a from-scratch build of SQLite), you will be unable to load `libcephsqlite.so`.
After creating a `CephClient` similar to [`deploy/examples/sqlitevfs-client.yaml`](https://github.com/rook/rook/blob/master/deploy/examples/sqlitevfs-client.yaml) and retrieving it's credentials, you may set the following ENV variables:
```console
export CEPH_CONF=/libsqliteceph/ceph.conf;
export CEPH_KEYRING=/libsqliteceph/ceph.keyring;
export CEPH_ARGS=--id sqlitevfs
```
Then start your SQLite database:
```console
sqlite> .load libcephsqlite.so
sqlite> .open file:///poolname:/test.db?vfs=ceph
sqlite>
```
If those lines complete without error, you have successfully set up SQLite to access Ceph.
See [the libcephsqlite documentation][libcephsqlite] for more information on the file URL format.
[libcephsqlite]: https://docs.ceph.com/en/latest/rados/api/libcephsqlite/
[sqlite-vfs]: https://www.sqlite.org/vfs.html
+178
View File
@@ -0,0 +1,178 @@
# CephClient - sqlitevfs
#
# Applying this will prompt Rook to create a similarly named ceph client
---
apiVersion: ceph.rook.io/v1
kind: CephClient
metadata:
name: sqlitevfs
namespace: rook-ceph
spec:
caps:
mon: 'allow r'
osd: 'profile rbd pool=example'
# ServiceAccount - sqlitevfs-setup
#
# This service account will be used to set up workloads that use the sqlitevfs CephClient
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: sqlitevfs-setup
# ClusterRole - sqlitevfs-setup
#
# This ClusterRole will allow the sqlitevfs-setup workload to access credentials during setup
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: sqlitevfs-setup
rules:
- apiGroups: ["ceph.rook.io"]
resources:
- 'cephclients'
verbs:
- 'get'
- apiGroups: [""]
resources:
- 'secrets'
verbs:
- 'get'
resourceNames:
- rook-ceph-client-sqlitevfs
- apiGroups: [""]
resources:
- 'configmaps'
verbs:
- 'get'
resourceNames:
- rook-ceph-mon-endpoints
# ClusterRoleBinding - sqlitevfs-setup
#
# Binds the sqlitevfs-setup ClusteRole
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: sqlitevfs-setup
roleRef:
kind: ClusterRole
name: sqlitevfs-setup
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: sqlitevfs-setup
apiGroup: ""
# Deployment - sqlitevfs
#
# A deployment that uses libcephsqlite (https://docs.ceph.com/en/latest/rados/api/libcephsqlite/)
# via a pre-created ceph client (via the CephClient CRD).
#
# This deployment performs lengthy setup via it's init container to prepare credentials for use
# credentials are stored on an ephemeral in-memory emptyDir volume between the initContainer and the workload
#
# Once the deployment is running, you may `kubectl exec` into the container and use sqlite like so:
#
# ```
# export CEPH_CONF=/libsqliteceph/ceph.conf;
# export CEPH_KEYRING=/libsqliteceph/ceph.keyring;
# export CEPH_ARGS="--id sqlitevfs";
# sqlite3
# ```
#
# Once in the SQLite console:
# sqlite> .load libcephsqlite.so
# sqlite> .open file:///yourpoolname:/sqlitevfs.db?vfs=ceph
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: sqlitevfs
spec:
replicas: 1
selector:
matchLabels:
app: sqlitevfs
component: app
template:
metadata:
labels:
app: sqlitevfs
component: app
spec:
serviceAccountName: sqlitevfs-setup
initContainers:
## Setup Ceph SQLite VFS
- name: setup
image: bitnami/kubectl:1.21.11
command:
- /bin/bash
- -c
- |
# Wait until sqlitevfs cephclient is ready
SECRET_NAME=`kubectl get cephclient ${CEPH_CLIENT_NAME} -o jsonpath='{.status.info.secretName}' -n ${CEPH_NS}`
while [ -z "${SECRET_NAME}" ]; do
sleep 3;
echo -e "[info] checking for cephclient [${CEPH_CLIENT_NAME}]...";
SECRET_NAME=`kubectl get cephclient ${CEPH_CLIENT_NAME} -o jsonpath='{.status.info.secretName}' -n ${CEPH_NS}`;
done;
echo -e "[info] found ceph client secret [${SECRET_NAME}] in namespace [${CEPH_NS}], extracting content...";
SECRET_CONTENT=`kubectl get secret ${SECRET_NAME} -o jsonpath="{.data.${CEPH_CLIENT_NAME}}" -n ${CEPH_NS} | base64 -d`;
echo -e "[info] writing ceph keyring...";
echo -e "[client.${CEPH_CLIENT_NAME}]" > /libsqliteceph/ceph.keyring;
echo -e " key = ${SECRET_CONTENT}" >> /libsqliteceph/ceph.keyring;
echo -e " caps mon = 'allow r'" >> /libsqliteceph/ceph.keyring;
echo -e " caps osd = 'profile rbd pool=raid1, profile rbd pool=rook-raid-1-3n-host'" >> /libsqliteceph/ceph.keyring;
echo -e "retrieving mon endpoints...";
MON_ENDPOINTS=`kubectl get configmap rook-ceph-mon-endpoints -o jsonpath='{.data.data}' -n ${CEPH_NS} | sed 's/.=//g'`;
echo -e "[info] writing out ceph.conf...";
echo -e "[global]" > /libsqliteceph/ceph.conf;
echo -e "mon_host=${MON_ENDPOINTS}" >> /libsqliteceph/ceph.conf;
echo -e "[info] writing ceph args...";
echo -e "--id ${CEPH_CLIENT_NAME}" > /libsqliteceph/ceph.args
echo -e "[info] successfully set up temporary libsqliteceph credentials!";
env:
- name: CEPH_CLIENT_NAME
value: sqlitevfs
- name: CEPH_NS
value: rook-ceph
volumeMounts:
- name: libsqliteceph-config
mountPath: /libsqliteceph
containers:
- name: sqlitevfs
image: alpine:3.16.2
command:
- /bin/ash
- -c
- |
apk add ceph vim sqlite;
export CEPH_CONF=/libsqliteceph/ceph.conf;
export CEPH_KEYRING=/libsqliteceph/ceph.keyring;
export CEPH_ARGS="--id sqlitevfs";
# Sleep forever (kubectl exec in to test!)
sleep infinity;
volumeMounts:
- name: libsqliteceph-config
mountPath: /libsqliteceph
volumes:
- name: libsqliteceph-config
emptyDir:
medium: Memory