Deploy the yelb helm chart on Google Kubernetes Engine (GKE)
TypeScriptTo deploy the Yelb Helm chart on Google Kubernetes Engine (GKE), you need to follow these steps in Pulumi:
- Provision a GKE cluster using Pulumi's
google-native.container.v1beta1.Cluster
resource. - Install the Helm chart onto the GKE cluster using Pulumi's
kubernetes.helm.v3.Chart
resource.
Let's go through the process step-by-step to understand what each part of the code is doing.
Provisioning a GKE Cluster
Provisioning a GKE cluster involves creating a Kubernetes cluster in Google Cloud Platform. The
google-native.container.v1beta1.Cluster
resource is used to define and provision the cluster within your GCP project.Installing the Helm Chart
Once the cluster is up and running, you can deploy the Helm chart to it. Pulumi provides the
kubernetes.helm.v3.Chart
resource as part of the Kubernetes provider to deploy Helm charts to a Kubernetes cluster.First, you'll need to set up your Pulumi program. Make sure you've installed the Pulumi CLI and logged in, and that you have the necessary cloud provider CLI tools installed (in this case,
gcloud
for Google Cloud).Now, let's look at the complete Pulumi TypeScript program that accomplishes these tasks.
import * as gcp from "@pulumi/gcp"; import * as kubernetes from "@pulumi/kubernetes"; import * as pulumi from "@pulumi/pulumi"; // Create a GKE cluster const cluster = new gcp.container.Cluster("my-gke-cluster", { // Specify the location to deploy the cluster location: "us-west1-a", // Define the initial node count for the default node pool initialNodeCount: 2, // Define the machine type to use for the cluster nodes nodeConfig: { machineType: "n1-standard-1", }, }); // Expose the Kubeconfig for the GKE cluster const kubeconfig = pulumi.all([cluster.name, cluster.endpoint, cluster.masterAuth]).apply(([name, endpoint, masterAuth]) => { const context = `${gcp.config.project}_${gcp.config.zone}_${name}`; return `apiVersion: v1 clusters: - cluster: certificate-authority-data: ${masterAuth.clusterCaCertificate} server: https://${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 Kubernetes provider using the GKE cluster's kubeconfig const k8sProvider = new kubernetes.Provider("gke-k8s", { kubeconfig: kubeconfig, }); // Deploy the Yelb Helm chart using the Kubernetes provider const yelbChart = new kubernetes.helm.v3.Chart("yelb", { chart: "yelb", // Helm repository details can be provided here if needed // fetchOpts: { // repo: "http://example.com/charts", // }, }, { provider: k8sProvider }); // Export the GKE cluster name and Yelb service details export const clusterName = cluster.name; export const yelbService = yelbChart.getResource("v1/Service", "yelb-ui");
Explanation
- We define a GKE cluster with some basic configurations, specifying the number of nodes and machine type for the nodes.
- We generate a kubeconfig file that would allow us to interact with our GKE cluster using
kubectl
. This kubeconfig is extracted from the cluster properties and adjusted for use with the Pulumi GCP plugin. - With the kubeconfig, we create a Pulumi Kubernetes provider that will drive the communication with the GKE cluster.
- Using the Kubernetes provider, we deploy the Yelb Helm chart to our GKE cluster. Note that in this code, I've commented out the
fetchOpts
section, which you would use if your Helm chart is located in a custom Helm repository. You can uncomment and update that section with the appropriate chart details.
After deploying the program with
pulumi up
, you'll have a running instance of the Yelb application on GKE. The output of thepulumi up
command will include theclusterName
and service endpoint details for Yelb, which you can use to access the application.- Provision a GKE cluster using Pulumi's