1. Answers
  2. Creating a Kubernetes Namespace with Pulumi

How do I create a Kubernetes namespace with Pulumi?

In this guide, we will create a Kubernetes namespace using Pulumi in TypeScript. A namespace in Kubernetes is a way to divide cluster resources between multiple users (via resource quota).

Key Points:

  • We will use the Pulumi Kubernetes provider.
  • We will define and create a namespace in our Kubernetes cluster.
  • The code will be written in TypeScript.
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";

// Create a Kubernetes Namespace
const ns = new k8s.core.v1.Namespace("my-namespace", {
    metadata: {
        name: "my-namespace",
    },
});

// Export the namespace name
export const namespaceName = ns.metadata.name;

Summary

In this example, we created a Kubernetes namespace named my-namespace using Pulumi. We imported the necessary Pulumi and Kubernetes libraries, defined the namespace, and exported its name. This program will create the namespace in the configured Kubernetes cluster when run.

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