Deploy the workshop-exercise helm chart on Kubernetes
TypeScriptWhen you want to deploy a Helm chart on a Kubernetes cluster using Pulumi, you'll use the
Chart
resource from the Pulumi Kubernetes provider. Helm charts are packages for Kubernetes resources. A Helm chart includes all necessary resource definitions to run an application, tool, or service inside a Kubernetes cluster. When you use Pulumi to deploy a Helm chart, you're effectively describing your Kubernetes resources declaratively in code and managing them alongside your infrastructure.Here's an example that demonstrates how to deploy a Helm chart with the hypothetical name
workshop-exercise
:import * as k8s from "@pulumi/kubernetes"; // Assuming you have a Kubernetes cluster already provisioned and configured with the necessary credentials available to Pulumi. // Create a new instance of the 'Chart' resource which represents a Helm chart. // Replace the `repo` property with the Helm chart's repository URL if it's hosted remotely and not included in the default Helm repos. // Use the `version` property to specify the specific chart version, if needed. const workshopExerciseChart = new k8s.helm.v3.Chart("workshop-exercise", { // 'chart' specifies the name of the chart. You might need to prepend it with the repository name if it's not in the default repo. chart: "workshop-exercise", // Uncomment and set the 'repo' property if your chart is in a custom Helm repository. // repo: "https://my-helm-repo.example.com", // 'namespace' specifies the Kubernetes namespace to deploy the chart in. If omitted, it defaults to 'default'. // If the namespace doesn't exist, you'll need to create it separately or set 'createNamespace' to true. namespace: "workshop-ns", // 'values' is a set of configuration values that are passed to the Helm chart. values: { // Customize your Helm chart's values here. These values override the ones in the Helm chart's `values.yaml` file. // It could be something like the application's image version, resource limits, or any other configurable option. // exampleKey: exampleValue, }, }); // Exporting the resources that the Helm chart created. // This make them accessible outside of Pulumi and can be handy for CI/CD integration or manual inspection. export const chartResources = workshopExerciseChart.resources;
In the Pulumi program above, I used the
@pulumi/kubernetes
package to utilize the Kubernetes SDK for Pulumi. TheChart
class represents a deployment of a Helm chart in your Kubernetes cluster. When the Pulumi program is applied, it will tell Helm to deploy theworkshop-exercise
chart in theworkshop-ns
namespace with the specified configuration.The
values
property in theChart
class allows you to override or set configuration options that are specific to this particular deployment. These will typically correspond to values in the chart'svalues.yaml
file, which contains the default settings.Finally, exporting
chartResources
allows you to see a list of the Kubernetes resources the Helm chart created when you runpulumi up
, which could be useful for debugging or understanding exactly what resources were deployed by the chart.To run this Pulumi program, you would save the above TypeScript code to a file (for instance,
index.ts
), and then executepulumi up
in the terminal within your Pulumi project directory. This command initializes a Pulumi deployment which applies the code and provisions the resources on the cloud provider, which in this case is the Kubernetes cluster configured in your environment.Note that you'll need Node.js and Pulumi installed to use TypeScript with Pulumi. Additionally, you'll need access configured to your Kubernetes cluster, typically via a
kubeconfig
file, for Pulumi to interact with your cluster.