StorageClass

Module

A StorageClass provides a way for administrators to describe the “classes” of storage they offer.

Overview

At the end of this module, you will :

  • Learn to persist data thanks to a dynamic volumes

  • Learn to manage the volumes and the claim

  • Learn to access data within a container

Prerequisites

Create the directory data/storageclass in your home folder to manage the YAML file needed in this module.

mkdir ~/data/storageclass

Create

StorageClasses are the foundation of dynamic provisioning, allowing cluster administrators to define abstractions for the underlying storage platform. Users simply refer to a StorageClass by name in the PersistentVolumeClaim (PVC) using the “storageClassName” parameter.

Storage is a critical part of running stateful containers, and Kubernetes offers powerful primitives for managing it. Dynamic volume provisioning, a feature unique to Kubernetes, allows storage volumes to be created on-demand. The storage resources can be dynamically provisioned using the provisioner specified by the StorageClass object.

StorageClasses are essentially blueprints that abstract away the underlying storage provider, as well as other parameters, like disk-type.

The create command can create a StorageClass object based on a yaml file definition.

Exercise n°1

Create a StorageClass object to automatically use the AWS EBS volumes.

~/data/storageclass/01_storageclass.yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: aws-ebs-gp2
provisioner: kubernetes.io/aws-ebs
parameters:
  type: gp2
reclaimPolicy: Retain
mountOptions:
  - debug
volumeBindingMode: Immediate

Create the resource based on the previous yaml definition file.

kubectl create -f ~/data/storageclass/01_storageclass.yaml

Get

The get command list the object asked. It could be a single object or a list of multiple objects comma separated. This command is useful to get the status of each object. The output can be formatted to only display some information based on some json search or external tools like tr, sort, uniq.

The default output display some useful information about each services :

  • Name : the name of the newly created resource

  • Provisioner : the target storage provisioner used to create the futur volumes

  • Age : the age since his creation

Exercise n°1

Get the information of a Storage Class deployed in the default namespace.

kubectl get storageclass

Describe

Once an object is running, it is inevitably a need to debug problems or check the configuration deployed.

The describe command display a lot of configuration information about the StorageClass (labels, annotations, etc.) and the class definition depending on the external storage service (provider, access, type ...).

This command is really useful to introspect and debug an object deployed in a cluster.

Exercise n°1

Describe one of the existing StorageClass in the default namespace.

kubectl describe storageclass aws-ebs-gp2

Explain

Kubernetes come with a lot of documentation about his objects and the available options in each one. Those information can be fin easily in command line or in the official Kubernetes documentation.

The explain command allows to directly ask the API resource via the command line tools to display information about each Kubernetes objects and their architecture.

Exercise n°1

Get the documentation of a specific field of a resource.

kubectl explain storageclass

Add the --recursive flag to display all of the fields at once without descriptions.

Default Storage Class

The default Storage Class is defined by an annotation set to true : storageclass.kubernetes.io/is-default-class

This parameter can be updated in command line or by editing the yaml file of each Storage Class. If a Storage Class already exist, it is needed to disable the annotation to enable it on another object.

Exercise n°1

  1. Disable the default StorageClass in the default namespace.

  2. Configure the previous StorageClass created as default

# Disable the current default StorageClass
kubectl patch storageclass CURRENT_DEFAULT_STORAGECLASS_NAME -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'
 
# Configure the new default StorageClass
kubectl patch storageclass NEW_DEFAULT_STORAGECLASS_NAME -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}' 

Delete

The delete command delete resources by filenames, stdin, resources and names, or by resources and label selector.

A StorageClass can only be deleted if it is not used by a running storage object.

Note that the delete command does NOT do resource version checks, so if someone submits an update to a resource right when you submit a delete, their update will be lost along with the rest of the resource.

Exercise n°1

Delete the previous storage class in command line.

kubectl delete storageclasses aws-ebs-gp2

Module exercise

The purpose of this section is to manage each steps of the lifecycle of an application to better understand each concepts of the Kubernetes course.

The main objective in this module is to understand how to dynamically share a storage object to persist and share data of Pods.

For more information about the application used all along the course, please refer to the Exercise App > Voting App link in the left panel.

Based on the principles explain in this module, try by your own to handle this steps. The development of a yaml file is recommended.

The file developed has to be stored in this directory : ~/data/votingapp/08_storageclass

  1. Create a StorageClass based on the cloud provider.

  2. Create a PersistentVolumeClaim to consume that StorageClass and create a storage object capacity of 10Gi.

  3. Update the database Deployment to attach the previous PersistentVolumeClaim created.

External documentation

Those documentations can help you to go further in this topic :

Last updated