[CKA] 9일차 - Storage (2) PV, PVC, SC
- advanced/Devops
- 2022. 8. 22.
Storage
- CSI는 k8s의 귀속적인 스펙이 아니라 ochestration tool 중에서의 universal standard임
- CSI는 volume create시에 RPC call을 요청받아서 volume을 만드는 방식으로 구현되어야 함
Volumes
pod에서 volume을 사용하는 예제(node의 host path)
(이 경우에 각 node마다 저장된 데이터가 다를 수 있음)
NFS, GlusterFS, Flocker, Ceph, SCALEIO 등을 이용해서 해결할 수 있음
apiVersion: v1
kind: Pod
metatdata:
name: random-number-generator
spec:
containers:
- image: alpine
name: alpine
command: ["/bin/sh", "-c"]
args: ["shuf -i 0-100 -n 1 >> /opt/number.out;"]
volumeMounts:
- mountPath: /opt
name: data-volume
volumes:
- name: data-volume
hostPath:
path: /data
type: Directory
Persistent Volume
pv-definition.yaml
접근 모드는 ReadOnlyMany, ReadWriteOnce, ReadWriteMany 모드가 있음
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-vol1
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
hostPath: # option 1
path: /tmp/data
awsElasticBlockStorage: # option 2
volumeID: <volume-id>
fsType: ext4
PVC(Persistent Volume Claims)
PVC 클레임의 요구사항이 맞는 PV가 있는 경우에 바인딩함
pvc-definition.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: myclaim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
Delete PVCs
kubectl delete persistentvolumeclaim myclaim
persistentVolumeReclaimPolicy: Retain # Delete, Recycle
- Retain으로 설정되어 있으면 admin에 의해서 PV가 삭제될 때까지 계속 PV 사용 가능
Retain이 default값임. Retain으로 되어 있는 경우에는 재사용 불가능 - Delete: PVC가 삭제될 때, PV도 같이 삭제됨
- Recycle: 다른 PVC에 가능하도록 만들기 전에, PV 안의 데이터들이 문질러짐?(scrubbed)
PVC를 POD에서 사용하기
PVC가 만들어지면, POD에서 다음과 같이 사용할 수 있음
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: myfrontend
image: nginx
volumeMounts:
- mountPath: "/var/www/html"
name: mypd
volumes:
- name: mypd
persistentVolumeClaim:
claimName: myclaim
Dynamic Provisioning
gcp에서 cli를 사용해서 storage를 생성하는 것은 static provisioning이라고 함
동적으로 provisioning하려면 더이상 수동으로 PV를 작성할 필요가 없습니다.
storage class를 정의하고 PVC에 연결하면 됩니다.
sc-definition.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: google-storage
provisioner: kubernetes.io/gce-pd
pvc-definition.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: myclaim
spec:
accessModes:
- ReadWriteOnce
storageClassName: google-storage
resources:
requests:
storage: 500Mi
'advanced > Devops' 카테고리의 다른 글
[CKA] 11일차 network(2) - CNI, Ingress, CoreDNS (0) | 2022.08.26 |
---|---|
[CKA] 10일차 - network(1) network 이론 및 network namespace (0) | 2022.08.26 |
[CKA] 8일차 - Storage (0) | 2022.08.21 |
[CKA] 7일차 - security (2) (config file, Authorization) (0) | 2022.08.20 |
[CKA] 6일차 - Security (0) | 2022.08.19 |