Deploy the helm-nginx helm chart on Google Kubernetes Engine (GKE)
TypeScriptTo deploy the
helm-nginx
Helm chart on Google Kubernetes Engine (GKE) using Pulumi, you'll need to follow these steps:-
Set Up a GKE Cluster: First, you need a running Kubernetes cluster on GKE. For this, you'll use the
google-native.container/v1beta1.Cluster
resource to create a new GKE cluster. -
Install the Helm Chart: Once you have a Kubernetes cluster running, you can use the
kubernetes.helm.sh/v3.Release
resource to deploy thenginx
Helm chart to your GKE cluster.
Below you'll find a complete Pulumi program that sets up a GKE cluster and deploys the
nginx
Helm chart. The program is written in TypeScript.Pulumi Program to Deploy
helm-nginx
on GKE:import * as gcp from "@pulumi/gcp"; import * as k8s from "@pulumi/kubernetes"; // Create a GKE cluster const cluster = new gcp.container.Cluster("my-gke-cluster", { initialNodeCount: 2, nodeConfig: { machineType: "n1-standard-1", 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 Kubeconfig export const kubeconfig = cluster.name.apply(name => { const context = `${gcp.config.project}_${gcp.config.zone}_${name}`; return `apiVersion: v1 clusters: - cluster: certificate-authority-data: ${cluster.masterAuth.clusterCaCertificate} server: https://${cluster.endpoint} name: ${context} contexts: - context: cluster: ${context} user: ${context} name: ${context} current-context: ${context} kind: Config preferences: {} users: - name: ${context} user: auth-provider: config: cmd-args: config config-helper --format=json cmd-path: gcloud expiry-key: '{.credential.token_expiry}' token-key: '{.credential.access_token}' name: gcp `; }); // Create a Provider for the cluster const clusterProvider = new k8s.Provider("my-gke-cluster-provider", { kubeconfig: kubeconfig, }); // Deploy the nginx-ingress Helm chart using the Provider const nginxHelmChart = new k8s.helm.v3.Chart("nginx-ingress", { chart: "nginx-ingress", version: "1.41.3", // Specify the version of the Helm chart you wish to deploy namespace: "default", // Targeted Kubernetes namespace fetchOpts: { repo: "https://helm.nginx.com/stable", // NGINX stable repository }, }, { provider: clusterProvider }); // Export the Helm chart resources export const nginxResources = nginxHelmChart.resources;
In this program:
- We define a
gcp.container.Cluster
resource, which creates a GKE cluster with 2 nodes of machine typen1-standard-1
. - We export the
kubeconfig
for the created cluster. Thekubeconfig
is used to interact with the cluster usingkubectl
or any Kubernetes client. - We create a Pulumi Kubernetes
Provider
which utilizes the kubeconfig of our GKE cluster. This provider is responsible for deploying resources to the GKE cluster. - We then define a
k8s.helm.v3.Chart
resource, which represents the Helm chart we want to deploy. In this case, we're deployingnginx-ingress
, specifying its version and Helm repo. Note the usage ofprovider: clusterProvider
, which tells Pulumi to use the created GKE cluster for this deployment. - Finally, we export the resources created by the Helm chart for visibility. You can access these resources using the
nginxResources
export.
To run the program:
- Set up Pulumi with GCP credentials as per the official documentation.
- Save the above code in a file e.g.,
index.ts
. - Install the required npm dependencies:
npm install @pulumi/pulumi @pulumi/gcp @pulumi/kubernetes
- Run
pulumi up
to create the resources. This will prompt you to confirm the action before proceeding.
-