[쿠버네티스 스토리지] 스토리지클래스를 활용한 동적 프로비저닝

hi·2023년 8월 3일
0

쿠버네티스

목록 보기
44/64
post-custom-banner

PV 동적 프로비저닝

  • PV를 직접 만드는 대신 사용자가 원하는 PV 유형을 선택하도록 오브젝트를 정의하는 기능



storageclass.yaml

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: storage-class
provisioner: kubernetes.io/gce-pd # 프로비저닝에 사용할 플러그인
parameters:
  type: pd-ssd # 제공자에게 전달될 매개 변수
imkunyoung@cloudshell:~/storage (k8s-inflearn)$ nano storageclass.yaml
imkunyoung@cloudshell:~/storage (k8s-inflearn)$ kubectl create -f storageclass.yaml
storageclass.storage.k8s.io/storage-class created
imkunyoung@cloudshell:~/storage (k8s-inflearn)$ kubectl get sc
NAME                     PROVISIONER             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
premium-rwo              pd.csi.storage.gke.io   Delete          WaitForFirstConsumer   true                   37d
standard                 kubernetes.io/gce-pd    Delete          Immediate              true                   37d
standard-rwo (default)   pd.csi.storage.gke.io   Delete          WaitForFirstConsumer   true                   37d
storage-class            kubernetes.io/gce-pd    Delete          Immediate              false                  7s

mongodb-pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mongodb-pvc # 클레임 사용 때 필요
spec:
  resources:
    requests:
      storage: 1Gi # 요청하는 스토리지 양
  accessModes:
    - ReadWriteOnce # 단일 클라이언트에 읽기 쓰기 지원
  storageClassName: storage-class # 동적 프로비저닝에서 사용
imkunyoung@cloudshell:~/storage (k8s-inflearn)$ kubectl get pod
NAME                       READY   STATUS    RESTARTS   AGE
http-go-85cf4fd86b-bhnmj   1/1     Running   0          5d7h
mariadb-6976d764d4-zvnh9   1/1     Running   0          2d7h
mongodb                    1/1     Running   0          3h26m

kubectl delete pods mongodb

kubectl replace -f mongodb-pvc.yaml --force


  • PV 동적 프로비저닝을 사용하면 사용할 디스크와 PV가 자동으로 생성됨
imkunyoung@cloudshell:~/storage (k8s-inflearn)$ gcloud compute disks list
NAME: gke-my-first-cluster-1-default-pool-a0f2cf43-ayqc
LOCATION: us-central1-c
LOCATION_SCOPE: zone
SIZE_GB: 32
TYPE: pd-balanced
STATUS: READY

NAME: gke-my-first-cluster-1-default-pool-a0f2cf43-njrp
LOCATION: us-central1-c
LOCATION_SCOPE: zone
SIZE_GB: 32
TYPE: pd-balanced
STATUS: READY

NAME: gke-my-first-cluster-1-default-pool-a0f2cf43-uu79
LOCATION: us-central1-c
LOCATION_SCOPE: zone
SIZE_GB: 32
TYPE: pd-balanced
STATUS: READY

NAME: mongodb
LOCATION: us-central1-c
LOCATION_SCOPE: zone
SIZE_GB: 10
TYPE: pd-standard
STATUS: READY


NAME: pvc-f09652db-2d8a-49ea-991e-e33156ec9787 ⬅️⬅️⬅️⬅️⬅️⬅️⬅️⬅️⬅️⬅️⬅️
LOCATION: us-central1-c
LOCATION_SCOPE: zone
SIZE_GB: 1
TYPE: pd-ssd
STATUS: READY

NAME: master-1
LOCATION: us-west1-b
LOCATION_SCOPE: zone
SIZE_GB: 100
TYPE: pd-standard
STATUS: READY

NAME: worker-1
LOCATION: us-west1-b
LOCATION_SCOPE: zone
SIZE_GB: 100
TYPE: pd-standard
STATUS: READY

NAME: worker-2
LOCATION: us-west1-b
LOCATION_SCOPE: zone
SIZE_GB: 100
TYPE: pd-standard
STATUS: READY
imkunyoung@cloudshell:~/storage (k8s-inflearn)$ kubectl get pv
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS     CLAIM                 STORAGECLASS    REASON   AGE
mongodb-pv                                 1Gi        RWO,ROX        Retain           Released   default/mongodb-pvc                            3h44m
pvc-f09652db-2d8a-49ea-991e-e33156ec9787   1Gi        RWO            Delete           Bound      default/mongodb-pvc   storage-class            2m25s

  • PV 동적 프로비저닝 동작 순서

post-custom-banner

0개의 댓글