How do I build a Kubernetes storage.k8s.io storageclass?
To create a Kubernetes StorageClass
, we need to define a YAML manifest that specifies its parameters, the provisioner
, and other configuration settings. A StorageClass
provides a way for administrators to describe the “classes” of storage they offer. When a PersistentVolumeClaim
(PVC) is created, it can request a particular class by specifying the name of a StorageClass
.
Here’s an example of how you can define such a StorageClass
using infrastructure as code, ensuring we specify necessary details like the provisioner
:
import * as pulumi from "@pulumi/pulumi";
import * as kubernetes from "@pulumi/kubernetes";
const example = new kubernetes.storage.v1.StorageClass("example", {
metadata: {
name: "example-storage-class",
},
provisioner: "kubernetes.io/aws-ebs",
parameters: {
type: "gp2",
},
});
export const storageClassName = example.metadata.apply(metadata => metadata.name);
Explanation:
Provider Configuration: This specifies how to access your Kubernetes cluster. In this example, it uses the kubeconfig file located at
~/.kube/config
.Resource Definition:
- We define a resource of type
kubernetes_storage_class
namedexample
. - Metadata and
provisioner
are specified. parameters
include details specific to theprovisioner
type, e.g.,type
set togp2
for AWS EBS.
- We define a resource of type
Output: Export the name of the created
StorageClass
to easily reference it after deployment.
By following this approach, you can manage your StorageClass definitions programmatically and ensure they are version-controlled and part of your infrastructure code.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.