Deploy the splunk-operator helm chart on Google Kubernetes Engine (GKE)
TypeScriptTo deploy the
splunk-operator
Helm chart on Google Kubernetes Engine (GKE) using Pulumi, we need to follow these high-level steps:- Set up a new GKE cluster where our applications will be deployed.
- Use the Pulumi Kubernetes provider to install the
splunk-operator
Helm chart on the GKE cluster.
For step 1, we'll use the
google-native.container/v1beta1.Cluster
resource to create a new GKE cluster. For step 2, we'll use thekubernetes.helm.sh/v3.Release
resource to deploy the Helm chart to our cluster.Below is a TypeScript program using Pulumi to accomplish these steps. The Pulumi program below does not cover the installation of Pulumi or the setup of the GKE credentials, which you will need to have in place to execute this successfully.
import * as pulumi from "@pulumi/pulumi"; import * as gcp from "@pulumi/gcp"; import * as k8s from "@pulumi/kubernetes"; // Step 1: Create a new GKE cluster const cluster = new gcp.container.Cluster("my-gke-cluster", { initialNodeCount: 2, }); // Export the Kubeconfig export 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 `; }); // Step 2: Install the splunk-operator Helm chart on the GKE cluster const splunkOperatorChart = new k8s.helm.v3.Release("splunk-operator", { chart: "splunk-operator", // Fetch the Helm chart from a Helm repo, if necessary: // repositoryOpts: { // repo: "https://<helm-repo-url>" // }, // Specify the namespace and values for the chart if required: // namespace: "default", // values: { /* ... */ }, }, { provider: new k8s.Provider("k8s-provider", { kubeconfig: kubeconfig }) }); // Export the status of the Helm release export const helmReleaseStatus = splunkOperatorChart.status;
Here's a breakdown of what we're doing in the program:
- First, we import the necessary Pulumi packages.
- We create a new GKE cluster called
my-gke-cluster
withinitialNodeCount
set to two nodes. - We export the
kubeconfig
which will be used to interact with your GKE cluster viakubectl
or any Kubernetes client. - We create a new Helm release for the
splunk-operator
chart using thenew k8s.helm.v3.Release
call. This step assumes that the Helm chartsplunk-operator
is available in your configured Helm repository or the default repositories. - We set up a dependency on the GKE cluster to ensure that the cluster is created before the Helm chart is deployed.
- As an extra, we're exporting the status of the Helm release. This can be used to check if the Operator was deployed successfully.
Please make sure to replace
<helm-repo-url>
with the actual Helm repository URL where thesplunk-operator
chart is hosted if it's not in the default Helm repo.Further, you must have Pulumi set up with the right GCP credentials to create the resources, and Helm must be configured correctly on your local machine if you plan to make any Helm-related operations locally.
Before running this code, you also need to have the appropriate IAM permissions for creating GKE clusters and deploying resources to them. You can execute this code by running
pulumi up
in the directory where this code is saved. Pulumi will perform the deployment and output the results.