Dynamically Provisioning New Storage in Rancher

This section describes how to provision new persistent storage for workloads in Rancher.

This section assumes that you understand the Kubernetes concepts of storage classes and persistent volume claims. For more information, refer to the section on how storage works.

New storage is often provisioned by a cloud provider such as Amazon EBS. However, new storage doesn’t have to be in the cloud.

If you have a pool of block storage, and you don’t want to use a cloud provider, Longhorn could help you provide persistent storage to your Kubernetes cluster. For more information, see Cloud Native Storage with Longhorn.

To provision new storage for your workloads, follow these steps:

  1. Add a storage class and configure it to use your storage.
  2. Use the Storage Class for Pods Deployed with a StatefulSet.

Prerequisites

  • To set up persistent storage, the Manage Volumes role is required.
  • If you are provisioning storage for a cluster hosted in the cloud, the storage and cluster hosts must have the same cloud provider.
  • The cloud provider must be enabled. For details on enabling cloud providers, refer to this page.
  • Make sure your storage provisioner is available to be enabled.

The following storage provisioners are enabled by default:

NamePlugin
Amazon EBS Diskaws-ebs
AzureFileazure-file
AzureDiskazure-disk
Google Persistent Diskgce-pd
Longhornflex-volume-longhorn
VMware vSphere Volumevsphere-volume
Locallocal
Network File Systemnfs
hostPathhost-path

To use a storage provisioner that is not on the above list, you will need to use a feature flag to enable unsupported storage drivers.

1. Add a storage class and configure it to use your storage

These steps describe how to set up a storage class at the cluster level.

  1. Click ☰ > Cluster Management.
  2. Go to the cluster where you want to dynamically provision persistent storage volumes and click Explore.
  3. Click Storage > Storage Classes.
  4. Click Create.
  5. Enter a name for your storage class.
  6. From the Provisioner drop-down, select the service that you want to use to dynamically provision storage volumes. For example, if you have a Amazon EC2 cluster and you want to use cloud storage for it, use the Amazon EBS Disk provisioner.
  7. In the Parameters tab, fill out the information required for the service to dynamically provision storage volumes. Each provisioner requires different information to dynamically provision storage volumes. Consult the service’s documentation for help on how to obtain this information.
  8. Click Create.

Result: The storage class is available to be consumed by a PVC.

For full information about the storage class parameters, refer to the official Kubernetes documentation..

2. Use the Storage Class for Pods Deployed with a StatefulSet

StatefulSets manage the deployment and scaling of Pods while maintaining a sticky identity for each Pod. In this StatefulSet, we will configure a VolumeClaimTemplate. Each Pod managed by the StatefulSet will be deployed with a PersistentVolumeClaim based on this VolumeClaimTemplate. The PersistentVolumeClaim will refer to the StorageClass that we created. Therefore, when each Pod managed by the StatefulSet is deployed, it will be bound to dynamically provisioned storage using the StorageClass defined in its PersistentVolumeClaim.

  1. Click ☰ > Cluster Management.
  2. Go to the cluster where you want to add use the StorageClass for a workload and click Explore.
  3. In the left navigation bar, click Workload.
  4. Click Create.
  5. Click StatefulSet.
  6. In the Volume Claim Templates tab, click Add Claim Template.
  7. Enter a name for the persistent volume.
  8. In the StorageClass field, select the StorageClass that will dynamically provision storage for pods managed by this StatefulSet.
  9. In the Mount Point field, enter the path that the workload will use to access the volume.
  10. Click Launch.

Result: When each Pod managed by the StatefulSet is deployed, it will make a request for the specified amount of disk space to the Kubernetes master. If a PV with the specified resources is available when the workload is deployed, the Kubernetes master will bind the PV to Pod with a compatible PVC.

To attach the PVC to an existing workload,

  1. Click ☰ > Cluster Management.
  2. Go to the cluster where you want to add use the StorageClass for a workload and click Explore.
  3. In the left navigation bar, click Workload.
  4. Go to the workload that will use storage provisioned with the StorageClass that you cared at click ⋮ > Edit Config.
  5. In the Volume Claim Templates section, click Add Claim Template.
  6. Enter a persistent volume name.
  7. In the StorageClass field, select the StorageClass that will dynamically provision storage for pods managed by this StatefulSet.
  8. In the Mount Point field, enter the path that the workload will use to access the volume.
  9. Click Save.

Result: The workload will make a request for the specified amount of disk space to the Kubernetes master. If a PV with the specified resources is available when the workload is deployed, the Kubernetes master will bind the PV to the PVC. If not, Rancher will provision new persistent storage.