sangw0804 / study-docker

0 stars 1 forks source link

9. 퍼시스턴트 볼륨(PV)과 퍼시스턴트 볼륨 클레임(PVC) #9

Open gyeol1212 opened 3 years ago

gyeol1212 commented 3 years ago

WHY?

퍼시스턴트 볼륨(PV)

HostPath

apiVersion: v1
kind: Pod
metadata:
  name: hostpath-pod
spec:
  containers:
    - name: my-container
      image: busybox
      args: [ "tail", "-f", "/dev/null" ]
      volumeMounts:
      - name: my-hostpath-volume
        mountPath: /etc/data # 1. 여기에 파일을 생성하면
  volumes:
    - name: my-hostpath-volume
      hostPath:
        path: /tmp # 2. (호스트의) 여기에 파일이 저장됨

emptyDir

kubectl apply -f emptydir-pod.yaml

kubectl exec -it emptydir-pod -c content-creator sh

echo Hello World >> /data/test.html

kubectl describe pod emptydir-pod | grep IP

kubectlrun -i --tty --rm debug --image=alicek106/ubuntu:curl --restart=Never -- curl 10.1.0.7/test.html


### 네트워크 볼륨
#### NFS
- 네트워크 스토리지
- 여러개의 클라이언트가 동시에 마운트해서 사용 가능
- 우선은 임시로 쿠버네티스 클러스터 내부에서 NFS를 만들어서 사용해보자
#### NFS 서버 생성

kubectl apply -f nfs-deployment.yaml

kubectl apply -f nfs-service.yaml

#### NFS 서버의 볼륨 마운트
```YAML
apiVersion: v1
kind: Pod
metadata:
  name: nfs-pod
spec:
  containers:
    - name: nfs-mount-container
      image: busybox
      args: [ "tail", "-f", "/dev/null" ]
      volumeMounts:
      - name: nfs-volume
        mountPath: /mnt           # 포드 컨테이너 내부의 /mnt 디렉터리에 마운트합니다.
  volumes:
  - name : nfs-volume
    nfs:                            # NFS 서버의 볼륨을 포드의 컨테이너에 마운트합니다.
      path: /
      server: {NFS_SERVICE_IP}
# export NFS_CLUSTER_IP=$(kubectl get svc/nfs-service -o jsonpath='{.spec.clusterIP}')
# cat nfs-pod.yaml | sed "s/{NFS_SERVICE_IP}/$NFS_CLUSTER_IP/g" | kubectl apply -f -
# kubectl exec -it nfs-pod sh

# kubectl get pod nfs-pod -o yaml | kubectl replace --force -f-

퍼시스턴트 볼륨 클레임(PVC)

EBS 볼륨 생성

퍼시스턴트 볼륨 생성

apiVersion: v1
kind: PersistentVolume
metadata:
  name: ebs-pv
spec:
  capacity:
    storage: 5Gi         # 이 볼륨의 크기는 5G입니다.
  accessModes:
    - ReadWriteOnce    # 하나의 포드 (또는 인스턴스) 에 의해서만 마운트 될 수 있습니다.
  awsElasticBlockStore:
    fsType: ext4
    volumeID: <VOLUME_ID> # 머릿속의 볼륨 아이디

퍼시스턴트 볼륨 클레임 생성

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-ebs-pvc                  # 1. my-ebs-pvc라는 이름의 pvc 를 생성합니다.
spec:
  storageClassName: ""
  accessModes:
    - ReadWriteOnce       # 2.1 속성이 ReadWriteOnce인 퍼시스턴트 볼륨과 연결합니다.
  resources:
    requests:
      storage: 5Gi          # 2.2 볼륨 크기가 최소 5Gi인 퍼시스턴트 볼륨과 연결합니다.
---
apiVersion: v1
kind: Pod
metadata:
  name: ebs-mount-container
spec:
  containers:
    - name: ebs-mount-container
      image: busybox
      args: [ "tail", "-f", "/dev/null" ]
      volumeMounts:
      - name: ebs-volume
        mountPath: /mnt
  volumes:
  - name : ebs-volume
    persistentVolumeClaim:
      claimName: my-ebs-pvc    # 3. my-ebs-pvc라는 이름의 pvc를 사용합니다.

PVC 선택 조건

accessMode

accessMode descrption
ReadWriteOnce RWO 1:1 마운트 / 읽기 쓰기 가능
ReadOnlyMany ROX 1:N 마운트 / 읽기 전용
ReadWriteMany RWX 1:N 마운트 / 읽기 쓰기 가능

storage

storageClassName / label Selector

LifeCycle

Reclaim Policy

다이나믹 프로비저닝

storageClass