본문 바로가기
IT 잡지식/DevOps

[CKA] KodeKloud - Storage Class

by 쯀리♥️ 2024. 7. 29.

 

 

안녕하세요, 쯀리입니다.

오늘은 Storage Class에 대해 알아보겠습니다. 

https://kubernetes.io/docs/concepts/storage/storage-classes/

 

Storage Classes

This document describes the concept of a StorageClass in Kubernetes. Familiarity with volumes and persistent volumes is suggested. A StorageClass provides a way for administrators to describe the classes of storage they offer. Different classes might map t

kubernetes.io

 


 

Storage Class

Storage Class는 클러스터 내에서 스토리지 프로비저닝을 동적으로 관리하는 방법을 정의하는 중요한 개념입니다. Storage Class를 통해 사용자들은 다양한 스토리지 유형을 필요에 따라 자동으로 할당받을 수 있습니다. Storage Class에 대해 배울 때 다루게 되는 주요 내용은 다음과 같습니다:

1. Storage Class 개념 이해

  • Storage Class 정의: Storage Class는 클러스터 관리자가 생성하며, 특정 스토리지 유형(예: SSD, HDD, 네트워크 스토리지 등)을 정의하는 객체입니다.
  • 프로비저닝 정책: Storage Class는 provisioner 필드를 통해 스토리지를 어떻게 프로비저닝할지 정의합니다. 이는 클라우드 제공자별로 또는 로컬 스토리지 공급자에 따라 달라질 수 있습니다.

Quiz.

1.  How many StorageClasses exist in the cluster right now?

controlplane ~ ➜  k get sc
NAME                   PROVISIONER             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
local-path (default)   rancher.io/local-path   Delete          WaitForFirstConsumer   false                  8m23s

 

2. How about now? How many Storage Classes exist in the cluster?
We just created a few new Storage Classes. Inspect them.

controlplane ~ ➜  k get sc
NAME                        PROVISIONER                     RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
local-path (default)        rancher.io/local-path           Delete          WaitForFirstConsumer   false                  9m11s
local-storage               kubernetes.io/no-provisioner    Delete          WaitForFirstConsumer   false                  14s
portworx-io-priority-high   kubernetes.io/portworx-volume   Delete          Immediate              false                  14s

 

3. What is the name of the Storage Class that does not support dynamic volume provisioning?

controlplane ~ ➜  k get sc
NAME                        PROVISIONER                     RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
local-path (default)        rancher.io/local-path           Delete          WaitForFirstConsumer   false                  9m11s
local-storage               kubernetes.io/no-provisioner    Delete          WaitForFirstConsumer   false                  14s
portworx-io-priority-high   kubernetes.io/portworx-volume   Delete          Immediate              false                  14s

  local-storage: kubernetes.io/no-provisioner 
로컬 볼륨은 쿠버네티스 1.30에서 동적 프로비저닝을 지원하지 않습니다.

4. What is the Volume Binding Mode used for this storage class (the one identified in the previous question)?

  local-storage의 Volume Binding Mode는 현재 WaitForFirstConsumer 모드입니다.

 

5. What is the Provisioner used for the storage class called portworx-io-priority-high?

portworx-volume

 

6. Is there a PersistentVolumeClaim that is consuming the PersistentVolume called local-pv?
따로 PVC가 설정되어있지 않습니다. 

ontrolplane ~ ➜  k get pvc
No resources found in default namespace.

controlplane ~ ➜  k get pv
NAME       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM   STORAGECLASS    VOLUMEATTRIBUTESCLASS   REASON   AGE
local-pv   500Mi      RWO            Retain           Available           local-storage   <unset>                          5m40s

 

7. Let's fix that. Create a new PersistentVolumeClaim by the name of local-pvc that should bind to the volume local-pv.
Inspect the pv local-pv for the specs.

PVC: local-pvc
Correct Access Mode?
Correct StorageClass Used?
PVC requests volume size = 500Mi?
controlplane ~ ➜  vi local-pvc.yaml 

controlplane ~ ➜  cat local-pvc.yaml 
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: local-pvc
spec:
  resources:
    requests:
      storage: 500Mi
  accessModes:
    - ReadWriteOnce
  storageClassName: local-storage
  

controlplane ~ ➜  k apply -f local-pvc.yaml 
persistentvolumeclaim/local-pvc created

 

