1. Answers
  2. Building a Kubernetes YAML ConfigGroup with Pulumi

How do I build a Kubernetes yaml configgroup with Pulumi?

In this guide, we will demonstrate how to build a Kubernetes YAML ConfigGroup using Pulumi. A ConfigGroup allows you to define multiple Kubernetes resources from YAML or JSON files. This is useful for managing complex configurations and deploying multiple resources in a single step.

Key Points:

  • We will use the @pulumi/kubernetes package to manage Kubernetes resources.
  • The ConfigGroup resource will be used to load and apply multiple YAML configurations.
  • The example will include creating a ConfigMap and a Deployment from YAML files.
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";

// Define the YAML configuration as a string
const configYaml = `
apiVersion: v1
kind: ConfigMap
metadata:
  name: example-config
data:
  example.property.1: "value1"
  example.property.2: "value2"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: example
  template:
    metadata:
      labels:
        app: example
    spec:
      containers:
      - name: example
        image: nginx
        ports:
        - containerPort: 80
`;

// Create a ConfigGroup to manage the resources defined in the YAML string
const configGroup = new k8s.yaml.ConfigGroup("example-config-group", {
    yaml: configYaml,
});

// Export the name of the ConfigMap and Deployment
export const configMapName = configGroup.getResource("v1/ConfigMap", "example-config").metadata.name;
export const deploymentName = configGroup.getResource("apps/v1/Deployment", "example-deployment").metadata.name;

Summary:

In this example, we created a Kubernetes YAML ConfigGroup using Pulumi. We defined a ConfigMap and a Deployment in a YAML string and applied them using the ConfigGroup resource from the @pulumi/kubernetes package. This approach allows you to manage multiple Kubernetes resources efficiently using Pulumi.

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