Categories
General

Kubernetes: Install Sonarqube on GKE with Google SQL

SonarQube is an open sourced code quality scanning tool.

You can use a helm chart, but at the time of writing this blog I didn’t see a Google SQL proxy option. I ended up using helm template to generate the majority of the yaml files and added the Google SQL proxy parts myself.

https://github.com/Oteemo/charts/tree/master/charts/sonarqube

Create Database

https://cloud.google.com/sql/docs/mysql/connect-kubernetes-engine#before_you_begin

I used PostgreSQL 12 and created a user account and a database called sonar.

https://docs.sonarqube.org/latest/requirements/requirements/

Create namespace

kubectl create ns sonarqube

Create Google Service Account

Create secrets

Service Account

This secret enables authentication to Cloud SQL.

kubectl -n sonarqube create secret generic sonarqube-cloudsql-instance-credentials \
--from-file=credentials.json=./credentials.json

Database Username & Password

  • Update [PASSWORD]
kubectl -n sonarqube create secret generic sonarqube-cloudsql-db-credentials \
--from-literal=username=sonar \
--from-literal=password="[PASSWORD]" \
--from-literal=url="jdbc:postgresql://localhost:5432/sonar"

Create

  • Download the yaml file
  • Update [YOUR_GOOGLE_CLOUD_CONNECTION_NAME]
kubectl apply -f sonarqube-example.yaml

Connect

Create a port-forward connection.

kubectl port-forward deploy/sonarqube 9000:9000 -n sonarqube

Open in browser.

open http://localhost:9000

Login (default).

  • Username: admin
  • Password: admin

By Tommy Elmesewdy

DevOps Engineer