Deploy the z2jh4k8s helm chart on Google Kubernetes Engine (GKE)
TypeScriptTo deploy the
z2jh4k8s
Helm chart on Google Kubernetes Engine (GKE), we'll go through several steps. First, we need to create a GKE cluster. Once the cluster is ready, we'll deploy thez2jh4k8s
Helm chart to it.Pulumi's
gcp.container.Cluster
resource will be used to create the GKE cluster. For deploying the Helm chart, we'll use Pulumi'skubernetes.helm.sh/v3.Release
resource, which is a custom resource that leverages the Helm SDK to deploy Helm charts into a Kubernetes cluster.It is assumed that you have Pulumi CLI installed and configured for use with GCP.
Below is a TypeScript program that sets up the resources:
import * as pulumi from '@pulumi/pulumi'; import * as gcp from '@pulumi/gcp'; import * as k8s from '@pulumi/kubernetes'; // Create a GKE cluster const cluster = new gcp.container.Cluster("z2jh4k8s-cluster", { initialNodeCount: 2, minMasterVersion: "latest", nodeVersion: "latest", nodeConfig: { machineType: "n1-standard-1", // You can choose the machine type according to your requirement. 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; // Get the Kubeconfig from the created 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 instance with the kubeconfig from above const k8sProvider = new k8s.Provider("k8s-provider", { kubeconfig: kubeconfig, }); // Deploy the z2jh4k8s Helm chart into the GKE cluster const z2jh4k8sChart = new k8s.helm.v3.Release("z2jh4k8s-release", { chart: "z2jh4k8s", version: "0.11.1", // Replace with the specific chart version you want to deploy namespace: "default", fetchOpts:{ repo: "https://helm.repo.url/", // Replace with the URL of the repo where the chart is located }, }, { provider: k8sProvider }); // Export the Helm chart default values export const helmChartDefaultValues = z2jh4k8sChart.status.apply(status => status.values);
In this program:
- We first declare a GKE cluster resource with a couple of nodes. The
machineType
and node count is specified for the cluster. - Then, we derive the kubeconfig needed to interact with the cluster once GKE provisions it.
- A Kubernetes provider is set up using the kubeconfig we obtained. This provider is what Pulumi will use to communicate with your GKE cluster.
- Lastly, we use the Kubernetes provider to deploy the
z2jh4k8s
Helm chart. Thechart
andversion
attributes specify the Helm chart to deploy.
Please make sure you replace
"https://helm.repo.url/"
with the actual repository URL where thez2jh4k8s
chart is hosted.Also, if you'd like to pass custom values to the Helm chart or configure other aspects of your Kubernetes resources, you can do so by adding appropriate properties in the
k8s.helm.v3.Release
resource call.To run this Pulumi program, save it to a file (e.g.,
index.ts
), and then runpulumi up
to deploy the infrastructure.Note: The creation of GKE clusters can take several minutes. Pulumi will provide progress updates in the console where you run
pulumi up
. After the deployment is complete, Pulumi will output any exported values, such as the cluster name and the default values of the deployed Helm chart.- We first declare a GKE cluster resource with a couple of nodes. The