This post mainly records the script for creating an enterprise-edition JuiceFS PVC, to make configuration quick.
1. Set Environment Variables
1.1 Basic Configuration
1
2
3
| export NAMESPACE=
export PVC_NAME=
export JUICEFS_VOLUME=
|
1.2 JuiceFS Credentials
1
2
3
| export TOKEN=
export ACCESS_KEY=
export SECRET_KEY=
|
1.3 JuiceFS Service Configuration
1
2
| export BASE_URL=http://x.x.x.x:8080/static
export CFG_URL=http://x.x.x.x:8080/volume/%s/mount
|
1.4 Image Configuration
1
2
3
4
| export JUICEFS_IMAGE=juicedata/mount
export JUICEFS_IMAGE_TAG=ee-5.2.13-7a0eb79
export DEMO_IMAGE=ubuntu
|
1.5 Worker Configuration
1
2
3
| export WORKER_REPLICAS=1
export NODE_SELECTOR_KEY=
export NODE_SELECTOR_VALUE="true"
|
1.6 Cache Configuration
1
2
3
| export CACHE_GROUP="${PVC_NAME}-cache-group"
export CACHE_PATH=/data/jfs-cache
export CACHE_QUOTA=2Ti
|
For clusters in different network zones, CACHE_GROUP should be set to different values; sharing cache data is prohibited.
2. Create the Secret
Create a Secret containing the JuiceFS credentials and configuration.
1
2
3
4
5
6
| kubectl -n $NAMESPACE create secret generic ${PVC_NAME} \
--from-literal=name=$PVC_NAME \
--from-literal=token="$TOKEN" \
--from-literal=accesskey=$ACCESS_KEY \
--from-literal=secretkey=$SECRET_KEY \
--from-literal=envs="{\"BASE_URL\": \"$BASE_URL\", \"CFG_URL\": \"$CFG_URL\"}"
|
3. Create the Dataset
Create the Dataset resource, configuring the mount point and encryption options.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
| kubectl apply -f - <<EOF
apiVersion: data.fluid.io/v1alpha1
kind: Dataset
metadata:
name: $PVC_NAME
namespace: $NAMESPACE
spec:
accessModes:
- ReadWriteMany
mounts:
- name: $JUICEFS_VOLUME
mountPoint: juicefs:///
options:
max-uploads: "200"
max-cached-inodes: "10000000"
cache-size: "2048000"
opencache: ""
buffer-size: "2048"
cache-group: "$CACHE_GROUP"
encryptOptions:
- name: access-key
valueFrom:
secretKeyRef:
name: ${PVC_NAME}
key: accesskey
- name: secret-key
valueFrom:
secretKeyRef:
name: ${PVC_NAME}
key: secretkey
- name: token
valueFrom:
secretKeyRef:
name: ${PVC_NAME}
key: token
EOF
|
4. Create the JuiceFSRuntime
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
| kubectl apply -f - <<EOF
apiVersion: data.fluid.io/v1alpha1
kind: JuiceFSRuntime
metadata:
name: $PVC_NAME
namespace: $NAMESPACE
spec:
replicas: $WORKER_REPLICAS
juicefsVersion:
image: $JUICEFS_IMAGE
imageTag: $JUICEFS_IMAGE_TAG
fuse:
image: $JUICEFS_IMAGE
imageTag: $JUICEFS_IMAGE_TAG
env:
- name: BASE_URL
value: $BASE_URL
- name: CFG_URL
value: $CFG_URL
cleanPolicy: OnDemand
options:
cache-size: "0"
worker:
env:
- name: BASE_URL
value: $BASE_URL
- name: CFG_URL
value: $CFG_URL
nodeSelector:
$NODE_SELECTOR_KEY: "$NODE_SELECTOR_VALUE"
resources:
requests:
cpu: 1
memory: 5Gi
tieredstore:
levels:
- mediumtype: SSD
path: $CACHE_PATH
quota: $CACHE_QUOTA
low: "0.2"
EOF
|
5. Create a Test Pod
Create a test Pod to verify that the PVC works correctly.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| kubectl apply -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
name: ${PVC_NAME}
namespace: $NAMESPACE
spec:
containers:
- name: demo
image: $DEMO_IMAGE
command: ["sleep", "infinity"]
volumeMounts:
- mountPath: /data/jfs
name: data
volumes:
- name: data
persistentVolumeClaim:
claimName: $PVC_NAME
EOF
|
6. Clean Up Resources
1
2
3
4
| kubectl -n $NAMESPACE delete pod ${PVC_NAME}
kubectl -n $NAMESPACE delete juicefsruntime $PVC_NAME
kubectl -n $NAMESPACE delete dataset $PVC_NAME
kubectl -n $NAMESPACE delete secret ${PVC_NAME}
|
7. Other Configuration
worker and fuse use the configuration file in the /root/.juicefs directory, which is generated by the juicefs auth command. If you need a custom configuration file, you can create a Secret and then mount that Secret in the JuiceFSRuntime.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| apiVersion: v1
kind: Secret
metadata:
name: ${PVC_NAME}-conf
namespace: $NAMESPACE
type: Opaque
stringData:
${JUICEFS_VOLUME}.conf: |
{
"master": "cn-beijing-1.local:9420",
"master_ip": [
],
"storage": "ks3",
"region": "cn-beijing",
"bucket": "http://my-bucket.ks3.my-domain.com"
}
|
The bucket’s full domain name here is detected by JuiceFS based on the environment; if the internal domain is reachable, the internal domain is preferred. If you need to customize it, you can specify the full domain name in the configuration file.
1
2
3
4
5
6
7
8
9
10
11
12
13
| apiVersion: data.fluid.io/v1alpha1
kind: JuiceFSRuntime
metadata:
name: jfsdemo-ee
spec:
fuse:
volumeMounts:
- name: auth-config
mountPath: "/root/.juicefs"
volumes:
- name: auth-config
secret:
secretName: ${PVC_NAME}-conf
|