Deploy the web-service helm chart on Kubernetes
TypeScriptTo deploy a Helm chart on a Kubernetes cluster using Pulumi, you can make use of the
kubernetes.helm.v3.Chart
resource. This resource allows you to deploy a Helm chart from various sources such as a Helm repository, a local Helm chart, etc.Below you'll find a Pulumi TypeScript program that demonstrates how to deploy a web-service Helm chart to a Kubernetes cluster. Make sure you have Pulumi installed, have access to a Kubernetes cluster, and your kubeconfig is properly set up to point to this cluster.
Firstly, the program will start by importing the required packages. We will use the
@pulumi/kubernetes
package to interact with Kubernetes and deploy the Helm chart.Next, we'll create a new
Chart
resource, specifying thechart
name, which should match the name of the Helm chart you wish to deploy, and theversion
of the chart. If the chart is available in a Helm repository, you need to set therepo
property with the repository URL. In addition, you can providevalues
in the form of a JavaScript object that correspond to the values you would set in avalues.yaml
file when using Helm directly.The
namespace
property is optional, and if not set, the chart will be installed in the default namespace. If you wish to install it in a specific namespace, make sure to specify the namespace in this property.Here is the TypeScript program:
import * as pulumi from "@pulumi/pulumi"; import * as k8s from "@pulumi/kubernetes"; // The name of the Helm chart to deploy. Replace with your desired chart name const chartName = "web-service"; // The version of the Helm chart to deploy. Replace with your desired chart version const chartVersion = "1.0.0"; // This should match the version of the chart you want to deploy // Optionally, if your Helm chart is in a private repository, specify the repository URL here const chartRepo = "http://myhelmrepo.example.com/"; // Optionally, set the namespace where you want to deploy your chart const ns = "my-namespace"; // Values for the Helm release. // These values correspond to the values you would set in a `values.yaml` file. const helmValues = { service: { type: "LoadBalancer", port: 80, }, // ... add more configuration based on the web-service chart ... }; // Create a Helm Chart resource using the `Chart` class. This will deploy the chart to your cluster. const webServiceChart = new k8s.helm.v3.Chart(chartName, { chart: chartName, version: chartVersion, repo: chartRepo, namespace: ns, values: helmValues, }, { dependsOn: [/* other resources such as a namespace the chart might depend on */] }); // Export the public IP of the LoadBalancer from the `web-service` chart export const webServicePublicIP = webServiceChart.getResourceProperty("v1/Service", "web-service", "status") .apply(status => status.loadBalancer?.ingress[0]?.ip || status.loadBalancer?.ingress[0]?.hostname);
Replace
"web-service"
with the name of the actual Helm chart you want to deploy, and make necessary adjustments to thehelmValues
object as per the configurations your chart provides.This program assumes that you have a running Kubernetes cluster and have configured Pulumi to have access to your kubeconfig file. After running this Pulumi program, it will perform a Helm install for the specified chart.
Finally, it's also exporting the public IP address of the service assuming it creates a Kubernetes Service of type
LoadBalancer
. If your service type is different or you need to export other values, adjust this section accordingly.To run this program:
- Save the code to a file with a
.ts
extension, such asindex.ts
. - Run
pulumi up
in the command line within the same directory as your file. - Pulumi will print out the planned changes and ask for confirmation before applying them to the cluster.
Always ensure that you have the latest
@pulumi/kubernetes
library installed and that you have access to a Kubernetes cluster.- Save the code to a file with a