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.
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.
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.
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.
kubectlexplainstorageclass
KIND:StorageClassVERSION:storage.k8s.io/v1DESCRIPTION:StorageClassdescribestheparametersforaclassofstorageforwhichPersistentVolumescanbedynamicallyprovisioned.StorageClassesarenon-namespaced; thenameofthestorageclassaccordingtoetcdisinObjectMeta.Name.FIELDS:allowVolumeExpansion<boolean>AllowVolumeExpansionshowswhetherthestorageclassallowvolumeexpandallowedTopologies<[]Object>Restrictthenodetopologieswherevolumescanbedynamicallyprovisioned.Eachvolumeplugindefinesitsownsupportedtopologyspecifications.AnemptyTopologySelectorTermlistmeansthereisnotopologyrestriction.ThisfieldisonlyhonoredbyserversthatenabletheVolumeSchedulingfeature.apiVersion<string>APIVersiondefinestheversionedschemaofthisrepresentationofanobject.Serversshouldconvertrecognizedschemastothelatestinternalvalue,andmayrejectunrecognizedvalues.Moreinfo:https://git.k8s.io/community/contributors/devel/api-conventions.md#resourceskind<string>KindisastringvaluerepresentingtheRESTresourcethisobjectrepresents.Serversmayinferthisfromtheendpointtheclientsubmitsrequeststo.Cannotbeupdated.InCamelCase.Moreinfo:https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kindsmetadata<Object>Standardobject's metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata mountOptions <[]string> Dynamically provisioned PersistentVolumes of this storage class are created with these mountOptions, e.g. ["ro", "soft"]. Not validated - mount of the PVs will simply fail if one is invalid. parameters <map[string]string> Parameters holds the parameters for the provisioner that should create volumes of this storage class. provisioner <string> -required- Provisioner indicates the type of the provisioner. reclaimPolicy <string> Dynamically provisioned PersistentVolumes of this storage class are created with this reclaimPolicy. Defaults to Delete. volumeBindingMode <string> VolumeBindingMode indicates how PersistentVolumeClaims should be provisioned and bound. When unset, VolumeBindingImmediate is used. This field is only honored by servers that enable the VolumeScheduling feature.
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
Disable the default StorageClass in the default namespace.
Configure the previous StorageClass created as default
# Disable the current default StorageClasskubectl patch storageclass CURRENT_DEFAULT_STORAGECLASS_NAME -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'
# Configure the new default StorageClasskubectl 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.
kubectldeletestorageclassesaws-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
Create a StorageClass based on the cloud provider.
Create a PersistentVolumeClaim to consume that StorageClass and create a storage object capacity of 10Gi.
Update the database Deployment to attach the previous PersistentVolumeClaim created.
Create a StorageClass to consume the AWS Elastic Block Store (EBS).