본문 바로가기
kubenetes

JuiceFS CSI driver를 이용해 MinIO와 HDFS를 Kubernetes와 연동하기

by kyeongseo.oh 2024. 10. 11.

Kubernetes 환경에서 JuiceFS CSI(Container Storage Interface) 드라이버를 사용하여 MinIO와 HDFS를 스토리지 백엔드로 통합하는 방법을 설명한다.

JuiceFS CSI 드라이버를 통해 StorageClass를 생성하고, 이를 이용해 PVC를 만들어 Kubernetes POD에서 MinIO와 HDFS 스토리지를 마운트 하여 사용할 수 있다.

 

JuiceFS CSI 드라이버 설치

1. Helm 저장소 추가 및 업데이트

helm repo add juicefs https://juicedata.github.io/charts/
helm repo update

 

2. 기본 설정 파일 다운로드

설정 파일을 다운로드 한 후 필요한 부분은 수정한다. 이 예제에서는 기본 설정을 그대로 사용했다.

helm show values juicefs/juicefs-csi-driver > values.yaml

 

3. JuiceFS CSI 드라이버 설치

kube-system namespace에 juicefs csi driver를 설치한다.

helm upgrade --install juicefs-csi-driver juicefs/juicefs-csi-driver -n kube-system -f ./values.yaml

 

4. 설치 확인

[root@km ~]# k get pod -n kube-system | grep juicefs
juicefs-csi-controller-0                3/3     Running   0          17h
juicefs-csi-controller-1                3/3     Running   0          17h
juicefs-csi-dashboard-9cfdbfbfc-cffnl   1/1     Running   0          17h
juicefs-csi-node-44md6                  3/3     Running   0          17h
juicefs-csi-node-knpsg                  3/3     Running   0          17h
juicefs-csi-node-v9hlm                  3/3     Running   0          17h
juicefs-csi-node-vjrr4                  3/3     Running   0          17h
juicefs-csi-node-wh6qg                  3/3     Running   0          17h

 

메타데이터 저장소 설치 (Redis)

JuiceFS는 데이터와 메타데이터를 분리하여 저장한다. 파일 데이터는 Amazon S3와 같은 객체 스토리지에 청크로 분할되어 저장되고, 메타데이터는 Redis, MySQL, TiKV, SQLite 등 다양한 데이터베이스에 저장될 수 있다.

 

redis password는 적절히 수정한 후 redis를 설치한다. 이 예제에서는 my-password를 사용했다.

helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm install my-redis bitnami/redis --set auth.password=my-password -n redis --create-namespace

 

Redis 접속 정보: `redis://:my-password@my-redis-master.redis.svc.cluster.local:6379`

 

MinIO를 PV로 사용하기

1. Secret 및 StorageClass 생성

name을 minio-fs로 지정했기에 sandbox/minio-fs 하위에 file chunk가 저장된다.

apiVersion: v1
kind: Secret
metadata:
  name: juicefs-minio-secret
  namespace: kube-system
type: Opaque
stringData:
  name: minio-fs
  metaurl: redis://:my-password@my-redis-master.redis.svc.cluster.local:6379/0
  storage: minio
  bucket: http://10.0.2.3/sandbox/
  access-key: vL3AovUpljEjFufwu3IA
  secret-key: YWL5hs2B8CLqaXs7KGp0qzf6Jtk2lfCCgOJLPT9x
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: juicefs-minio-sc
provisioner: csi.juicefs.com
parameters:
  csi.storage.k8s.io/provisioner-secret-name: juicefs-minio-secret
  csi.storage.k8s.io/provisioner-secret-namespace: kube-system
  csi.storage.k8s.io/node-publish-secret-name: juicefs-minio-secret
  csi.storage.k8s.io/node-publish-secret-namespace: kube-system

 

2. PVC 생성하기

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: minio-pvc
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi
  storageClassName: juicefs-minio-sc

 

3. 테스트 POD 생성하기

apiVersion: v1
kind: Pod
metadata:
  name: juicefs-app-minio
