1. Answers
  2. Setting up a Kubernetes Secret

How do I set up a Kubernetes secret?

To set up a Kubernetes Secret using Pulumi, you will need to define the secret data and create the secret resource in your Pulumi program. Below is a complete example of how to do this using TypeScript.

import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";

// Define the secret data
const secretData = {
    username: Buffer.from("my-username").toString("base64"),
    password: Buffer.from("my-password").toString("base64"),
};

// Create the Kubernetes secret
const mySecret = new k8s.core.v1.Secret("my-secret", {
    metadata: {
        name: "my-secret",
        namespace: "default",  // Change this to your desired namespace
    },
    data: secretData,
    type: "Opaque",
});

// Export the secret name
export const secretName = mySecret.metadata.name;

In this example, we first import the necessary Pulumi and Kubernetes packages. We then define the secret data, encoding the values in base64 format as required by Kubernetes. Next, we create a Kubernetes Secret resource with the specified metadata and data. Finally, we export the name of the secret.

This program sets up a Kubernetes secret in the specified namespace with the provided data. The secret can then be used by your Kubernetes applications to securely access sensitive information.

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