목차

Kubernetes Volume - StorageClass

  • 관리자가 수동으로 PV생성
  • 하위 세부요소인 용량, 액세스 도드 및 저장소 유형을 지정
  • 정의된 PV는 사용자가 생성하는 PVC의 요구사항과 일치하는 사용 가능한 PV에 Binding
  • PVC요청에 맞게 PV생성을 자동화
  • 관지라는 PV 생성하기 위한 템플릿 StorageClass 정의
  • 사용자가 특정 StoargeClass를 참조하는 PVC를 생성하면 프로비저너는 PVC요구사항에 맞는 PV를 자동 생성
  • 프로비저너(Porvisioner)는 일반적으로 CSP가 제공하는 볼륨플러그인을 사용
  • 운영환경에서는 성능을 최대로 높게
  • 개발환경에서는 느리지만 안전한 volume에 저장하도록 구성
  • 운영정책에 따라 StorageClass를 정의하여 그에 맞는 PV를 자동 생성 가능
  • OpenEBS hostpath는 Pod가 실행되는 Node의 디렉토리(hostpath)를 Pod의 볼륨으로 할당
$ kubectl apply -f https://openebs.github.io/charts/openebs-operator-lite.yaml

$ kubectl apply -f https://openebs.github.io/charts/openebs-lite-sc.yaml

$ kubectl get sc
NAME               PROVISIONER        RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
openebs-device     openebs.io/local   Delete          WaitForFirstConsumer   false                  7s
openebs-hostpath   openebs.io/local   Delete          WaitForFirstConsumer   false                  7s

openbs-pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: openebs-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: "openebs-hostpath"

openbs-pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: openebs-pod
spec:
  containers:
  - image: nginx:1.24.0
    name: openebs-container
    ports:
    - containerPort: 80
    volumeMounts:
    - name: openebs-path
      mountPath: /data
  volumes:
  - name: openebs-path
    persistentVolumeClaim:
      claimName: openebs-pvc

테스트

$ kubectl apply -f openbs-pvc.yaml

$ kubectl apply -f openbs-pod.yaml

$ kubectl get pv,pvc | grep openebs
persistentvolume/pvc-ba074adb-605b-4c3c-96f6-b490073980c6   1Gi        RWO            Delete           Bound    default/openebs-pvc   openebs-hostpath            8m53s
persistentvolumeclaim/openebs-pvc   Bound    pvc-ba074adb-605b-4c3c-96f6-b490073980c6   1Gi        RWO            openebs-hostpath   9m13s

#파일 생성
$ kubectl exec -it openebs-pod -- bash

root@openebs-pod:/# cd data/

root@openebs-pod:/data# touch test.txt

#pod node 확인
$ kubectl get po,pv,pvc -o wide | grep openeb
pod/openebs-pod                         1/1     Running   0          14m     10.109.131.16   k8s-node2    <none>           <none>
persistentvolume/pvc-8d027ec0-984b-4a95-a3ce-a3621bf8b838   1Gi        RWO            Delete           Bound    default/openebs-pvc   openebs-hostpath            21m   Filesystem
persistentvolumeclaim/openebs-pvc   Bound    pvc-8d027ec0-984b-4a95-a3ce-a3621bf8b838   1Gi        RWO            openebs-hostpath   22m   Filesystem

#node2 에서 확인
$ sudo find / -name test.txt
/var/openebs/local/pvc-8d027ec0-984b-4a95-a3ce-a3621bf8b838/test.txt