Deploy the generic helm chart on Google Kubernetes Engine (GKE)
TypeScriptDeploying a generic Helm chart on Google Kubernetes Engine (GKE) with Pulumi involves several steps. First, you need to create a GKE cluster, and then you use Helm's Pulumi integration to deploy your chart to that cluster. Below is a detailed guide followed by a Pulumi program written in TypeScript that accomplishes this.
Step 1: Define Your GKE Cluster
You'll start with defining a GKE cluster, which is a group of compute resources where your containerized applications will run. In Pulumi, you use the
gcp.container.Cluster
resource to create a new GKE cluster.Step 2: Deploy Your Helm Chart
Once you have a Kubernetes cluster, you can deploy applications using Helm charts. Helm is a package manager for Kubernetes that provides an easy way to distribute and deploy applications. The
kubernetes.helm.v3.Chart
resource in Pulumi allows you to deploy any Helm chart to your cluster, whether it's from the public Helm repository or your own private chart.Below, you'll find a Pulumi program that creates a GKE cluster and deploys a generic Helm chart. The placeholder values for the chart and its values should be replaced with the actual chart you wish to deploy and the specific configuration values for your use case.
Pulumi TypeScript Program
import * as gcp from "@pulumi/gcp"; import * as k8s from "@pulumi/kubernetes"; // Step 1: Create a GKE cluster const cluster = new gcp.container.Cluster("my-gke-cluster", { initialNodeCount: 2, nodeVersion: "latest", minMasterVersion: "latest", nodeConfig: { machineType: "n1-standard-1", // Example machine type, choose based on your needs oauthScopes: [ "https://www.googleapis.com/auth/compute", "https://www.googleapis.com/auth/devstorage.read_only", "https://www.googleapis.com/auth/logging.write", "https://www.googleapis.com/auth/monitoring" ], }, }); // Export the Cluster name export const clusterName = cluster.name; // Step 2: Deploy a generic Helm chart to the GKE cluster const k8sProvider = new k8s.Provider("k8s-provider", { kubeconfig: cluster.kubeConfigRaw, }); const myChart = new k8s.helm.v3.Chart("my-generic-chart", { chart: "nginx", // Replace with your Helm chart name version: "1.16.0", // Replace with the chart version you desire fetchOpts: { repo: "https://charts.helm.sh/stable", // Replace with your Helm chart repository }, // Replace with the configuration values according to your chart's requirements values: { service: { type: "LoadBalancer", }, }, }, { provider: k8sProvider }); // Export the URL to access the deployed service export const serviceUrl = myChart.getResourceProperty("v1/Service", "my-generic-chart-nginx-service", "status") .apply(status => `http://${status.loadBalancer.ingress[0].ip}`);
How to Run This Program
- Ensure Pulumi is installed and configured to connect to your GCP account.
- Create a new directory for your Pulumi project and enter it.
- Run
pulumi new typescript
to create a new Pulumi TypeScript project. - Replace the contents of
index.ts
with the code above. - Install the necessary dependencies by running
npm install @pulumi/gcp @pulumi/kubernetes
. - Run
pulumi up
to preview and deploy the changes.
The
index.ts
file first creates a new GKE cluster with two nodes and then deploys an NGINX Helm chart to the cluster. The NGINX Helm chart is used here as an example and should be replaced with your actual chart of interest.The name and version of the chart, along with the repository URL and chart configuration values (
values
), need to be set according to the Helm chart you're deploying. You can find these details in the chart's documentation.The
serviceUrl
is exported from the program, providing an easy way to access the IP address of the deployed service after the Pulumi program has run successfully.You would replace the values provided with those specific to your chart, its repository, and the appropriate configuration settings necessary for your deployment. The
kubeConfigRaw
property of the cluster is used to configure the Kubernetes provider, allowing Pulumi to communicate with your GKE cluster to manage resources.