spec:
  containers:
  - name: app
    image: ubuntu
    command: ["/bin/sh"]
    args: ["-c", "while true; do echo $(date) >> /minio/test.txt; done"]
    volumeMounts:
    - name: minio-storage
      mountPath: /minio
  volumes:
  - name: minio-storage
    persistentVolumeClaim:
      claimName: minio-pvc

 

4. MinIO에 저장된 chunk 파일 확인

C:\Users\oks52>aws s3 ls --recursive s3://sandbox/minio-fs/
2024-10-11 16:18:18         29 minio-fs/chunks/0/0/100_0_29
2024-10-11 16:18:18       2871 minio-fs/chunks/0/0/101_0_2871
2024-10-11 16:18:18         29 minio-fs/chunks/0/0/102_0_29
2024-10-11 16:18:18         29 minio-fs/chunks/0/0/103_0_29
2024-10-11 16:18:18         29 minio-fs/chunks/0/0/104_0_29
2024-10-11 16:18:18         29 minio-fs/chunks/0/0/105_0_29
2024-10-11 16:18:18         29 minio-fs/chunks/0/0/106_0_29
2024-10-11 16:18:18         29 minio-fs/chunks/0/0/107_0_29
2024-10-11 16:18:18         29 minio-fs/chunks/0/0/108_0_29
2024-10-11 16:18:18         29 minio-fs/chunks/0/0/109_0_29
2024-10-11 16:18:17         29 minio-fs/chunks/0/0/10_0_29
2024-10-11 16:18:18         29 minio-fs/chunks/0/0/110_0_29
2024-10-11 16:18:18         29 minio-fs/chunks/0/0/111_0_29
2024-10-11 16:18:18         29 minio-fs/chunks/0/0/112_0_29
2024-10-11 16:18:18         29 minio-fs/chunks/0/0/113_0_29
2024-10-11 16:18:18         29 minio-fs/chunks/0/0/114_0_29
2024-10-11 16:18:18         29 minio-fs/chunks/0/0/115_0_29
2024-10-11 16:18:18         29 minio-fs/chunks/0/0/116_0_29
2024-10-11 16:18:18         29 minio-fs/chunks/0/0/117_0_29
2024-10-11 16:18:18         29 minio-fs/chunks/0/0/118_0_29
2024-10-11 16:18:18         29 minio-fs/chunks/0/0/119_0_29
...

 

HDFS를 PV로 사용하기

1. Secret 및 StorageClass 생성

HADOOP_USER_NAME 환경변수를 추가해 hdfs 유저를 사용해 hdfs에 접근하도록 설정한다.

해당 설정을 추가하지 않으면, 권한 문제로 hdfs에 경로를 생성할 수 없기에 수동으로 경로를 생성 후 권한을 부여해야 한다.

 

bucket에는 hdfs namenode 정보를 입력한다.

apiVersion: v1
kind: Secret
metadata:
  name: juicefs-hdfs-secret
  namespace: kube-system
type: Opaque
stringData:
  name: hdfs-fs
  metaurl: redis://:my-password@my-redis-master.redis.svc.cluster.local:6379/1
  storage: hdfs
  bucket: hdfs://10.0.1.61:8020/juicefs
  envs: "{HADOOP_USER_NAME: hdfs}"
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: juicefs-hdfs-sc
provisioner: csi.juicefs.com
parameters:
  csi.storage.k8s.io/provisioner-secret-name: juicefs-hdfs-secret
  csi.storage.k8s.io/provisioner-secret-namespace: kube-system
  csi.storage.k8s.io/node-publish-secret-name: juicefs-hdfs-secret
  csi.storage.k8s.io/node-publish-secret-namespace: kube-system

 

2. PVC 생성하기

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: hdfs-pvc
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi
  storageClassName: juicefs-hdfs-sc

 

3. 테스트 POD 생성하기

apiVersion: v1
kind: Pod
metadata:
  name: juicefs-app
