SonarQube-PostgreSQL Installation on Azure Kubernetes Service with Azure Disk&File

Çiğdem Kadakoğlu
4 min readJan 3, 2023

--

AKS:1.24.6-SonarQube Community Edition: 7.9.4

Hi everyone,

Today we will set up SonarQube on AKS cluster. 🐧🐳☸️

kadakoglucigdem

What we are going to do now is creating yaml files. We need to create namespace named “sast” in namespace.yaml file.

Run the command below after you’ve created the file.

kubectl create -f namespace.yaml
kubectl get ns
kadakoglucigdem

PostgreSQL

Next, we need an Azure file in order to use PostgreSQL’s persistent volume. You can use the default storage class, such as managed-csi, or create your own in both dynamic and static Azure disk.

kadakoglucigdem

We’ll go with the default. For PostgreSQL, we need

  • ConfigMap: Creating Users and Databases
  • PersistentVolumeClaim: Mounting PostgreSQL data
  • Secret: Using passwords
  • Deployment: Creating a PostgreSQL instance
  • Service: Accessing the PostgreSQL database from SonarQube

Run the command below after you’ve created the file.

kubectl apply -f postgresql.yaml
kadakoglucigdem

We can see from the logs that the database is ready to accept connections.

kubectl get po -n sast
kubectl logs -f <POD_NAME> -n sast
kadakoglucigdem

SonarQube

We will now create SonarQube YAML files. To begin, we must create an Azure file in order to mount the SonarQube data and extensions directory.

kadakoglucigdem
kubectl create -f storageclass.yaml
kubectl get storageclass

For SonarQube, we need

  • PersistentVolumeClaim: Mounting SonarQube data
  • Secret: Using passwords
  • Deployment: Creating a SonarQube instance
  • Service: Accessing the SonarQube from Users
kadakoglucigdem
kubectl create -f sonarqube.yaml
kubectl get po -n sast

SonarQube is ready for now.

Username: admin

Password: admin

kadakoglucigdem
kadakoglucigdem

We still require the plugins because SonarQube images no longer include them after version 7 Community Edition. That is why we need to use Portal to add the plugins.

When you click the node resource group, you can see the storage account that was created by the storage class.

kadakoglucigdem

Click the “File Sharing” button after selecting this storage account. There are sonarqube-extensions and sonarqube-data persistent volume claims.

kadakoglucigdem

Create a new directory called “plugins”. Next, upload all of the plugin files that we require. It takes a while.

kadakoglucigdem

If you want to look inside the sonarqube pod, you can find these files in the plugins directory. You can get the plugins from here, depending on which version you have.

kadakoglucigdem
kubectl exec <POD_NAME> -c sonarqube -n sast -- ls /opt/sonarqube/extensions/plugins
kubectl delete po <POD_NAME> -n sast

We must now restart SonarQube. You can do this by deleting the pod. You can only analyze the main branch using this method.

kadakoglucigdem

Even if community-branch-plugin is installed, the environment variables in the sonar.properties file don’t work properly, and you get an error. I tried so many things with Azure files, but nothing worked. You can check it here.

kadakoglucigdem

Hope you find my article helpful. I wish everyone an awesome day!

You can check this article: Microsoft Azure Static IP & DNS Configuration for SonarQube

--

--

Çiğdem Kadakoğlu

Docker Captain🐳🇹🇷👩‍✈️ | Microsoft MVP | Instructor | Senior Cloud&DevOps Engineer | CK{A|AD}-AZ{104|204|305|400|800|801|900}-DP900-AI{900|102}-PL900🐧🐳🌼☕