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:
- Add a storage class and configure it to use your storage.
- 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:
Name | Plugin |
---|---|
Amazon EBS Disk | aws-ebs |
AzureFile | azure-file |
AzureDisk | azure-disk |
Google Persistent Disk | gce-pd |
Longhorn | flex-volume-longhorn |
VMware vSphere Volume | vsphere-volume |
Local | local |
Network File System | nfs |
hostPath | host-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.
- Click ☰ > Cluster Management.
- Go to the cluster where you want to dynamically provision persistent storage volumes and click Explore.
- Click Storage > Storage Classes.
- Click Create.
- Enter a name for your storage class.
- 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. - 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.
- 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.
- Click ☰ > Cluster Management.
- Go to the cluster where you want to add use the StorageClass for a workload and click Explore.
- In the left navigation bar, click Workload.
- Click Create.
- Click StatefulSet.
- In the Volume Claim Templates tab, click Add Claim Template.
- Enter a name for the persistent volume.
- In the *StorageClass field, select the StorageClass that will dynamically provision storage for pods managed by this StatefulSet.
- In the Mount Point field, enter the path that the workload will use to access the volume.
- 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,
- Click ☰ > Cluster Management.
- Go to the cluster where you want to add use the StorageClass for a workload and click Explore.
- In the left navigation bar, click Workload.
- Go to the workload that will use storage provisioned with the StorageClass that you cared at click ⋮ > Edit Config.
- In the Volume Claim Templates section, click Add Claim Template.
- Enter a persistent volume name.
- In the *StorageClass field, select the StorageClass that will dynamically provision storage for pods managed by this StatefulSet.
- In the Mount Point field, enter the path that the workload will use to access the volume.
- 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.