본문 바로가기

CKA &. CKAD/Storage

Volumes and Persistent Volume

 

[volumes]

apiVersion: v1
kind: Pod
metadata:
  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:
    - moutnPath: /opt
      name: data-volume
  volumes:
  - name: data-volume
    hostPath:
        path: /data
        type: directory

AWS EBS를 Volume Storage로 사용하는 경우 아래와 같이 변경한다.

  volumes:
  - name: data-volume
    awsElasticbBlockStore:
      volumeID: <volume-id>
      fsType: ext4

 

[Persistent Volume]

 

 

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-vol1
spec:
  accessModes:
    - ReadWriteOnce
  caapcity:
    storage: 1 Gi
  hostPath:
    path: /tmp/dat

[Persistent Volume Claim]

 

 

 

pvc-definition.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myclaim
spec:
  accessModes:
    -ReadWriteOnce
  resources:
    requests:
      storage: 500Mi

pv-definition.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-vol1
spec:
  accessModes:
    - ReadWriteOnce
  capacity:
    storage: 1Gi
  awsElasticBlockStore:
    volumeID: <volume-id>
    fsType: ext4

 

View PVCs

kubectl get persistentvolumeclaim

Delete PVCs

kubectl delete persistentvoluemclaim myclaim

 

Using PVCs in PODs

 

PVC를 만든 후에는 다음과 같이 POD의 Volume Section의 persistentVolumeClaim 섹션에서 PVC 이름을 지정하여 POD defintion file에서 사용한다.

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
    - name: myfrontend
      image: nginx
      volumeMounts:
      - mountPath: "/var/www/html"
        name: mypd  
  volumes:
    - name: mypd
      persistentVolumeClaim:
        calimName: myclaim

ReplicaSets 또는 Deployment 배포도 마찬가지이다. 이것을 Deployment on ReplicaSet의 POD 템플릿 섹션에 추가한다.

https://kubernetes.io/docs/concepts/storage/persistent-volumes/#claims-as-volumes

 

Persistent Volumes

This document describes the current state of 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 us

kubernetes.io

 

'CKA &. CKAD > Storage' 카테고리의 다른 글

Storage Class  (0) 2021.03.30
Practice Test - Persistent Volumes and Persistent Volume Claims  (0) 2021.03.30
Container Storage Interface  (0) 2021.03.30
Docker storage and Volume  (0) 2021.03.30