Deploy the profile helm chart on Kubernetes
TypeScriptTo deploy the "profile" Helm chart on a Kubernetes cluster using Pulumi, we will use the
kubernetes.helm.v3.Chart
resource from the Pulumi Kubernetes provider. TheChart
resource enables you to deploy packaged applications into your Kubernetes cluster. Helm charts are a collection of pre-configured Kubernetes resources that can be deployed as a unit.Here's a Pulumi program to deploy the "profile" Helm chart on a Kubernetes cluster:
import * as k8s from '@pulumi/kubernetes'; // Create a new Helm Chart resource const profileChart = new k8s.helm.v3.Chart("profile", { // Specify the chart repository // Replace this with the actual repository URL where the profile chart is located // In this example, we assume "https://charts.example.com/" is the repository URL repo: "my-repo", // The name of the chart. "profile" in this case chart: "profile", // Version of the chart to deploy version: "1.2.3", // Any custom values you want to overwrite in the chart. // These values will replace the chart's default values. values: { // Example of custom values. The actual values depend on the "profile" chart's requirements. service: { type: "ClusterIP" } }, // If you have a specific namespace for your deployment, set it here. // If the namespace does not exist, it will not be created by default, so ensure it exists. namespace: "my-namespace" }); // Optionally export the Service URL by querying the deployed Service // This part is highly dependent on whether your chart creates a Service and its details // It assumes the "profile" chart does and that it's of type LoadBalancer // Adjust accordingly for other Service types like ClusterIP or NodePort export const serviceUrl = profileChart.getResourceProperty("v1/Service", "profile-service", "status").apply(status => { // Assuming the service type is LoadBalancer and will have ingress points // This may not always be the case, so check accordingly and adjust if needed const ingress = status.loadBalancer.ingress[0]; if (ingress.hostname) { // If there's a hostname provided, likely from cloud provider's LB services return `http://${ingress.hostname}/`; } else if (ingress.ip) { // If an IP address is provisioned for the LoadBalancer return `http://${ingress.ip}/`; } // If ingress is not available, return a message return "Service does not have an ingress point yet."; });
Let's break down what we're doing in this program:
-
We import the Kubernetes package for Pulumi to interact with Kubernetes resources.
-
We create a new instance of the
Chart
resource. This is what instructs Pulumi to deploy a Helm chart in the cluster:repo
: Specifies the Helm chart repository where the "profile" chart is stored.chart
: This is the name of the chart we want to deploy – "profile" in this case.version
: We specify the version of the Helm chart to use – replace "1.2.3" with the version you need.values
: Here you can override the default values provided by the Helm chart with your custom configuration. In this example, we configure the chart to create a service of typeClusterIP
.namespace
: Specify the Kubernetes namespace where the chart should be deployed. If this is not set, the default namespace is used. Also ensure the namespace exists because Pulumi won't create it automatically.
-
Optionally, we export the URL of the service created by the Helm chart, assuming it's of type
LoadBalancer
and thus will provide an external ingress point. This is to demonstrate how you can programmatically access the properties of resources created by the chart. -
We add comments within the code to explain what each part is doing so it's clear to you as you maintain the program.
To use this Pulumi program:
- Ensure you have Pulumi CLI installed.
- Ensure you have
kubectl
installed and configured to connect to your Kubernetes cluster. - Create a new Pulumi project in TypeScript.
- Replace "https://charts.example.com/" with the actual repository URL of your "profile" chart in the program above.
- Replace "1.2.3" with the actual version of the chart you wish to deploy.
- Add your custom configurations in the
values
section as required by your Helm chart. - Run
pulumi up
to deploy your chart to the Kubernetes cluster.
The code is designed to proliferate the "profile" Helm chart across your Kubernetes cluster, creating all the Kubernetes resources defined by that chart with the configurations you specify.
-