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 this page.
To provision new storage for your workloads, follow these steps:
- Add a storage class and configure it to use your storage.
- Add a persistent volume claim that refers to the storage class.
- Mount the persistent volume claim as a volume for your workload.
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.
Go to the Cluster Explorer of the cluster for which you want to dynamically provision persistent storage volumes.
From the cluster view, select
Storage > Storage Classes
. ClickAdd Class
.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 theAmazon EBS Disk
provisioner.From the
Parameters
section, 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
Save
.
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. Add a persistent volume claim that refers to the storage class
These steps describe how to set up a PVC in the namespace where your stateful workload will be deployed.
Go to the Cluster Manager to the project containing a workload that you want to add a PVC to.
From the main navigation bar, choose Resources > Workloads. (In versions before v2.3.0, choose Workloads on the main navigation bar.) Then select the Volumes tab. Click Add Volume.
Enter a Name for the volume claim.
Select the Namespace of the volume claim.
In the Source field, click Use a Storage Class to provision a new persistent volume.
Go to the Storage Class drop-down and select the storage class that you created.
Enter a volume Capacity.
Optional: Expand the Customize section and select the Access Modes that you want to use.
Click Create.
Result: Your PVC is created. You can now attach it to any workload in the project.
3. Mount the persistent volume claim as a volume for your workload
Mount PVCs to workloads so that your applications can store their data.
You can mount PVCs during the deployment of a workload, or following workload creation.
To attach the PVC to a new workload,
- Create a workload as you would in Deploying Workloads.
- For Workload Type, select Stateful set of 1 pod.
- Expand the Volumes section and click Add Volume > Use an Existing Persistent Volume (Claim).
- In the Persistent Volume Claim section, select the newly created persistent volume claim that is attached to the storage class.
- In the Mount Point field, enter the path that the workload will use to access the volume.
- Click Launch.
Result: When the workload 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 the PVC.
To attach the PVC to an existing workload,
- Go to the project that has the workload that will have the PVC attached.
- Go to the workload that will have persistent storage and click ⋮ > Edit.
- Expand the Volumes section and click Add Volume > Use an Existing Persistent Volume (Claim).
- In the Persistent Volume Claim section, select the newly created persistent volume claim that is attached to the storage class.
- 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.