Project: Fluid (Orchestration & Management / Scheduling & Orchestration)
File: cubefs-v3.2.md

Kubernetes 1.14+ CSI spec version 1.1.0 Helm 3 Deploy CubeFS v3.2.0 according to . Create storage volumes that need to be mounted in the CubeFS cluster. Parameter Resolution Script In the FUSE container, you need to extract the configuration information of the remote file system from the relevant ThinRuntimeProfile, Dataset, and ThinRuntime resources. The relevant information is saved to the FUSE container in the form of JSON strings in /etc/fluid/config.json file. ```python import json rawStr = "" with open("/etc/fluid/config/config.json", "r") as f: rawStr = f.readlines() print(rawStr[0]) script = """ 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 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) ``` The Python script injects the parameters into the shell script in the form of variables after extraction. The mounted storage volume is created by the root user in the CubeFS cluster, and `logDir` and `logLevel` are default. Mount script After the parameters are parsed and injected into the shell script, the generated script is as follows ```shell targetPath="/runtime-mnt/thin/default/cubefs-test/thin-fuse" 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 ``` The shell script creates the mounted folder and mounts the remote file system to the target locationtargetPath.To avoid the FUSE pod from restarting repeatedlysleep inf is required to keep the process alive. Build FUSE Client Image Package parameter resolution scripts, mount scripts, and related libraries into the image. ```dockerfile FROM chubaofs/cfs-client:v3.2.0 ADD fluidconfiginit.py / ``` cfs-client is needed to mount CubeFS volume, so we use CubeFS client image(chubaofs/cfs-client:v3.2.0) here. At the same time, the client image has integrated the Python environment (Python2.7), which will be used to perform parameter resolution script. ```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 /fluidconfiginit.py && chmod u+x /mount-cubefs.sh && /mount-cubefs.sh" EOF $ kubectl apply -f runtime-profile.yaml ``` Replace the above <IMG REPO> to the repository name of the image you created, <IMG TAG>is modified to the TAG of your image. ```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 ``` Modify the above `mountPoint` to the address of the Master of CubeFS you want to use. Modify `name` to the name of the storage volume to be mounted ```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 ``` After the application using the remote file system is deployed, the corresponding FUSE pod is also scheduled to the same node. ```shell $ kubectl get pods NAME READY STATUS RESTARTS AGE cubefs-test-fuse-wsd26 1/1 Running 0 2m56s nginx 1/1 Running 0 2m56s ``` The remote file system is mounted to the /data directory of nginx pod. ``` $ kubectl exec -it nginx bash root@nginx:/# df -h Filesystem Size Used Avail Use% ... chubaofs-fluid 5.0G 4.0K 5.0G 1% /data ... ```