Docker and k8s: k8s volumes 'StorageClass'

Peter Jeon·2023년 4월 17일

Docker and k8s

목록 보기
12/41

Kubernetes StorageClass

In this blog post, we'll explore StorageClass, a Kubernetes (k8s) concept that enables dynamic provisioning of storage resources within a cluster.

What is StorageClass?

What is StorageClass?

A StorageClass is a Kubernetes abstraction that defines different types of storage resources available in a cluster. StorageClasses make it easy to dynamically provision Persistent Volumes (PVs) for Persistent Volume Claims (PVCs) based on their requirements, without manual intervention from the cluster administrator.

Creating a StorageClass

Creating a StorageClass

To create a StorageClass, you need to define a configuration file in YAML format. Here's an example configuration file for a StorageClass using the AWS EBS storage provider:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: my-aws-ebs-storageclass
provisioner: kubernetes.io/aws-ebs
parameters:
  type: gp2
  fsType: ext4

Using StorageClass with PVCs

To use a StorageClass with a PVC, you need to specify the storageClassName in the PVC definition:

Copy code
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-aws-ebs-pvc
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: my-aws-ebs-storageclass

Default StorageClass

In a Kubernetes cluster, you can designate a default StorageClass. When a PVC is created without specifying a storageClassName, the default StorageClass will be used to dynamically provision a PV. To set a StorageClass as the default, add the storageclass.kubernetes.io/is-default-class annotation with a value of "true" in the StorageClass definition:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: my-default-storageclass
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
provisioner: kubernetes.io/aws-ebs
parameters:
  type: gp2
  fsType: ext4

Conclusion

Kubernetes StorageClass is a powerful feature that simplifies storage management in a cluster by enabling dynamic provisioning of Persistent Volumes. By utilizing StorageClasses, developers can quickly and easily request storage resources without manual intervention from administrators.

profile
As a growing developer, I am continually expanding my skillset and knowledge, embracing new challenges and technologies

0개의 댓글