Recent Comments
Link
Recent Posts
Today
Total
«   2025/03   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
관리 메뉴

Study Memory Work

[K8S/CKA 자격증] Storage - Persistent Volume, Persistent VolumeClaim 본문

Infra/Kubernetes

[K8S/CKA 자격증] Storage - Persistent Volume, Persistent VolumeClaim

Hera Choi 2023. 1. 29. 19:35

PV(Persistent Volume) 만들기

미리 물리적으로 준비되어있는 starage를 kube 환경에서 사용할 수 있도록 등록하는 것!

 

Persistent Volumes

This document describes persistent volumes in Kubernetes. Familiarity with volumes is suggested. Introduction Managing storage is a distinct problem from managing compute instances. The PersistentVolume subsystem provides an API for users and administrator

kubernetes.io

# pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv0003									# PV name
spec:
  capacity:
    storage: 5Gi								# storage_size
  accessModes:									# 적용방식
    - ReadWriteOnce
    - ReadOnlyMany								
  persistentVolumeReclaimPolicy: Recycle		# Reclaim 정책. recycle(재사용), retain(데이터 보존), delete(스토리지 삭제)
  storageClassName: slow
  nfs:											# 사용 storage에 대한 정보 구성
    path: /tmp									
    server: 172.17.0.2

 

PersistentVolumeClaim 만들기

pvc를 선엉하여 disk를 요청하고, pod를 생성할 때 volume mount 작업을 통해 할당받은 disk를 사용한다.

 

Storage

Ways to provide both long-term and temporary storage to Pods in your cluster.

kubernetes.io

  • pvc 요청
# pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myclaim							# pvc name
spec:
  accessModes:
    - ReadWriteOnce						# 엑세스 모드
  resources:
    requests:
      storage: 8Gi						# 사용 용량
  storageClassName: slow				# storage class
  • volume mount
# pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: podname
spec:
  containers:
    - name: containername
      image: nginx
      volumeMounts:
      - mountPath: "/var/www/html"
        name: mypd
  volumes:
    - name: mypd
      persistentVolumeClaim:
        claimName: myclaim

 


[문제 3] PersistentVolume 만들기

작업 클러스터 : hk8s

pv001라는 이름으로 size 1Gi, access mode ReadWriteMany를 사용하여 persistent volume을 생성합니다.
volume type은 hostPath이고 위치는 /tmp/app-config입니다.

# 1. yaml 파일 생성
$ vi pv001.yaml

###
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv001
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: /tmp/app-config
###

# 2. 실행
$ kubelctl apply -f pv001.yaml

# 3. 확인
$ kubectl get pv
$ kubectl descrive pv pv001

 

[문제 4] PVC를 사용하는 애플리케이션 Pod 운영

작업 클러스터 : k8s

다음의 조건에 맞는 새로운 PersistentVolumeClaim 생성하시오. 

  • Name: pv-volume
  • Class: app-hostpath-sc
  • Capacity: 10Mi

앞서 생성한 pv-volume PersistentVolumeClaim을 mount하는 Pod 를 생성하시오.

  • Name: web-server-pod
  • Image: nginx
  • Mount path: /usr/share/nginx/html

Volume에서 ReadWriteMany 액세스 권한을 가지도록 구성합니다.

# 1. pvc 생성
$ vi pvc.yaml

###
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pv-volume
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Mi
  storageClassName: app-hostpath-sc
###

$ kubectl apply -f pvc.yaml


# 2. pvc 확인
$ kubectl get pvc
$ kubectl describe pvc pv-volume


# 3. pod 생성
$ vi pvc-pod.yaml

###
apiVersion: v1
kind: Pod
metadata:
  name: web-server-pod
spec:
  containers:
    - name: web-server
      image: nginx
      volumeMounts:
      - mountPath: "/usr/share/nginx/html"
        name: mypd
  volumes:
    - name: mypd
      persistentVolumeClaim:
        claimName: pv-volume
###

$ kubectl apply -f pvc-pod.yaml


# 4. pod 확인
$ kubectl get pod 
$ kubectl describe pod web-server-pod