본문 바로가기
IT 기술/k8s

[cka] Storage Class

by Geunny 2024. 8. 6.
반응형

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

 

controlplane ~ ➜  k get storageclasses.storage.k8s.io 
NAME                   PROVISIONER             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
local-path (default)   rancher.io/local-path   Delete          WaitForFirstConsumer   false                  6m17s

controlplane ~ ➜  k get storageclasses.storage.k8s.io --no-headers
local-path (default)   rancher.io/local-path   Delete   WaitForFirstConsumer   false   6m27s

controlplane ~ ➜  k get storageclasses.storage.k8s.io --no-headers |  wc -l
1

 

answer : 1

 

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 storageclasses.storage.k8s.io 
NAME                        PROVISIONER                     RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
local-path (default)        rancher.io/local-path           Delete          WaitForFirstConsumer   false                  6m59s
local-storage               kubernetes.io/no-provisioner    Delete          WaitForFirstConsumer   false                  23s
portworx-io-priority-high   kubernetes.io/portworx-volume   Delete          Immediate              false                  23s

controlplane ~ ➜  k get storageclasses.storage.k8s.io --no-headers |  wc -l
3

 

answer : 3

 

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

 

ontrolplane ~ ➜  k describe storageclasses.storage.k8s.io local-path
Name:                  local-path
...
Provisioner:           rancher.io/local-path

controlplane ~ ➜  k describe storageclasses.storage.k8s.io local-storage
Name:            local-storage
...
Provisioner:           kubernetes.io/no-provisioner

controlplane ~ ➜  k describe storageclasses.storage.k8s.io portworx-io-priority-high
Name:            portworx-io-priority-high
...
Provisioner:           kubernetes.io/portworx-volume
...

 

answer : local-storage

 

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

controlplane ~ ➜  k describe storageclasses.storage.k8s.io local-storage
Name:            local-storage
IsDefaultClass:  No
Annotations:     kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{"annotations":{},"name":"local-storage"},"provisioner":"kubernetes.io/no-provisioner","volumeBindingMode":"WaitForFirstConsumer"}

Provisioner:           kubernetes.io/no-provisioner
Parameters:            <none>
AllowVolumeExpansion:  <unset>
MountOptions:          <none>
ReclaimPolicy:         Delete
VolumeBindingMode:     WaitForFirstConsumer
Events:                <none>

 

answer : WaitForFirstConsumer

 

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

controlplane ~ ➜  k describe storageclasses.storage.k8s.io portworx-io-priority-high
Name:            portworx-io-priority-high
IsDefaultClass:  No
Annotations:     kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{"annotations":{},"name":"portworx-io-priority-high"},"parameters":{"priority_io":"high","repl":"1","snap_interval":"70"},"provisioner":"kubernetes.io/portworx-volume"}

Provisioner:           kubernetes.io/portworx-volume
Parameters:            priority_io=high,repl=1,snap_interval=70
AllowVolumeExpansion:  <unset>
MountOptions:          <none>
ReclaimPolicy:         Delete
VolumeBindingMode:     Immediate
Events:                <none>

 

answer : portworx-volume

 

6. Is there a PersistentVolumeClaim that is consuming the PersistentVolume called local-pv?

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

controlplane ~ ➜  k get pvc -A
No resources found

 

answer : No

 

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.

 

https://kubernetes.io/docs/concepts/storage/_print/#persistentvolumeclaims

 

Storage

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

kubernetes.io

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

 

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>                 21s

 

answer : PENDING

 

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  6s (x6 over 70s)  persistentvolume-controller  waiting for first consumer to be created before binding

 

answer :  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.

 

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
    - name: nginx
      image: nginx:alpine
      volumeMounts:
      - mountPath: "/var/www/html"
        name: local-nginx-storage
  volumes:
    - name: local-nginx-storage
      persistentVolumeClaim:
        claimName: local-pvc

 

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>                 6m59s

 

answer : Bound

 

13. Create a new Storage Class called delayed-volume-sc that makes use of the below specs: provisioner: kubernetes.io/no-provisioner volumeBindingMode: WaitForFirstConsumer

 

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: delayed-volume-sc
  annotations:
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

'IT 기술 > k8s' 카테고리의 다른 글

[cka] CNI  (0) 2024.08.09
[cka] Explore Environment  (0) 2024.08.07
[cka] Persistent Volume Claims  (0) 2024.07.28
[cka] Network Policies  (0) 2024.07.28
[cka] Security Contexts  (0) 2024.07.28

댓글