본문 바로가기

DevOps & SRE 엔지니어 부트캠프/프로젝트 진행

[프로젝트] Ceph Stroage

분산형 스토리지 ceph

스토리지에는 3가지 종류가 있다.

  • 블록 스토리지: 파드 하나가 사용할 블록 스토리지를 생성(RWO)
  • 파일 스토리지: 여러 파드가 공유하여 사용할 수 있는 파일 시스템 생성(RWX)
  • 객체 스토리지: S3 엔드포인트 또는 쿠버네티스 외부에서 접근할 수 있는 객체를 노출

Ceph storage는 분산형 스토리지 시스템으로, 블록스토리지, 객체스토리지, 파일 스토리지의 기능을 모두 제공한다. Rook은 쿠버네티스 클러스터 내에서 스토리지 시스템을 관리하기 위한 오픈소스 솔루션인데, Rook ceph를 사용하면 Ceph 스토리지를 쿠버네티스 클러스터 내에서 손쉽게 배포하고 관리할 수 있다.

Rook ceph는 분산 스토리지 시스템을 Self-managing, Self-scaling, Self-healing storage service로 전환하여 스토리지 관리자의 작업을 자동화한다.

 

주의! 설정하기에 앞서 Ceph에 사용할 빈 디스크를 먼저 추가해주어야 한다.

Ceph클러스터를 구성하려는 모든 가상머신에 sdb라는 빈 디스크를 추가한다.

 

다음의 설정은 마스터 노드에서만 실행한다.

git clone --single-branch --branch v1.14.8 https://github.com/rook/rook.git

cd rook/deploy/examples
kubectl create -f crds.yaml -f common.yaml -f operator.yaml

kubectl create -f cluster.yaml (모든 작업이 완료되기까지 소요시간이 존재)

kubectl get all -n rook-ceph

 

git clone으로 가져오는 파일 설명(/deploy/examples)

  • cluster.yaml : 이 파일은 Rook 클러스터의 기본 설정을 정의한다. 스토리지 노드, 리소스 요구사항, 네트워크 설정 등을 포함한다. 주의! 노드가 3개 이상 필요함
  • operator.yaml : Rook 오퍼레이터를 배포하기 위한 Yaml 파일. 오퍼레이터는 Rook 클러스터의 라이프 사이클을 관리한다.
  • common.yaml : 공통 리소스(ex: CRDs, RBAC 규칙 등)을 정의하는 파일
  • toolbox.yaml : Rook 클러스터를 디버깅하고 관리하기 위한 툴박스 파드를 배포하는 파일
  • ceph-cluster.yaml : Ceph 스토리지 클러스터를 설정하기 위한 예제 파일. Ceph는 Rook이 지원하는 주요 스토리지 백엔드 중의 하나이다.
  • ceph-filesystem.yaml, ceph-block-pool.yaml : 각각 Ceph 파일 시스템, 블록스토리지를 설정하기 위한 예제파일
  • storageclass.yaml : 쿠버네티스 StorageClass를 정의하는 파일로, 동적 프로비저닝을 가능하게 함

오퍼레이터가 작동하는지 확인

kubectl -n rook-ceph get pod

정상적으로 실행되는 rook-ceph-operator

 

각 노드에 OSD가 제대로 생성되었는지 확인해야 한다.

 

OSD 파드는 Running 상태여야 하고, OSD-prepare 파는 Completed 상태여야 한다. OSD-prepare 파드는 3개가 있는데, OSD 파드가 부족하다면 오퍼레이터에 의해 skip된 것이다.

OSD-prepare은 completed되어야 한다.

 

모든 파드가 활성화된 모습


디버깅용 툴박스 파드 생성

kubectl create -f toolbox.yaml

스토리지 클래스 생성


블록스토리지를 사용하는 경우

  • Ceph Block pool 생성
apiVersion: ceph.rook.io/v1
kind: CephBlockPool
metadata:
  name: replicapool
  namespace: rook-ceph
spec:
  failureDomain: host
  replicated:
    size: 3
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
   name: rook-ceph-block
# Change "rook-ceph" provisioner prefix to match the operator namespace if needed
provisioner: rook-ceph.rbd.csi.ceph.com
parameters:
    # clusterID is the namespace where the rook cluster is running
    clusterID: rook-ceph
    # Ceph pool into which the RBD image shall be created
    pool: replicapool

    # (optional) mapOptions is a comma-separated list of map options.
    # For krbd options refer
    # https://docs.ceph.com/docs/master/man/8/rbd/#kernel-rbd-krbd-options
    # For nbd options refer
    # https://docs.ceph.com/docs/master/man/8/rbd-nbd/#options
    # mapOptions: lock_on_read,queue_depth=1024

    # (optional) unmapOptions is a comma-separated list of unmap options.
    # For krbd options refer
    # https://docs.ceph.com/docs/master/man/8/rbd/#kernel-rbd-krbd-options
    # For nbd options refer
    # https://docs.ceph.com/docs/master/man/8/rbd-nbd/#options
    # unmapOptions: force

    # RBD image format. Defaults to "2".
    imageFormat: "2"

    # RBD image features. Available for imageFormat: "2". CSI RBD currently supports only `layering` feature.
    imageFeatures: layering

    # The secrets contain Ceph admin credentials.
    csi.storage.k8s.io/provisioner-secret-name: rook-csi-rbd-provisioner
    csi.storage.k8s.io/provisioner-secret-namespace: rook-ceph
    csi.storage.k8s.io/controller-expand-secret-name: rook-csi-rbd-provisioner
    csi.storage.k8s.io/controller-expand-secret-namespace: rook-ceph
    csi.storage.k8s.io/node-stage-secret-name: rook-csi-rbd-node
    csi.storage.k8s.io/node-stage-secret-namespace: rook-ceph

    # Specify the filesystem type of the volume. If not specified, csi-provisioner
    # will set default as `ext4`. Note that `xfs` is not recommended due to potential deadlock
    # in hyperconverged settings where the volume is mounted on the same node as the osds.
    csi.storage.k8s.io/fstype: ext4