8. What is the status of the newly created Persistent Volume Claim?

controlplane ~ ➜  k get pvc
NAME        STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS    VOLUMEATTRIBUTESCLASS   AGE
local-pvc   Pending                                      local-storage   <unset>                 11s

 

9. Why is the PVC in a pending state despite making a valid request to claim the volume called local-pv?
Inspect the PVC events.

controlplane ~ ➜  k describe pvc local-pvc 
Name:          local-pvc
Namespace:     default
StorageClass:  local-storage
Status:        Pending
Volume:        
Labels:        <none>
Annotations:   <none>
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      
Access Modes:  
VolumeMode:    Filesystem
Used By:       <none>
Events:
  Type    Reason                Age                   From                         Message
  ----    ------                ----                  ----                         -------
  Normal  WaitForFirstConsumer  15s (x18 over 4m24s)  persistentvolume-controller  waiting for first consumer to be created before binding

원인: waiting for first consumer to be created before binding

A Pod consuming the volume is not scheduled

10. The Storage Class called local-storage makes use of VolumeBindingMode set to WaitForFirstConsumer. This will delay the binding and provisioning of a PersistentVolume until a Pod using the PersistentVolumeClaim is created.

11. Create a new pod called nginx with the image nginx:alpine. The Pod should make use of the PVC local-pvc and mount the volume at the path /var/www/html. The PV local-pv should be in a bound state.

Pod created with the correct Image?
Pod uses PVC called local-pvc?
local-pv bound?
nginx pod running?
Volume mounted at the correct path?
controlplane ~ ➜  vi nginx.yaml 

controlplane ~ ➜  cat nginx.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  volumes:
    - name: local-pvc
      persistentVolumeClaim:
        claimName: local-pvc
  containers:
    - name: nginx
      image: nginx:alpine
      volumeMounts:
        - mountPath: "/var/www/html"
          name: local-pvc
          
          
controlplane ~ ➜  k apply -f nginx.yaml 
pod/nginx created

 

12. What is the status of the local-pvc Persistent Volume Claim now?

controlplane ~ ➜  k get pvc
NAME        STATUS   VOLUME     CAPACITY   ACCESS MODES   STORAGECLASS    VOLUMEATTRIBUTESCLASS   AGE
local-pvc   Bound    local-pv   500Mi      RWO            local-storage   <unset>                 11m

 

13. Create a new Storage Class called delayed-volume-sc that makes use of the below specs:

provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

Storage Class uses: kubernetes.io/no-provisioner ?
Storage Class volumeBindingMode set to WaitForFirstConsumer
controlplane ~ ➜  vi delayed-volume-sc.yaml 

controlplane ~ ➜  cat delayed-volume-sc.yaml 
###
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: delayed-volume-sc
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
###

controlplane ~ ➜  k apply -f delayed-volume-sc.yaml 
storageclass.storage.k8s.io/delayed-volume-sc created

controlplane ~ ➜  k get sc
NAME                        PROVISIONER                     RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
local-path (default)        rancher.io/local-path           Delete          WaitForFirstConsumer   false                  35m
local-storage               kubernetes.io/no-provisioner    Delete          WaitForFirstConsumer   false                  27m
portworx-io-priority-high   kubernetes.io/portworx-volume   Delete          Immediate              false                  27m
delayed-volume-sc           kubernetes.io/no-provisioner    Delete          WaitForFirstConsumer   false                  5s

Kubernetes에서 Storage Class는 클러스터 내에서 스토리지 프로비저닝을 효율적으로 관리하고, 다양한 스토리지 요구사항을 충족시키는 방법을 이해할 수 있습니다. Storage Class를 사용하여 동적 스토리지 프로비저닝, 다양한 스토리지 유형 지원, 그리고 애플리케이션 요구사항에 맞는 스토리지 제공 등의 기능을 구현할 수 있습니다.

 


참조

 Udemy Labs - Certified Kubernetes Administrator with Practice Tests

'IT 잡지식 > DevOps' 카테고리의 다른 글

[CKA] KodeKloud - CNI  (0) 2024.08.08
[CKA] KodeKloud - Explore Environment  (0) 2024.08.08
[CKA] KodeKloud - Persistent Volume Claims  (0) 2024.07.28
[CKA] KodeKloud - Network Policy  (0) 2024.07.28
[CKA] KodeKloud - Security Contexts  (0) 2024.07.24