Deploy the vid helm chart on Kubernetes
TypeScriptTo deploy a Helm chart on a Kubernetes cluster using Pulumi, you will use the
Chart
resource from the@pulumi/kubernetes
package. This resource allows you to install, configure, and manage Kubernetes applications defined by Helm charts.Before we dive into the code, here's an overview of what we'll do:
- Import the required Pulumi and Kubernetes packages.
- Instantiate a
Chart
resource to deploy our Helm chart.
Below is the complete TypeScript program to deploy the 'vid' Helm chart:
import * as k8s from "@pulumi/kubernetes"; // Create a namespace for the 'vid' chart, if you want to isolate it within the cluster. // Feel free to omit this step if you are deploying to the default namespace or an existing namespace. const ns = new k8s.core.v1.Namespace("vid-namespace", { metadata: { name: "vid-ns" } }); // Deploy the 'vid' Helm chart into the created namespace. const vidChart = new k8s.helm.v3.Chart("vid", { // Chart name which you want to deploy chart: "vid", // Optionally, specify the Helm chart version you want to deploy version: "1.0.0", // Specify the namespace where you want to deploy your Helm chart namespace: ns.metadata.name, // Values to provide to the Helm chart // The values here are just placeholders and need to be replaced with the real values required by the 'vid' Helm chart. values: { service: { type: "ClusterIP" } }, // Add a transformation to the Chart resources, if needed transformations: [ (resource) => { if (resource.kind === "Deployment") { resource.metadata.namespace = ns.metadata.name; } }, ] }, { dependsOn: [ns] }); // Exports the namespace and Chart name, these will show up after deployment in the pulumi stack output export const namespaceName = ns.metadata.name; export const chartName = vidChart.metadata.name;
Explanation:
-
Namespace Creation: It's a good practice to deploy your applications into a dedicated namespace for better isolation and management. Here, we've created a namespace specifically for the 'vid' application.
-
Chart Deployment: This block uses the
Chart
resource to deploy the Helm chart. We specify the chart name (vid
), the version, and the namespace to which we want to deploy it. We also provide a values object, which represents any overrides to the default values that the Helm chart provides. Thetransformations
function here is optional–used if you need to modify the properties of Kubernetes resources created by the Helm chart before they are deployed.
Things to Note:
-
Helm Chart Repository: The
chart
property specifies only the Helm chart name. If the 'vid' chart is in a Helm repository other than the default stable repository, you must also specify therepo
property with the repository URL. -
Helm Chart Version: Replace
"1.0.0"
with the correct version of the 'vid' chart you wish to deploy. If you are uncertain about the chart version, you can leave out theversion
field to deploy the latest version. -
Values Object: Update the
values
object with configurations required by the 'vid' chart. This is how you can customize the deployment specifications, such as service type, resource limits, replica count, image version, etc. You'll need to refer to the chart's documentation or values.yaml file to know what values can be specified. -
Dependency on Namespace: The
{ dependsOn: [ns] }
argument ensures the namespace is created before Pulumi attempts to deploy the Helm chart.
After you've written your Pulumi program, you can deploy it using the Pulumi CLI commands
pulumi up
to create or update resources. After the deployment, you can inspect the output vars withpulumi stack output
. Remember to first authenticate with your cluster; how you do this depends on your cloud provider and Kubernetes setup.