# Delete the rbd volume when a PVC is deleted
reclaimPolicy: Delete

파일 스토리지를 사용하는 경우

  • Ceph 파일 시스템 기반 동적 프로비저닝
# Ceph 파일 시스템 정의

apiVersion: ceph.rook.io/v1
kind: CephFilesystem
metadata:
  name: myfs
  namespace: rook-ceph
spec:
  metadataPool:
    replicated:
      size: 3
  dataPools:
    - replicated:
        size: 3
  preserveFilesystemOnDelete: true
  metadataServer:
    activeCount: 1
    activeStandby: true
# 스토리지클래스 생성

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: rook-cephfs
# Change "rook-ceph" provisioner prefix to match the operator namespace if needed
provisioner: rook-ceph.cephfs.csi.ceph.com
parameters:
  # clusterID is the namespace where operator is deployed.
  clusterID: rook-ceph

  # CephFS filesystem name into which the volume shall be created
  fsName: myfs

  # Ceph pool into which the volume shall be created
  # Required for provisionVolume: "true"
  pool: myfs-data0

  # The secrets contain Ceph admin credentials. These are generated automatically by the operator
  # in the same namespace as the cluster.
  csi.storage.k8s.io/provisioner-secret-name: rook-csi-cephfs-provisioner
  csi.storage.k8s.io/provisioner-secret-namespace: rook-ceph
  csi.storage.k8s.io/controller-expand-secret-name: rook-csi-cephfs-provisioner
  csi.storage.k8s.io/controller-expand-secret-namespace: rook-ceph
  csi.storage.k8s.io/node-stage-secret-name: rook-csi-cephfs-node
  csi.storage.k8s.io/node-stage-secret-namespace: rook-ceph

reclaimPolicy: Delete

스토리지 클래스 생성

kubectl apply -f ~/rook/deploy/examples/csi/rbd/storageclass.yaml

kubectl get storageclasses.storage.k8s.io

Rook-ceph-block 스토리지 클래스가 생성되었다.


Pod에서 Ceph 스토리지에 접근

  • PVC 생성
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-cephfs-pvc
spec:
  accessModes:
    - ReadWriteMany # 블록 스토리지를 사용하면 ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  storageClassName: rook-ceph-filesystem # 생성한 스토리지 클래스에 따라 변경
  • 파드와 PVC 연결
apiVersion: v1
kind: Pod
metadata:
  name: my-cephfs-pod
spec:
  containers:
  - name: my-container
    image: nginx
    volumeMounts:
    - mountPath: "/data"
      name: cephfs-storage
  volumes:
  - name: cephfs-storage
    persistentVolumeClaim:
      claimName: my-cephfs-pvc

Ceph 모니터링


  • Rook ceph는 대시보드를 활성화하여 클러스터의 상태를 웹에서 확인할 수 있도록 한다.
# rook-ceph 서비스의 설정을 수정해야 한다

kubectl edit CephCluster rook-ceph -n rook-ceph

dashboard:
    enabled: true
    ssl: true  # http로 사용하려면 false로 수정
  • 노드 포트 추가(로드밸런서를 이용하려면 metallb를 설치한 다음 설정 진행)
apiVersion: v1
kind: Service
metadata:
  name: rook-ceph-mgr-dashboard-external-https
  namespace: rook-ceph
  labels:
    app: rook-ceph-mgr
    rook_cluster: rook-ceph
spec:
  ports:
  - name: dashboard
    port: 7000
    protocol: TCP
    targetPort: 7000
  selector:
    app: rook-ceph-mgr
    rook_cluster: rook-ceph
  sessionAffinity: None
  type: NodePort

 

위와 같이 설정이 완료되면 노드 포트를 통해 대시보드에 접속할 수 있다.

 

계정: admin 

비밀번호: 아래 명령어로 확인

kubectl get secret rook-ceph-dashboard-password -n rook-ceph -o yaml | grep "password:" | awk '{print $2}' | base64 --decode

http://[노드의 ip 주소]:[포트번호]

 

주의! 필요없더라도 Rook-ceph 네임스페이스를 삭제하지 말자. 아주 귀찮은 작업이 발생함