소프트웨어 아키텍처/Kubernetes
[Kubernetes] 1-06. PV, PVC 를 사용하는 파드 생성
bluefriday
2022. 5. 2. 16:11
반응형
이번에는 PersistentVolume(이하 PV) 을 생성한 후에, 생성된 PV를 사용하는 PersistentVolumeClaim(이하 PVC) 를 생성한다. 그리고 해당 PVC를 사용하는 파드를 만들어본다.
먼저 다음과 같이 PV 생성을 위한 yaml script를 준비한다.
apiVersion: v1
kind: PersistentVolume
metadata:
name: test-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/Volumes/Data"
하단의 명령어를 사용하여 위 PV를 생성한다.
kubectl apply -f pv.yaml
이번에는 위의 PV를 사용하는 PVC를 생성해보자. yaml script는 다음과 같다.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: test-pvc
namespace: test-namespace
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
하단의 명령어를사용하여 위 PVC를 생성한다.
kubectl apply -f pvc.yaml
이제 생성한 PVC가 PV에 바인딩 되었는지를 확인한다.
kubectl -n test-namespace get pv,pvc
NAME CAPACITY ... STATUS CLAIM ...
persistentvolume/test-pv 2Gi ... Bound test-namespace/test-pvc ...
NAME STATUS VOLUME CAPACITY ...
persistentvolumeclaim/test-pvc Bound test-pv 2Gi ...
마지막으로, PVC를 사용하는 deployment 의 script를 준비한다.
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: test
name: test
namespace: project-tiger
spec:
replicas: 1
selector:
matchLabels:
app: test
template:
metadata:
labels:
app: test
spec:
volumes:
- name: data
persistentVolumeClaim:
claimName: test-pvc
containers:
- image: httpd:2.4.41-alpine
name: container
volumeMounts:
- name: data
mountPath: /tmp/test-data
하단의 명령어를 사용하여 위 Deployment 를 생성한다.
kubectl apply -f deployment.yaml
구동 후에 PVC 를 마운트하고 있는지 확인한다.
kubectl -n test-namespace describe pod test-5cbf46d6d-mjhsb | grep -A2 Mounts:
Mounts:
/tmp/test-data from data (rw) #
/var/run/secrets/kubernetes.io/serviceaccount from default-token-n2sjj (ro)