CKA SimA 06 스토리지, PV, PVC, Pod 볼륨

(CKA 1.32A - Q6 스토리지, PV, PVC, Pod 볼륨에서 넘어옴)

1 개요[ | ]

PV, PVC, Deployment을 이용한 볼륨 마운트 실습
  • PersistentVolume, PersistentVolumeClaim, Deployment 리소스를 활용하여 Pod에 볼륨을 마운트하는 실습
  • ReadWriteOnce 접근 모드, hostPath를 활용한 로컬 디렉토리 바인딩 구성
  • storageClassName이 정의되지 않은 수동 바인딩 구성 예시 포함
  • "pv" → https://kubernetes.io/docs/concepts/storage/persistent-volumes/

2 PersistentVolume 생성[ | ]

  • 정적 볼륨(provisioning) 방식으로 hostPath 기반의 PV 정의
  • storageClassName 없이 구성 시 수동 매칭 필요
apiVersion: v1
kind: PersistentVolume
metadata:
  name: web-docs-pv
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /Volumes/Data
# k apply -f /tmp/web-docs-pv.yaml
persistentvolume/web-docs-pv created

3 PersistentVolumeClaim 생성[ | ]

  • ReadWriteOnce 모드와 동일한 용량으로 PVC 정의
  • storageClassName 명시 생략 시 수동 PV와 매칭됨
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: web-docs-pvc
  namespace: demo-ns
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
# k apply -f /tmp/web-docs-pvc.yaml
persistentvolumeclaim/web-docs-pvc created

4 PVC 바인딩 상태 확인[ | ]

  • PV, PVC가 서로 잘 바인딩되었는지 확인
  • STATUSBound로 출력되어야 정상
# k get pv,pvc -n demo-ns
NAME                           CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                   STORAGECLASS   REASON   AGE
persistentvolume/web-docs-pv   2Gi        RWO            Retain           Bound    demo-ns/web-docs-pvc    manual         -        10s

NAME                                 STATUS   VOLUME         CAPACITY   ACCESS MODES   STORAGECLASS   AGE
persistentvolumeclaim/web-docs-pvc   Bound    web-docs-pv    2Gi        RWO            manual         10s

5 Deployment 생성 및 볼륨 마운트[ | ]

  • PVC를 사용하는 Deployment 구성
  • volumeMounts를 통해 컨테이너 내부 경로에 마운트
  • httpd:2-alpine 이미지 사용
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-docs
  namespace: demo-ns
spec:
  replicas: 1
  selector:
    matchLabels:
      app: web-docs
  template:
    metadata:
      labels:
        app: web-docs
    spec:
      volumes:
      - name: docs-volume
        persistentVolumeClaim:
          claimName: web-docs-pvc
      containers:
      - name: httpd
        image: httpd:2-alpine
        volumeMounts:
        - name: docs-volume
          mountPath: /tmp/docs
# k apply -f /tmp/web-docs-deploy.yaml
deployment.apps/web-docs created

6 Pod에 볼륨 마운트 확인[ | ]

  • 해당 Deployment로 생성된 Pod의 마운트 상태 확인
  • Mounts 항목에서 지정한 경로와 볼륨 이름 확인 가능
# k get po -n demo-ns -l app=web-docs
NAME                          READY   STATUS    RESTARTS   AGE
web-docs-xxxxxxxxxx-yyyyy     1/1     Running   0          10s

# k -n demo-ns describe po web-docs-xxxxxxxxxx-yyyyy | grep -A2 Mounts:
    Mounts:
      /tmp/docs from docs-volume (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-xxxxx (ro)

7 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}