Deploy the rotate-elasticsearch-index helm chart on Google Kubernetes Engine (GKE)
TypeScriptTo deploy the
rotate-elasticsearch-index
Helm chart on Google Kubernetes Engine (GKE), you will first need to create a GKE cluster, and then deploy the chart on it.Creating a GKE Cluster
The Pulumi program will use the
google-native.container.v1.Cluster
resource to create a GKE cluster. This resource defines a Kubernetes cluster in GKE and specifies configuration details such as the location, the initial node count, and the type of network policy.Deploying the Helm Chart
Once the GKE cluster is up and running, you can deploy the
rotate-elasticsearch-index
Helm chart using thekubernetes.helm.sh/v3.Release
resource from the Pulumi Kubernetes provider. This resource interacts with Helm to deploy a chart to a Kubernetes cluster.Below is a TypeScript program demonstrating how this can be accomplished using Pulumi. Please ensure you have the Pulumi CLI installed, logged in to your Google Cloud account, and have set up default credentials for the Google Cloud SDK.
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("gke-cluster", { // Specify initial settings for the cluster initialNodeCount: 2, minMasterVersion: "latest", nodeVersion: "latest", nodeConfig: { preemptible: true, 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 Cluster name export const clusterName = cluster.name; // Create a Kubernetes provider instance that uses our cluster from above. const k8sProvider = new k8s.Provider("gke-k8s", { kubeconfig: cluster.kubeConfigRaw, }); // Deploy the Helm chart for rotate-elasticsearch-index const helmChart = new k8s.helm.v3.Chart("rotate-elasticsearch-index", { chart: "rotate-elasticsearch-index", // Specify the Helm repository URL if the chart is not in the stable repository // repositoryOpts: { // repo: "http://<your-helm-chart-repository>", // }, values: { // Specify the chart values here }, }, { provider: k8sProvider }); // Export the Helm chart's status export const helmChartStatus = helmChart.status;
In this program:
- We create a GKE cluster by specifying some initial values, which include the number of nodes in the cluster, the master's version, and the machine type for the nodes.
- We then export the cluster name as a stack output.
- We create a Pulumi Kubernetes provider which is responsible for deploying resources to the GKE cluster.
- We deploy a Helm chart to the cluster using the
Chart
resource. You must specify the chart name, and optionally, the URL of the Helm repository if the chart is not in the default Helm chart repository. In addition, you can provide any custom values that your Helm chart accepts.
To use this program:
- Replace the placeholders in
values
with actual configuration values for therotate-elasticsearch-index
chart. - If the chart is not in a public repository or if it's in a custom repository, uncomment and edit the
repositoryOpts
configuration. - Install the Pulumi CLI, set up the GCP credentials, and create a new Pulumi project using the above code.
- Run
pulumi up
to execute the program and create the resources.