Skip to main content

Search the Dev Center

Search tutorials, templates, examples, and more.

Helm Chart on Kubernetes

The Helm Chart template scaffolds a Pulumi project that deploys a Helm chart to an existing Kubernetes cluster using Pulumi’s Kubernetes provider. The template creates a new namespace in the cluster and installs an Nginx ingress controller as the default chart, so the project deploys end to end out of the box.

Architecture diagram of the Helm Chart template Kubernetes Cluster Namespace Service Ingress Controller Deployment

Before you begin#

Create a new project#

Create a new project using the template in the language of your choice:

Terminal window
mkdir my-k8s-app && cd my-k8s-app
pulumi new helm-kubernetes-typescript

pulumi new walks you through creating and configuring a new project and stack. A stack is an instance of a project and you can have many of them — dev, staging, prod — each with its own configuration settings.

Then it asks for the template’s setting:

KeyDescriptionDefault
k8sNamespaceThe Kubernetes namespace to deploy intonginx-ingress
You can change these settings later with pulumi config set:
Terminal window
pulumi config set k8sNamespace <value>

When setup completes, you’ll see a few key files:

  • Pulumi.yaml names the project and the language it’s written in.
  • Pulumi.dev.yaml holds the dev stack’s settings, including the values you just entered.
  • index.ts is the program: the code that declares your Kubernetes resources.

Deploy the project#

The program installs the chart into the cluster your current kubeconfig context points at. Check which cluster that is before you deploy:

Terminal window
kubectl config current-context

Deploy with pulumi up. It starts with a preview of what it’s about to create and asks before it changes anything. Choose yes to deploy.

Terminal window
pulumi up

Pulumi adds a random suffix to most resource names, so the Helm release ingresscontroller becomes something like ingresscontroller-4f8a2c1d. This is autonaming. It lets you deploy the same program to more than one stack, and lets Pulumi create a replacement before it deletes the old resource, without names colliding. The namespace is the exception: the program names it from k8sNamespace, so it’s called exactly what you entered (nginx-ingress by default).

When it finishes, Pulumi prints the stack’s outputs, values it only knows once the resources exist:

name

The name of your new Helm chart deployment.

Read one any time with pulumi stack output <name>, or pass it to another command. To check the result, list the pods in the namespace (use yours if you didn’t keep nginx-ingress). The ingress controller’s pod shows Running once it’s up:

Terminal window
kubectl get pods -n nginx-ingress

Customize the project#

Projects created with the Helm Chart template expose the following configuration settings:

k8sNamespace

The name of the namespace to be created in your existing cluster. Defaults to nginx-ingress.

All of these settings are optional and may be adjusted either by editing the stack configuration file directly (by default, Pulumi.dev.yaml) or by changing their values with pulumi config set. For example, move the chart to a namespace called my-namespace:

Terminal window
pulumi config set k8sNamespace my-namespace
pulumi up

Pulumi installs the chart in the new namespace and deletes the old one. The controller’s pod now runs in my-namespace:

Terminal window
kubectl get pods -n my-namespace

You can customize the Helm chart by passing values to it in your Pulumi code. An example of passing a few values to the chart is included in the template for reference.

To see what else you can add, browse the Kubernetes provider in the Pulumi Registry.

Cleaning up#

You can cleanly destroy the stack and all of its infrastructure with pulumi destroy:

Terminal window
pulumi destroy

Learn more#

Related

The infrastructure as code platform for any cloud.