Deploy the basic helm chart on Kubernetes
TypeScriptDeploying a Helm chart on a Kubernetes cluster using Pulumi involves several steps, but essentially you need to have a Kubernetes cluster configured, and Pulumi needs access to that cluster to manage the Helm chart deployments. Below, I'll walk you through the Pulumi program that deploys a basic Helm chart into an existing Kubernetes cluster.
The resource we'll use to achieve this is
kubernetes.helm.v3.Chart
. This is a Pulumi resource that represents a Helm chart from either a public or private repository (or even from a local path). It will take care of fetching the Helm chart and applying it to the configured Kubernetes cluster.In this example, we don't specify the cluster because Pulumi uses the default Kubernetes context from your local
~/.kube/config
file. If you're running this in an environment where you want to specify a different context or a kubeconfig file, you need to configure Pulumi’s Kubernetes provider accordingly.Here's the TypeScript program to deploy a basic Helm chart:
import * as k8s from '@pulumi/kubernetes'; // Define the Helm chart repository and the chart details. const chart = new k8s.helm.v3.Chart("nginx", { chart: "nginx", version: "1.16.0", // specify the version of the chart you want to deploy fetchOpts: { repo: "https://charts.bitnami.com/bitnami", // URL of the Helm repository }, // Values to provide to the Helm chart. These values would be the equivalent // of what you'd put in a values.yaml file for configuration. values: { service: { type: "LoadBalancer", }, }, }); export const chartName = chart.metadata.apply(metadata => metadata.name);
This code does the following:
- It imports the necessary Kubernetes package from Pulumi.
- It creates a new Helm chart resource in Pulumi, called
nginx
. - The
chart
property identifies the name of the chart we want from the repository. - The
version
property specifies which version of the chart you want to deploy. - The
repo
url withinfetchOpts
defines which Helm repository to source the chart from. values
are the chart's configurable options. These are equivalent to overrides you might provide in a customvalues.yaml
file.- The exported
chartName
will display the name of the Helm chart once it is deployed.
This code assumes you have access to the cluster through
kubectl
and have previously installed@pulumi/kubernetes
npm package withnpm install @pulumi/kubernetes
.Please note that in real scenarios, your configuration might require additional parameters such as
namespace
if you want to target a specific namespace, and you can provide a long list of overrides withinvalues
to customize your Helm chart as required.When you run this Pulumi program, it will invoke the necessary Helm commands to deploy the chart onto your Kubernetes cluster. If this is the first time you are running it, Pulumi will perform a
helm install
, and on subsequent runs, it will automatically handlehelm upgrade
orhelm delete
as necessary.