DevOps/CKA Test 준비

14. CKA PV & PVC

치킨맛코드 2023. 3. 7. 08:46

PV(persistentVolume) 생성하기
pv를 생성하시오
작업 클러스터 : hk8s
name : pv001
size : 1Gi
access mode : RWX
volume tpye : hostpath
path : /tmp/app-config

작업 클러스터 확인하기
kubectl config use-context hk8s

yaml 파일 생성하기

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

2. 해당 yaml 실행하기


PVC생성하기
pvc를 생성한 후 해당 pvc를 mount 하는 pod를 생성하시오.
작업 클러스터 : k8s
namep: pv-volume
class : app-hostpath-sc
capacity: 10Mi

pod
name: web-server-pod
image : nginx
mount path: /usr/share/nginx/html
accessModes:ReadWriteMany

 
pv할당

pod 실행

volume 선언

mount


1. 작업 클러스터로 이동
kubectl config use-context k8s

2. pv생성
appVersion: v1
kind: PersistentVolumeClaim
metadata:
    name: pv-volume
spec:
   accessMode:
   - ReadWriteMany
   resources:
      requests:
         storage: 10Mi
  storageClassName: app-hostpath-sc

3.pvc 생성
kubectl apply -f pvc.yaml

4.pvc와 mount 하는 pod 생성

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