官方文档地址:在 Kubernetes 中使用 JuiceFS | JuiceFS Document Center
简介
JuiceFS 是一款面向云原生设计的高性能分布式文件系统,在 Apache 2.0 开源协议下发布。提供完备的 POSIX 兼容性,可将几乎所有对象存储接入本地作为海量本地磁盘使用,亦可同时在跨平台、跨地区的不同主机上挂载读写。
JuiceFS 采用「数据」与「元数据」分离存储的架构,从而实现文件系统的分布式设计。文件数据本身会被切分保存在对象存储(例如 Amazon S3),而元数据则可以保存在 Redis、MySQL、TiKV、SQLite 等多种数据库中,你可以根据场景与性能要求进行选择。
JuiceFS 支持 Kubernetes CSI;为容器提供解耦的文件存储,令应用服务可以无状态化;方便地在容器间共享数据
集群环境实践:
环境准备:
集群版本:v1.20.10
节点数量:3主3从
juicefs csi 驱动安装:
下载地址:https://github.com/juicedata/juicefs-csi-driver
kubectl 方式安装:
1.18版本之前使用 :
# wget https://raw.githubusercontent.com/juicedata/juicefs-csi-driver/master/deploy/k8s_before_v1_18.yaml
1.18版本之后使用:
# wget https://raw.githubusercontent.com/juicedata/juicefs-csi-driver/master/deploy/k8s.yaml
# kubectl apply -f k8s.yaml
JuiceFS CSI 驱动包含以下组件:JuiceFS CSI Controller(StatefulSet)以及 JuiceFS CSI Node Service(DaemonSet):
# kubectl -n kube-system get pod -l app.kubernetes.io/name=juicefs-csi-driver
helm-chart方式安装:
# helm repo add juicefs https://juicedata.github.io/charts/
# helm repo update
# helm install juicefs-csi-driver juicefs/juicefs-csi-driver -n kube-system
或
下载helm-chart离线包:
# helm install juicefs-csi-driver -n kube-system juicefs-csi-driver-0.19.9.tgz
创建存储类:
# kubectl apply -f juicefs-sc-secret.yaml
# kubectl apply -f juicefs-sc.yaml
juicefs-sc-secret.yaml:
用于记录 元数据库、文件系统、账户信息等,本次使用tikv做为juicefs元数据存储库,文件系统使用S3
apiVersion: v1 data: access-key: $ak bucket: $s3/bucket metaurl: tikv://$ip:port/name name: $name secret-key: $sk storage: czM= kind: Secret metadata: name: juicefs-sc-secret namespace: "aa" type: Opaque
juicefs-sc.yaml:
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: juicefs-sc mountOptions: - enable-xattr - max-uploads=50 - cache-size=10240000 - cache-dir=/var/juicefs/cache //缓存目录 - free-space-ratio=0.05 //缓存目录阈值 - prefetch=4 - writeback - buffer-size=1024 - no-bgjob parameters: csi.storage.k8s.io/node-publish-secret-name: juicefs-sc-secret csi.storage.k8s.io/node-publish-secret-namespace: "aa" csi.storage.k8s.io/provisioner-secret-name: juicefs-sc-secret csi.storage.k8s.io/provisioner-secret-namespace: "aa" juicefs/clean-cache: "true" juicefs/mount-cpu-limit: 4000m juicefs/mount-cpu-request: 1000m juicefs/mount-delete-delay: 1m juicefs/mount-memory-limit: 8Gi juicefs/mount-memory-request: 2Gi provisioner: csi.juicefs.com reclaimPolicy: Retain volumeBindingMode: Immediate
应用测试:
创建pvc关联sc:
# kubectl apply -f juicefs-fs-pvc.yaml
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: juice-fs-pvc namespace: "aa" spec: accessModes: - ReadWriteMany resources: requests: storage: 100Gi storageClassName: juicefs-sc
应用测试:
# kubectl apply -f nginx-test.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-test namespace: aa spec: selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80 volumeMounts: - mountPath: /config name: web-data volumes: - name: web-data persistentVolumeClaim: claimName: juice-fs-pvc
关联后会自动生成一个以“juicefs-节点-pv” 名称命名的pod,用于做持久化挂载,生命周期与pvc相关: