Skip to content

Commit

Permalink
add addons cubefs_v3.2 (fluid-cloudnative#2778)
Browse files Browse the repository at this point in the history
* add addons cubefs_v3.2

Signed-off-by: wangshulin <wangshulin@smail.nju.edu.cn>

* add version for runtime profile name

Signed-off-by: wangshulin <wangshulin@smail.nju.edu.cn>

---------

Signed-off-by: wangshulin <wangshulin@smail.nju.edu.cn>
  • Loading branch information
wangshli authored Mar 25, 2023
1 parent 9627258 commit d396e9d
Show file tree
Hide file tree
Showing 15 changed files with 774 additions and 11 deletions.
4 changes: 2 additions & 2 deletions addons/cubefs/v2.4/dev-guide/cubefs-v2.4-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ $ cat <<EOF > cubefs-profile.yaml
apiVersion: data.fluid.io/v1alpha1
kind: ThinRuntimeProfile
metadata:
name: cubefs-profile
name: cubefs2.4
spec:
fileSystemType: cubefs
fuse:
Expand Down Expand Up @@ -157,7 +157,7 @@ kind: ThinRuntime
metadata:
name: cubefs-test
spec:
profileName: cubefs
profileName: cubefs2.4
EOF

$ kubectl apply -f dataset.yaml
Expand Down
6 changes: 3 additions & 3 deletions addons/cubefs/v2.4/dev-guide/cubefs-v2.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ The shell script creates the mounted folder and mounts the remote file system to
Package parameter resolution scripts, mount scripts, and related libraries into the image.

```dockerfile
FROM chubaofs/cfs-client:v2.4.0
FROM chubaofs/cfs-client:2.4.0
ADD fluid_config_init.py /
```

Expand All @@ -122,7 +122,7 @@ $ cat <<EOF > cubefs-profile.yaml
apiVersion: data.fluid.io/v1alpha1
kind: ThinRuntimeProfile
metadata:
name: cubefs-profile
name: cubefs2.4
spec:
fileSystemType: cubefs
fuse:
Expand Down Expand Up @@ -156,7 +156,7 @@ kind: ThinRuntime
metadata:
name: cubefs-test
spec:
profileName: cubefs
profileName: cubefs2.4
EOF

$ kubectl apply -f dataset.yaml
Expand Down
2 changes: 1 addition & 1 deletion addons/cubefs/v2.4/docker/fluid_config_init.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 The Fluid Authors.
# Copyright 2023 The Fluid Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions addons/cubefs/v2.4/readme-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ $ cat <<EOF > runtime-profile.yaml
apiVersion: data.fluid.io/v1alpha1
kind: ThinRuntimeProfile
metadata:
name: cubefs
name: cubefs2.4
spec:
fileSystemType: cubefs
fuse:
Expand Down Expand Up @@ -58,7 +58,7 @@ kind: ThinRuntime
metadata:
name: cubefs-test
spec:
profileName: cubefs
profileName: cubefs2.4
EOF

$ kubectl apply -f dataset.yaml
Expand Down
4 changes: 2 additions & 2 deletions addons/cubefs/v2.4/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $ cat <<EOF > runtime-profile.yaml
apiVersion: data.fluid.io/v1alpha1
kind: ThinRuntimeProfile
metadata:
name: cubefs
name: cubefs2.4
spec:
fileSystemType: cubefs
fuse:
Expand Down Expand Up @@ -55,7 +55,7 @@ kind: ThinRuntime
metadata:
name: cubefs-test
spec:
profileName: cubefs
profileName: cubefs2.4
EOF

$ kubectl apply -f dataset.yaml
Expand Down
2 changes: 1 addition & 1 deletion addons/cubefs/v2.4/runtime-profile.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: data.fluid.io/v1alpha1
kind: ThinRuntimeProfile
metadata:
name: cubefs
name: cubefs2.4
spec:
fileSystemType: cubefs
fuse:
Expand Down
214 changes: 214 additions & 0 deletions addons/cubefs/v3.2/dev-guide/cubefs-v3.2-zh_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
# CubeFS 3.2 接入 ThinRuntime 的简单示例

## 前期准备

### CubeFS集群搭建

#### 前置条件

* Kubernetes 1.14+
* CSI spec version 1.1.0
* Helm 3

#### CubeFS 集群部署

根据 [cubefs-helm](https://github.com/cubefs/cubefs-helm) 部署 CubeFS v3.2.0 。


### 使用CubeFS作为后端存储

在CubeFS集群内创建需要挂载的存储卷。

## 准备 CubeFS-FUSE 客户端镜像

1. 挂载参数解析脚本

在 FUSE 容器内需要提取相关的 **ThinRuntimeProfile、Dataset、ThinRuntime**资源中对远程文件系统的配置信息,相关信息以 JSON 字符串的方式保存到 FUSE 容器的 **/etc/fluid/config.json** 文件内。

```python
import json

rawStr = ""
with open("/etc/fluid/config.json", "r") as f:
rawStr = f.readlines()

print(rawStr[0])

script = """
#!/bin/sh
MNT_POINT=$targetPath
echo $MNT_POINT
if test -e ${MNT_POINT}
then
echo "MNT_POINT exist"
else
mkdir -p ${MNT_POINT}
fi
/cfs/bin/cfs-client -c /cfs/fuse.json
sleep inf
"""

obj = json.loads(rawStr[0])
volAttrs = obj['mounts'][0]

print("pvAttrs", volAttrs)

fuse = {}
fuse["mountPoint"] = obj["targetPath"]
fuse["volName"] = volAttrs["name"]
fuse["masterAddr"] = volAttrs["mountPoint"]
fuse["owner"] = "root"
fuse["logDir"] = "/cfs/logs/"
fuse["logLevel"] = "error"

print("fuse.json: ", fuse)

with open("/cfs/fuse.json", "w") as f:
f.write(json.dumps(fuse))

with open("mount-cubefs.sh", "w") as f:
f.write("targetPath=\"%s\"\n" % obj['targetPath'])
f.write(script)
```
该 Python 脚本,将参数提取后以变量的方式注入 shell 脚本。其中挂载的存储卷为CubeFS集群中root用户创建,`logDir``logLevel`为默认。

2. 挂载远程文件系统脚本

在将参数解析并注入shell脚本后,生成的脚本如下
```shell
targetPath="/runtime-mnt/thin/default/cubefs-test/thin-fuse"

#!/bin/sh
MNT_POINT=$targetPath

echo $MNT_POINT

if test -e ${MNT_POINT}
then
echo "MNT_POINT exist"
else
mkdir -p ${MNT_POINT}
fi

/cfs/bin/cfs-client -c /cfs/fuse.json

sleep inf
```
该 shell 脚本创建挂载的文件夹并将远程文件系统挂载到目标位置(targetPath)。**为了防⽌ fuse pod 反复重启,需要 sleep inf 来保持进程的存在**


3. 创建 FUSE 客户端镜像

将参数解析脚本、挂载脚本和相关的库打包入镜像。

```dockerfile
FROM chubaofs/cfs-client:v3.2.0
ADD fluid_config_init.py /
```

由于Cubefs挂载需要使用官方提供的二进制文件 cfs-client,该文件存放于cubefs客户端镜像(chubaofs/cfs-client:v3.2.0) /cfs/bin中。

同时该客户端镜像已经集成了python环境(python2.7),将用于执行参数解析脚本。

## 使用示例

### 创建并部署 ThinRuntimeProfile 资源

```shell
$ cat <<EOF > cubefs-profile.yaml
apiVersion: data.fluid.io/v1alpha1
kind: ThinRuntimeProfile
metadata:
name: cubefs3.2
spec:
fileSystemType: cubefs
fuse:
image: <IMG_REPO>
imageTag: <IMG_TAG>
imagePullPolicy: IfNotPresent
command:
- sh
- -c
- "python /fluid_config_init.py && chmod u+x /mount-cubefs.sh && /mount-cubefs.sh"
EOF

$ kubectl apply -f runtime-profile.yaml
```
将上述 <IMG_REPO> 改为您制作的镜像的仓库名称,<IMG_TAG> 修改为该镜像的 TAG。

### 创建并部署 Dataset 和 ThinRuntime 资源
```shell
$ cat <<EOF > dataset.yaml
apiVersion: data.fluid.io/v1alpha1
kind: Dataset
metadata:
name: cubefs-test
spec:
mounts:
- mountPoint: <IP:Port>
name: fluid-test
---
apiVersion: data.fluid.io/v1alpha1
kind: ThinRuntime
metadata:
name: cubefs-test
spec:
profileName: cubefs3.2
EOF

$ kubectl apply -f dataset.yaml
```
将上述 `mountPoint` 修改为您需要使用的CuebFS集群Master的地址, `name`修改为需要挂载的存储卷的名字。

### 部署应用


```shell
$ cat <<EOF > app.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx
command: ["bash"]
args:
- -c
- sleep 9999
volumeMounts:
- mountPath: /data
name: data-vol
volumes:
- name: data-vol
persistentVolumeClaim:
claimName: cubefs-test
EOF

$ kubectl apply -f app.yaml
```

查看应用Pod,可发现其正常运行。Fluid自动根据ThinRuntimeProfile中的Fuse配置,创建Fuse Pod,并调度到应用同一个节点上。

```shell
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
cubefs-test-fuse-wsd26 1/1 Running 0 2m56s
nginx 1/1 Running 0 2m56s
```
远程的⽂件系统被挂载到 nginx pod 的 /data ⽬录下。

```
$ kubectl exec -it nginx bash
root@nginx:/# df -h
Filesystem Size Used Avail Use%
...
chubaofs-fluid 5.0G 4.0K 5.0G 1% /data
...
```
Loading

0 comments on commit d396e9d

Please sign in to comment.