1. Deploy the take-the-helm helm chart on Google Kubernetes Engine (GKE)


    To deploy a Helm chart on Google Kubernetes Engine (GKE), you need to perform the following steps:

    1. Create a GKE cluster: A Kubernetes cluster must be up and running to deploy Helm charts into it. Google Kubernetes Engine provides managed Kubernetes clusters that are easy to create and scale.

    2. Install and initialize Helm: Helm is a tool that streamlines the installation and management of Kubernetes applications. It uses a packaging format called charts, and you'll need it installed on your local machine or within your CI/CD pipeline to deploy the chart.

    3. Deploy the Helm chart: Once you have Helm installed and your Kubernetes cluster ready, you can deploy your Helm chart with the specific values that match your needs.

    Below is a Pulumi program in TypeScript that will create a GKE cluster and deploy the "take-the-helm" Helm chart to it. Before we jump into the code, make sure you have Pulumi and the GCP CLI installed and configured on your local machine. For Helm, you can rely on the Pulumi Kubernetes provider to install and manage Helm charts without needing to manually interact with the Helm CLI.

    Now, let's see the Pulumi program:

    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: { preemptible: true, machineType: "n1-standard-1", }, }); // Export the Cluster name. export const clusterName = cluster.name; // Export the Kubeconfig to access the cluster with kubectl. export const kubeconfig = cluster.endpoint.apply(endpoint => `apiVersion: v1 clusters: - cluster: certificate-authority-data: ${cluster.masterAuth.clusterCaCertificate} server: https://${endpoint} name: gke_${gcp.config.project}_${gcp.config.zone}_${cluster.name} contexts: - context: cluster: gke_${gcp.config.project}_${gcp.config.zone}_${cluster.name} user: gke_${gcp.config.project}_${gcp.config.zone}_${cluster.name} name: gke_${gcp.config.project}_${gcp.config.zone}_${cluster.name} current-context: gke_${gcp.config.project}_${gcp.config.zone}_${cluster.name} kind: Config preferences: {} users: - name: gke_${gcp.config.project}_${gcp.config.zone}_${cluster.name} user: auth-provider: config: cmd-args: config config-helper --format=json cmd-path: C:/Program Files (x86)/Google/Cloud SDK/google-cloud-sdk/bin/gcloud.cmd expiry-key: '{.credential.token_expiry}' token-key: '{.credential.access_token}' name: gcp `); // Initialize a K8s provider using the GKE cluster credentials. const provider = new k8s.Provider("gke-k8s", { kubeconfig: kubeconfig, }); // Deploy the Helm chart using the provider created above. const helmChart = new k8s.helm.v3.Chart("take-the-helm", { chart: "my-chart-name", // Replace with the chart repository, or specify a chart directory. fetchOpts: { repo: "http://my-chart-repo/", }, // Note: Depending on your chart's requirements, you might need to customize // the values here, passing a values object with specific properties. }, { provider }); // Export the Helm chart resources. export const helmResources = helmChart.resources;

    This program will set up a new GKE cluster, and then use the cluster credentials to initialize a K8s provider which is then used to deploy a Helm chart named "take-the-helm". Keep in mind that:

    • You'll need to replace my-chart-name and http://my-chart-repo/ with the actual name of your Helm chart and its repository URL, respectively.
    • The values property within the Chart resource can be customized to pass specific configurations to your Helm chart.

    The apiVersion, kind, and other declarations in the kubeconfig field are used to formulate a kubeconfig file inline, which can be used by Pulumi and kubectl to communicate with the cluster.

    After deploying with pulumi up, you'll get the kubeconfig file content as an output that you can use with kubectl to communicate with your GKE cluster. Also, the helmResources exported will store metadata about the resources created by the Helm chart.