1. Answers
  2. Configuring a Kubernetes Core ConfigMap

How do I configure a Kubernetes core configmap?

In this example, you’ll learn how to create and configure a Kubernetes ConfigMap. A ConfigMap is used to store non-confidential data in key-value pairs. Pods can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume.

Here’s how you can create a ConfigMap to store some configuration data:

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

// Define the namespace
const example = new kubernetes.core.v1.Namespace("example", {metadata: {
    name: "example-namespace",
}});
// Define the ConfigMap
const exampleConfigMap = new kubernetes.core.v1.ConfigMap("example", {
    metadata: {
        name: "example-config",
        namespace: example.metadata.apply(metadata => metadata.name),
    },
    data: {
        exampleKey: "example_value",
        anotherKey: "another_value",
    },
});
export const configMapName = exampleConfigMap.metadata.apply(metadata => metadata.name);
export const configMapNamespace = exampleConfigMap.metadata.apply(metadata => metadata.namespace);

What we did in this program:

  • Configured the Kubernetes provider, specifying to use the default kubeconfig file.
  • Created a namespace named “example-namespace”.
  • Created a ConfigMap named “example-config” within the “example-namespace” namespace, containing key-value pair data entries.
  • Exported the ConfigMap name and namespace as outputs.

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