
베하~! BTC_녹차공원 팀의 민물공원 입니다.
이번주는 PVC에 대해 알아보겠습니다!
PVC
PVC를 알기 전에 PV가 무엇인지 먼저 알아야합니다.
PV가 무엇인지 모르는 분들은 아래 링크를 참고해주세요.
[K8S] PV
베하~! BTC_녹차공원 팀의 하동녹차 입니다. Kubernetes PV(Persistent Volume) 에 대해 알아보겠습니다! 쿠버네티스 PV(Persistent Volume) 쿠버네티스 PV(Persistent Volume)는 쿠버네티스에서 데이터를 저장하기 위
btcd.tistory.com
PV(Persistent Volume)는 볼륨입니다. PVC(Persistent Volume Claim)는 사용자가 PV에 하는 요청입니다.
PVC를 통해 사용하고 싶은 용량은 얼마인지, 읽기/쓰기 중 어떤 모드로 설정하고 싶은지 등에 대한 요청을 할 수 있습니다.
Pod에 볼륨을 직접 할당하는 것이 아니라 PVC를 통해 파드와 스토리지를 분리하였습니다. 이런 구조를 통해 파드에 다양한 스토리지를 상황에 맞게 배치할 수 있습니다.
PVC 실습
이번 실습도 Killercoda 에서 따라해보아요.
Killercoda Interactive Environments
Learn DevOps Linux Kubernetes CKS CKA CKAD Git Cassandra etc | Katacoda compatible
killercoda.com
PVC를 생성하여 Pod에 PV를 Mount 해보는 실습을 진행해 보겠습니다.
먼저 PV를 생성해줍니다.
k apply -f- <<EOF
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-volume
labels:
type: local
spec:
storageClassName: test-sc
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"
EOF
그 후 PVC를 생성해줍니다.
k apply -f- <<EOF
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-volume
spec:
storageClassName: test-sc
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 10Mi
EOF
Pod를 생성합니다.
k apply -f- <<EOF
apiVersion: v1
kind: Pod
metadata:
labels:
run: web-server
name: web-server
spec:
containers:
- name: web-server
image: nginx
volumeMounts:
- name: pv-volume
mountPath: "/usr/share/nginx/html"
dnsPolicy: ClusterFirst
restartPolicy: Always
volumes:
- name: pv-volume
persistentVolumeClaim:
claimName: pvc-volume
EOF
PVC 와 PV가 Bound 상태인지 확인합니다.
kubectl get pv
kubectl get pvc

- Available : PV 생성
- Bound : PVC에 의해 Binding 되었을 경우
- Released : PVC가 삭제 되었을 경우
- Fail : PV에 문제가 생겼을 경우
Pod의 상태도 확인합니다.
kubectl get pods -o wide

정상적으로 Pod와 PVC, PV가 연결되었음을 확인할 수 있었습니다!
이렇게 오늘은 PVC 에 대해 알아보았는데요.
다음번에는 더 흥미로운 주제로 찾아뵙겠습니다.
이상 BTC_녹차공원 팀이였습니다!
베빠~!

댓글