JuiceFS Operator
JuiceFS 提供了一个 Operator,它是一个专为 Kubernetes 环境设计的控制器,用于自动化管理 JuiceFS 的分布式缓存集群、缓存预热和数据同步等功能,以便在容器环境中更轻易的使用 JuiceFS。
安装 JuiceFS Operator
安装 Helm,然 后加入 JuiceFS 官方仓库。
helm repo add juicefs https://juicedata.github.io/charts/
helm repo update
安装之前,阅读 values.yaml 了解各个配置项,该文件包含了所有的默认配置,如果需要修改配置,请在本地创建另一份 values(以下且称 values-mycluster.yaml),并把需要修改的部分加入其中。如果需要在多个 Kubernetes 集群部署 Operator,就创建多个 values 文件,来区分不同的集群配置。
# 根据需要修改 values-mycluster.yaml
helm upgrade --install juicefs-operator juicefs/juicefs-operator -n juicefs-operator --create-namespace -f values-mycluster.yaml
可以使用 kubectl wait 等待 Operator 准备就绪:
kubectl wait -n juicefs-operator --for=condition=Available=true --timeout=120s deployment/juicefs-operator
更新 JuiceFS Operator
如果需要更新 Operator,可以使用以下命令:
helm repo update
helm upgrade juicefs-operator juicefs/juicefs-operator -n juicefs-operator --reuse-values
由于 Helm 的限制,更新时并不会一起更新 CRD,因此请在更新 Operator 之后,手动更新 CRD:
export CHART_VERSION=$(helm show chart juicefs/juicefs-operator | grep appVersion | awk '{print $2}')
kubectl apply -f https://raw.githubusercontent.com/juicedata/juicefs-operator/refs/tags/v${CHART_VERSION}/dist/crd.yaml
缓存组集群
企业版用户可以使用「JuiceFS Operator」来创建和管理分布式缓存集群。相比于其它部署方式,Operator 在使用上更为便捷(支持 GUI 和 CLI 两种交互方式),同时还支持异构节点不同配置、平滑加减节点、自动清理缓存等高级功能。
以下章节介绍的操作通过 CSI Dashboard(0.25.3 及以上版本)和 kubectl 均可完成,选择你喜好的使用方式即可。为了简化文档示例,后续仅介绍基于 kubectl 的操作方法。

创建缓存组
参考以下示例将缓存组配置保存为一个 YAML 文件(例如 juicefs-cache-group.yaml),这个示例会在所有设置了 juicefs.io/cg-worker: "true" 标签的节点中部署分布式缓存(当然你也可以设置任意的标签)。关于更多配置项的说明请参考「缓存组配置项」小节。
apiVersion: v1
kind: Secret
metadata:
name: juicefs-secret
namespace: juicefs-cache-group
type: Opaque
stringData:
name: juicefs-xx
token: xx
access-key: xx
secret-key: xx
# envs: '{"BASE_URL": "http://<IP or HOST>/static"}'
---
apiVersion: juicefs.io/v1
kind: CacheGroup
metadata:
name: cachegroup-sample
namespace: juicefs-cache-group
spec:
secretRef:
name: juicefs-secret
cacheGroup: juicefs-cache-group-cachegroup-sample # 自定义缓存组名称,默认为 `${NAMESPACE}-${NAME}`
worker:
template:
nodeSelector:
juicefs.io/cg-worker: "true"
image: juicedata/mount:ee-5.1.1-1faf43b
opts:
- cache-size=204800
- free-space-ratio=0.01
- group-weight=100
cacheDirs:
- type: HostPath
path: /mnt/cache
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 1
memory: 1Gi
然后通过 kubectl apply 命令创建缓存组:
kubectl apply -f juicefs-cache-group.yaml
如果 Kubernetes 节点还没有设置 juicefs.io/cg-worker: "true" 标签,需要加上这个标签:
kubectl label node node1 juicefs.io/cg-worker=true
获取缓存组状态
通过以下命令获取缓存组状态,确认缓存组已经处于「Ready」状态:
$ kubectl get cachegroups
NAME CACHE GROUP NAME PHASE READY AGE
cachegroup-sample juicefs-cache-group-cachegroup-sample Ready 1/1 10s
使用缓存组
完成以上步骤以后,便已经在 K8s 中启动了一个 JuiceFS 分布式缓存集群,其缓存组名为 juicefs-cache-group-cachegroup-sample。为了让应用程序的 JuiceFS 客户端使用该缓存集群,需要让 JuiceFS 客户端加入这个缓存组,并添加 --no-sharing 挂载参数,这样一来,应用程序的 JuiceFS 客户端虽然加入了缓存组,但却不参与缓存数据的构建,避免了客户端频繁创建、销毁所导致的缓存数据不稳定。
以动态配置为例,按照下方示范修改挂载参数即可,有关如何调整挂载配置的介绍详见「挂载参数」。
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: juicefs-sc
mountOptions:
- cache-group=juicefs-cache-group-cachegroup-sample
- no-sharing