Files
my-rook-config/Documentation/ceph-filesystem.md
T

249 lines
8.3 KiB
Markdown
Raw Normal View History

---
2019-10-24 10:22:08 +02:00
title: Shared Filesystem
2019-02-04 09:46:00 -08:00
weight: 2300
indent: true
---
{% include_relative branch.liquid %}
2018-12-03 23:48:40 -07:00
2019-10-24 10:22:08 +02:00
# Shared Filesystem
2017-04-14 17:09:18 -07:00
2019-10-24 10:22:08 +02:00
A shared filesystem can be mounted with read/write permission from multiple pods. This may be useful for applications which can be clustered using a shared filesystem.
2017-04-14 17:09:18 -07:00
This example runs a shared filesystem for the [kube-registry](https://github.com/kubernetes/kubernetes/tree/release-1.9/cluster/addons/registry).
2017-04-14 17:09:18 -07:00
2019-10-24 10:22:08 +02:00
## Prerequisites
2017-04-14 17:09:18 -07:00
This guide assumes you have created a Rook cluster as explained in the main [Kubernetes guide](quickstart.md)
2017-04-14 17:09:18 -07:00
2021-03-02 16:09:38 +01:00
### Multiple Filesystems Support
2021-03-02 16:09:38 +01:00
Multiple filesystems are supported as of the Ceph Pacific release.
2019-10-24 10:22:08 +02:00
## Create the Filesystem
2019-10-24 10:22:08 +02:00
Create the filesystem by specifying the desired settings for the metadata pool, data pools, and metadata server in the `CephFilesystem` CRD. In this example we create the metadata pool with replication of three and a single data pool with replication of three. For more options, see the documentation on [creating shared filesystems](ceph-filesystem-crd.md).
2017-10-05 10:00:19 -07:00
2019-10-24 10:22:08 +02:00
Save this shared filesystem definition as `filesystem.yaml`:
2017-10-05 10:00:19 -07:00
```yaml
apiVersion: ceph.rook.io/v1
2018-12-03 23:48:40 -07:00
kind: CephFilesystem
2017-10-05 10:00:19 -07:00
metadata:
name: myfs
namespace: rook-ceph
2017-10-05 10:00:19 -07:00
spec:
metadataPool:
replicated:
size: 3
dataPools:
2018-08-16 11:36:21 +02:00
- replicated:
size: 3
preserveFilesystemOnDelete: true
2017-10-05 10:00:19 -07:00
metadataServer:
activeCount: 1
activeStandby: true
```
The Rook operator will create all the pools and other resources necessary to start the service. This may take a minute to complete.
2017-10-05 10:00:19 -07:00
2019-10-24 10:22:08 +02:00
```console
# Create the filesystem
kubectl create -f filesystem.yaml
2019-10-24 10:22:08 +02:00
[...]
2017-10-05 10:00:19 -07:00
```
```console
# To confirm the filesystem is configured, wait for the mds pods to start
kubectl -n rook-ceph get pod -l app=rook-ceph-mds
```
>```
>NAME READY STATUS RESTARTS AGE
>rook-ceph-mds-myfs-7d59fdfcf4-h8kw9 1/1 Running 0 12s
>rook-ceph-mds-myfs-7d59fdfcf4-kgkjp 1/1 Running 0 12s
>```
2019-10-24 10:22:08 +02:00
To see detailed status of the filesystem, start and connect to the [Rook toolbox](ceph-toolbox.md). A new line will be shown with `ceph status` for the `mds` service. In this example, there is one active instance of MDS which is up, with one MDS instance in `standby-replay` mode in case of failover.
2019-10-24 10:22:08 +02:00
```console
ceph status
2017-04-14 17:09:18 -07:00
```
>```
> ...
> services:
> mds: myfs-1/1/1 up {[myfs:0]=mzw58b=up:active}, 1 up:standby-replay
>```
2017-04-14 17:09:18 -07:00
2019-08-01 16:31:50 -06:00
## Provision Storage
Before Rook can start provisioning storage, a StorageClass needs to be created based on the filesystem. This is needed for Kubernetes to interoperate
with the CSI driver to create persistent volumes.
Save this storage class definition as `storageclass.yaml`:
```yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
2020-01-31 11:43:10 +01:00
name: rook-cephfs
# Change "rook-ceph" provisioner prefix to match the operator namespace if needed
provisioner: rook-ceph.cephfs.csi.ceph.com
2019-08-01 16:31:50 -06:00
parameters:
# clusterID is the namespace where the rook cluster is running
# If you change this namespace, also change the namespace below where the secret namespaces are defined
2019-08-01 16:31:50 -06:00
clusterID: rook-ceph
# CephFS filesystem name into which the volume shall be created
fsName: myfs
# Ceph pool into which the volume shall be created
# Required for provisionVolume: "true"
pool: myfs-data0
# The secrets contain Ceph admin credentials. These are generated automatically by the operator
# in the same namespace as the cluster.
2019-10-11 12:41:37 +02:00
csi.storage.k8s.io/provisioner-secret-name: rook-csi-cephfs-provisioner
2019-08-01 16:31:50 -06:00
csi.storage.k8s.io/provisioner-secret-namespace: rook-ceph
csi.storage.k8s.io/controller-expand-secret-name: rook-csi-cephfs-provisioner
csi.storage.k8s.io/controller-expand-secret-namespace: rook-ceph
2019-10-11 12:41:37 +02:00
csi.storage.k8s.io/node-stage-secret-name: rook-csi-cephfs-node
2019-08-01 16:31:50 -06:00
csi.storage.k8s.io/node-stage-secret-namespace: rook-ceph
reclaimPolicy: Delete
```
If you've deployed the Rook operator in a namespace other than "rook-ceph"
as is common change the prefix in the provisioner to match the namespace
you used. For example, if the Rook operator is running in "rook-op" the
provisioner value should be "rook-op.rbd.csi.ceph.com".
2019-08-01 16:31:50 -06:00
Create the storage class.
2019-10-24 10:22:08 +02:00
```console
2021-09-22 10:37:07 +02:00
kubectl create -f deploy/examples/csi/cephfs/storageclass.yaml
2019-08-01 16:31:50 -06:00
```
## Quotas
> **IMPORTANT**: The CephFS CSI driver uses quotas to enforce the PVC size requested.
Only newer kernels support CephFS quotas (kernel version of at least 4.17).
If you require quotas to be enforced and the kernel driver does not support it, you can disable the kernel driver
and use the FUSE client. This can be done by setting `CSI_FORCE_CEPHFS_KERNEL_CLIENT: false`
in the operator deployment (`operator.yaml`). However, it is important to know that when
the FUSE client is enabled, there is an issue that during upgrade the application pods will be
disconnected from the mount and will need to be restarted. See the [upgrade guide](ceph-upgrade.md)
for more details.
2019-10-24 10:22:08 +02:00
## Consume the Shared Filesystem: K8s Registry Sample
2017-10-05 10:00:19 -07:00
2019-10-24 10:22:08 +02:00
As an example, we will start the kube-registry pod with the shared filesystem as the backing store.
2017-08-08 14:03:04 -07:00
Save the following spec as `kube-registry.yaml`:
2017-08-08 14:03:04 -07:00
```yaml
2019-08-01 16:31:50 -06:00
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: cephfs-pvc
namespace: kube-system
2019-08-01 16:31:50 -06:00
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
2020-01-31 11:43:10 +01:00
storageClassName: rook-cephfs
2019-08-01 16:31:50 -06:00
---
apiVersion: apps/v1
kind: Deployment
2017-08-08 14:03:04 -07:00
metadata:
name: kube-registry
2017-08-08 14:03:04 -07:00
namespace: kube-system
labels:
k8s-app: kube-registry
kubernetes.io/cluster-service: "true"
spec:
replicas: 3
selector:
matchLabels:
k8s-app: kube-registry
2017-08-08 14:03:04 -07:00
template:
metadata:
labels:
k8s-app: kube-registry
kubernetes.io/cluster-service: "true"
spec:
containers:
- name: registry
image: registry:2
2018-12-26 20:23:15 +01:00
imagePullPolicy: Always
2017-08-08 14:03:04 -07:00
resources:
limits:
cpu: 100m
memory: 100Mi
env:
2018-12-26 20:23:15 +01:00
# Configuration reference: https://docs.docker.com/registry/configuration/
2017-08-08 14:03:04 -07:00
- name: REGISTRY_HTTP_ADDR
value: :5000
2018-12-26 20:23:15 +01:00
- name: REGISTRY_HTTP_SECRET
value: "Ple4seCh4ngeThisN0tAVerySecretV4lue"
2017-08-08 14:03:04 -07:00
- name: REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY
value: /var/lib/registry
volumeMounts:
- name: image-store
mountPath: /var/lib/registry
ports:
- containerPort: 5000
name: registry
protocol: TCP
2018-12-26 20:23:15 +01:00
livenessProbe:
httpGet:
path: /
port: registry
readinessProbe:
httpGet:
path: /
port: registry
2017-08-08 14:03:04 -07:00
volumes:
- name: image-store
2019-08-01 16:31:50 -06:00
persistentVolumeClaim:
claimName: cephfs-pvc
readOnly: false
2017-04-14 17:09:18 -07:00
```
2019-08-01 16:31:50 -06:00
Create the Kube registry deployment:
2019-10-24 10:22:08 +02:00
```console
2021-09-22 10:37:07 +02:00
kubectl create -f deploy/examples/csi/cephfs/kube-registry.yaml
2019-08-01 16:31:50 -06:00
```
You now have a docker registry which is HA with persistent storage.
2017-04-14 17:09:18 -07:00
2019-10-24 10:22:08 +02:00
### Kernel Version Requirement
If the Rook cluster has more than one filesystem and the application pod is scheduled to a node with kernel version older than 4.7, inconsistent results may arise since kernels older than 4.7 do not support specifying filesystem namespaces.
2019-10-24 10:22:08 +02:00
## Consume the Shared Filesystem: Toolbox
2017-04-14 17:09:18 -07:00
2019-10-24 10:22:08 +02:00
Once you have pushed an image to the registry (see the [instructions](https://github.com/kubernetes/kubernetes/tree/release-1.9/cluster/addons/registry) to expose and use the kube-registry), verify that kube-registry is using the filesystem that was configured above by mounting the shared filesystem in the toolbox pod. See the [Direct Filesystem](direct-tools.md#shared-filesystem-tools) topic for more details.
2017-04-14 17:09:18 -07:00
## Teardown
2019-10-24 10:22:08 +02:00
To clean up all the artifacts created by the filesystem demo:
```console
2017-04-14 17:09:18 -07:00
kubectl delete -f kube-registry.yaml
```
2019-10-24 10:22:08 +02:00
To delete the filesystem components and backing data, delete the Filesystem CRD.
> **WARNING: Data will be deleted if preserveFilesystemOnDelete=false**.
2019-10-24 10:22:08 +02:00
```console
2018-12-03 23:48:40 -07:00
kubectl -n rook-ceph delete cephfilesystem myfs
```
2019-08-01 16:31:50 -06:00
Note: If the "preserveFilesystemOnDelete" filesystem attribute is set to true, the above command won't delete the filesystem. Recreating the same CRD will reuse the existing filesystem.
2018-08-16 11:36:21 +02:00
### Advanced Example: Erasure Coded Filesystem
2019-10-24 10:22:08 +02:00
The Ceph filesystem example can be found here: [Ceph Shared Filesystem - Samples - Erasure Coded](ceph-filesystem-crd.md#erasure-coded).