1. Answers
  2. Deploy SonarQube on GKE with Helm

How Do I Deploy the SonarQube Helm Chart on GKE?

In this guide, we will deploy the SonarQube Helm chart on a Google Kubernetes Engine (GKE) cluster using Pulumi. SonarQube is an open-source platform for continuous inspection of code quality. We will create a GKE cluster, deploy the Helm chart for SonarQube, and configure it to run on the cluster.

Key Points

  • Create a GKE cluster.
  • Use the Pulumi Kubernetes provider to manage the cluster.
  • Deploy the SonarQube Helm chart on the GKE cluster.
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("sonarqube-cluster", {
    initialNodeCount: 3,
    minMasterVersion: "1.21",
    nodeVersion: "1.21",
    nodeConfig: {
        machineType: "n1-standard-1",
        oauthScopes: [
            "https://www.googleapis.com/auth/cloud-platform",
        ],
    },
});

// Export the Kubeconfig required to access the cluster
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:
        access-token: ${gcp.config.accessToken}
        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 cluster's kubeconfig
const k8sProvider = new k8s.Provider("k8s-provider", {
    kubeconfig: kubeconfig,
});

// Deploy the SonarQube Helm chart
const sonarqubeChart = new k8s.helm.v3.Chart("sonarqube", {
    chart: "sonarqube",
    version: "9.5.0",
    fetchOpts: {
        repo: "https://charts.bitnami.com/bitnami",
    },
}, { provider: k8sProvider });

Summary

In this guide, we created a GKE cluster, configured the Pulumi Kubernetes provider to use the cluster, and deployed the SonarQube Helm chart on the cluster. This setup ensures that SonarQube is running on a managed Kubernetes cluster in Google Cloud.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up