1. Answers
  2. Building a Kubernetes StorageClass

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:

  1. Provider Configuration: This specifies how to access your Kubernetes cluster. In this example, it uses the kubeconfig file located at ~/.kube/config.

  2. Resource Definition:

    • We define a resource of type kubernetes_storage_class named example.
    • Metadata and provisioner are specified.
    • parameters include details specific to the provisioner type, e.g., type set to gp2 for AWS EBS.
  3. 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 up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up