How to define the storage class on kubernetes manifest

Written by teamember02
Updated 9 months ago

n Kubernetes, a StorageClass is used to define different classes of storage, such as performance characteristics or provisioner-specific parameters. Here's how you can define a StorageClass:

  1. Create a YAML file: You'll typically define your StorageClass in a YAML file. Open a text editor and create a new file.

  2. Define the StorageClass:

    Here's a basic example of a StorageClass definition:

    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: <storage-class-name>
    provisioner: <provisioner-name>
    

    Replace <storage-class-name> with the desired name for your StorageClass, and <provisioner-name> with the name of the provisioner responsible for creating volumes of this class.

  3. Configure Parameters:

    Depending on your storage provider and requirements, you may need to specify additional parameters in the StorageClass definition. For example, you might define parameters for volume size, access modes, reclaim policies, etc. Here's an example with some common parameters:

    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: <storage-class-name>
    provisioner: <provisioner-name>
    parameters:
      type: <storage-type>
      size: <volume-size>
      accessMode: <access-mode>
      reclaimPolicy: <reclaim-policy>
    
    • <storage-type>: Specify the type of storage, such as gp2 for AWS EBS volumes or standard for GCE Persistent Disks.
    • <volume-size>: Specify the size of the volumes to be provisioned.
    • <access-mode>: Specify the access mode required for the volumes, such as ReadWriteOnce, ReadOnlyMany, or ReadWriteMany.
    • <reclaim-policy>: Specify the reclaim policy for the volumes, such as Retain or Delete.
  4. Save the YAML File:

    Save the YAML file with a descriptive name, such as storage-class.yaml.

  5. Apply the Configuration:

    Apply the StorageClass configuration to your Kubernetes cluster using the kubectl apply command:

    kubectl apply -f storage-class.yaml
    

    This command will create the StorageClass in your cluster based on the definition provided in the YAML file.

Once applied, your StorageClass will be available for use by PersistentVolumeClaims (PVCs) within your Kubernetes cluster. When creating PVCs, you can specify the StorageClass to indicate the desired class of storage to use.

Did this answer your question?