SonarQube-PostgreSQL Installation on Azure Kubernetes Service with Azure Disk&File
AKS:1.24.6-SonarQube Community Edition: 7.9.4
Hi everyone,
Today we will set up SonarQube on AKS cluster. 🐧🐳☸️
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
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.
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
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
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.
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
kubectl create -f sonarqube.yaml
kubectl get po -n sast
SonarQube is ready for now.
Username: admin
Password: admin
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.
Click the “File Sharing” button after selecting this storage account. There are sonarqube-extensions and sonarqube-data persistent volume claims.
Create a new directory called “plugins”. Next, upload all of the plugin files that we require. It takes a while.
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.
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.
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.
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