목차

Kubernetes Volume - StorageClass

$ 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
  • open