Deploy the nginx-gateway-fabric helm chart on Google Kubernetes Engine (GKE)
TypeScriptTo deploy the nginx-gateway-fabric Helm chart on Google Kubernetes Engine (GKE), we'll need to accomplish a few things:
- Create a GKE cluster.
- Establish a Kubernetes configuration to interact with the cluster.
- Deploy the nginx-gateway-fabric Helm chart to the GKE cluster.
For step 1, we'll use the
gcp.container.Cluster
resource for creating a GKE cluster. A basic GKE cluster is sufficient for our needs.For step 2, once the GKE cluster is created, we’ll retrieve its kubeconfig — the configuration file that
kubectl
and other Kubernetes-based tools use to interact with the cluster.For step 3, we’ll use the
kubernetes.helm.v3.Chart
resource to deploy the nginx-gateway-fabric Helm chart. Assuming the Helm chart is publicly available, we don't need to provide a repository URL; the stable repository is assumed by default.Below is the TypeScript program that performs these steps:
import * as pulumi from "@pulumi/pulumi"; 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, 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", ], }, // You may remove or update the following region and zone as per your requirements. location: "us-central1", zone: "us-central1-a", }); // Step 2: Establish Kubernetes configuration to interact with the 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 `; }); const clusterProvider = new k8s.Provider("gkeK8s", { kubeconfig: kubeConfig, }); // Step 3: Deploy the nginx-gateway-fabric Helm chart to the GKE cluster. const nginxGatewayFabricChart = new k8s.helm.v3.Chart("nginx-gateway-fabric", { chart: "nginx-gateway-fabric", // If the Chart is not in the stable repository or you wish to specify a version, please provide the additional fields like below: // repo: "https://charts.example.com/", // version: "1.2.3", }, { provider: clusterProvider }); // Export the Kubeconfig and the GKE cluster name. export const kubeConfigOutput = kubeConfig; export const gkeClusterName = cluster.name;
Here's what each part of the code does:
-
Create a GKE Cluster: We instantiate a
gcp.container.Cluster
to create a GKE cluster with two nodes. We've chosen then1-standard-1
machine type for the nodes, but this can be adjusted as needed. The scopes provided are necessary for the cluster to interact with other Google Cloud services. -
Kubernetes Configuration: After the cluster is created, we build the kubeconfig file. We are using the Pulumi's
apply
method to asynchronously handle the dependencies between resources. -
Deploy Helm Chart: We declare a
kubernetes.helm.v3.Chart
resource to deploy the indicated Helm chart. If your Helm chart is located in a custom repository or if you need a specific version of the Helm chart, you can specify therepo
andversion
in the options.
Finally, we export the generated kubeconfig and the GKE cluster name. The
kubeConfig
can be used locally with thekubectl
command-line tool to interact with your cluster, and you'll see the cluster name in your Google Cloud dashboard.