spec:
  containers:
  - name: app
    image: ubuntu
    command: ["/bin/sh"]
    args: ["-c", "while true; do echo $(date) >> /hdfs/test.txt; sleep 5; done"]
    volumeMounts:
    - name: hdfs-storage
      mountPath: /hdfs
  volumes:
  - name: hdfs-storage
    persistentVolumeClaim:
      claimName: hdfs-pvc

 

4. HDFS에 저장된 chunk 파일 확인

[root@adm ~]# hdfs dfs -ls -r /juicefs/hdfs-fs/chunks/*/*
Found 11 items
-rw-r--r--   3 root supergroup         29 2024-10-11 17:24 /juicefs/hdfs-fs/chunks/0/0/9_0_29
-rw-r--r--   3 root supergroup         29 2024-10-11 17:24 /juicefs/hdfs-fs/chunks/0/0/8_0_29
-rw-r--r--   3 root supergroup         29 2024-10-11 17:24 /juicefs/hdfs-fs/chunks/0/0/7_0_29
-rw-r--r--   3 root supergroup         29 2024-10-11 17:24 /juicefs/hdfs-fs/chunks/0/0/6_0_29
-rw-r--r--   3 root supergroup         29 2024-10-11 17:24 /juicefs/hdfs-fs/chunks/0/0/5_0_29
-rw-r--r--   3 root supergroup         29 2024-10-11 17:24 /juicefs/hdfs-fs/chunks/0/0/4_0_29
-rw-r--r--   3 root supergroup         29 2024-10-11 17:23 /juicefs/hdfs-fs/chunks/0/0/3_0_29
-rw-r--r--   3 root supergroup         29 2024-10-11 17:23 /juicefs/hdfs-fs/chunks/0/0/1_0_29
-rw-r--r--   3 root supergroup         29 2024-10-11 17:24 /juicefs/hdfs-fs/chunks/0/0/12_0_29
-rw-r--r--   3 root supergroup         29 2024-10-11 17:24 /juicefs/hdfs-fs/chunks/0/0/11_0_29
-rw-r--r--   3 root supergroup         29 2024-10-11 17:24 /juicefs/hdfs-fs/chunks/0/0/10_0_29
Found 34 items
-rw-r--r--   3 root supergroup         29 2024-10-11 17:27 /juicefs/hdfs-fs/chunks/0/4/4131_0_29
-rw-r--r--   3 root supergroup         29 2024-10-11 17:27 /juicefs/hdfs-fs/chunks/0/4/4130_0_29
-rw-r--r--   3 root supergroup         29 2024-10-11 17:27 /juicefs/hdfs-fs/chunks/0/4/4129_0_29
-rw-r--r--   3 root supergroup         29 2024-10-11 17:27 /juicefs/hdfs-fs/chunks/0/4/4128_0_29
-rw-r--r--   3 root supergroup         29 2024-10-11 17:27 /juicefs/hdfs-fs/chunks/0/4/4127_0_29
-rw-r--r--   3 root supergroup         29 2024-10-11 17:27 /juicefs/hdfs-fs/chunks/0/4/4126_0_29
-rw-r--r--   3 root supergroup         29 2024-10-11 17:27 /juicefs/hdfs-fs/chunks/0/4/4125_0_29
-rw-r--r--   3 root supergroup         29 2024-10-11 17:27 /juicefs/hdfs-fs/chunks/0/4/4124_0_29
-rw-r--r--   3 root supergroup         29 2024-10-11 17:26 /juicefs/hdfs-fs/chunks/0/4/4123_0_29
-rw-r--r--   3 root supergroup         29 2024-10-11 17:26 /juicefs/hdfs-fs/chunks/0/4/4122_0_29

 

JuiceFS DashBoard

juicefs-csi-dashboard svc을 NodePort 혹은 LoadBalancer로 변경해 외부에서 접근이 가능하도록 설정한다.

[root@km juicefs-csi-driver]# k get svc -n kube-system
NAME                    TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
juicefs-csi-dashboard   LoadBalancer   10.98.248.67     10.0.2.5      8088:32109/TCP           38h

 

10.0.2.5:8088로 접근하면 아래와 같은 DashBoard를 확인할 수 있다.

댓글