Sonarqube in AKS

- apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: sonarqube-azure-test
  spec:
    selector:
      matchLabels:
        app: sonarqube-azure-test
    template:
      metadata:
        labels:
          app: sonarqube-azure-test
      spec:
        containers:
        - name: sonarqube-azure-test
          image: sonarqube:lts-enterprise
          imagePullPolicy: IfNotPresent
          resources:
            limits:
              memory: "6144Mi"
              cpu: "2000m"
          ports:
          - containerPort: 9000
          volumeMounts:
            - name: sonarqube-azure-data
              mountPath: /opt/sonarqube/data
            - name: sonarqube-azure-logs
              mountPath: /opt/sonarqube/logs
            - name: sonarqube-azure-extensions
              mountPath: /opt/sonarqube/extensions
        volumes:
          - name: sonarqube-azure-data
            persistentVolumeClaim:
              claimName: sonarqube-azure-data
          - name: sonarqube-azure-logs
            persistentVolumeClaim:
              claimName: sonarqube-azure-logs
          - name: sonarqube-azure-extensions
            persistentVolumeClaim:
              claimName: sonarqube-azure-extensions
- apiVersion: v1
  kind: Service
  metadata:
    name: sonarqube-azure-test
  spec:
    selector:
      app: sonarqube-azure-test
    ports:
    - port: 9000
      targetPort: 9000
- apiVersion: networking.k8s.io/v1
  kind: Ingress
  metadata:
    name: sonarqube-azure-tests
    labels:
      name: sonarqube-azure-tests
    annotations:
      kubernetes.io/ingress.class: azure/application-gateway
  spec:
    rules:
    - host: sonarqubeazure.sandcsw.com
      http:
        paths:
        - pathType: Prefix
          path: "/"
          backend:
            service:
              name: sonarqube-azure-test
              port:
                number: 9000
- apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: sonarqube-azure-data
  spec:
    resources:
      requests:
        storage: 16Gi
    volumeMode: Filesystem
    accessModes:
      - ReadWriteMany
    storageClassName: azurefile
- apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: sonarqube-azure-logs
  spec:
    resources:
      requests:
        storage: 16Gi
    volumeMode: Filesystem
    accessModes:
      - ReadWriteMany
    storageClassName: azurefile
- apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: sonarqube-azure-extensions
  spec:
    resources:
      requests:
        storage: 16Gi
    volumeMode: Filesystem
    accessModes:
      - ReadWriteMany
    storageClassName: azurefile

I’m trying to deploy sonarqube enterprise edition version 8.9.7.52159 in an AKS cluster on azure with three volumes for data, logs and extensions.
But whenever i deploy it, the pod comes up fine and then after about a minute, it crashes and then restarts and keeps restarting until i get the error CrashLoopBackOff. Please see my yml file above.

Hi @Tomide and welcome to the community :wave:

could you share some logs regarding the crash that you observed? Also please note that we offer a helm chart that you could use to get you started with sonarqube on k8s, but there are known problems with some azure specific storage classes

Thank you very much for responding. The logs won’t show because the pod is down. But the status says crashloopbackoff.

Also I want to deploy a 3 replica enterprise sonarqube in AKS and would like to know which volume type in Azure is suitable for having the 3 replicas connected simultaneously? Will the /data volume not be needed if there is a postgres database attached. What about the /extensions and the /logs volumes, can those go inside a database or they have to be stored on a volume?

Thank you

If there are no logs, than maybe a describe pod could give some more information?

This is not possible. Only the Datacenter Edition supports horizontal scaling. for all other instances you are limited to 1 replica for now.

Okay, regards the database addition, Will the /data volume not be needed if there is a postgres database attached. What about the /extensions and the /logs volumes, can those go inside a database or they have to be stored on a volume?

Also, I got the deployment to work. Turns out it was something to do with the storage class. The file system storage doesn’t work so i had to use azure disk. And even that did not work instantly, i was getting the error “0/2 nodes are available: 2 pod has unbound immediate PersistentVolumeClaim” Then i used a storage class which had the volume binding mode set to “wait for first consumer” and the pod came up fine. So turns out that when i use a storage class with volume binding mode set to “immediate”, i get that error, but when the volume binding mode is set to “wait for first consumer” i don’t get the error and it works fine.

Can i get an input on this? Thank you

Also, I setup a deployment of sonarqube using postgresql version 14.2.0. Does this postgresql version work with sonarqube? Thank you

the data directory will hold the elasticsearch indeces. they will be recreated from the data in the database, but this takes some time and depending of the size of data that you expect in your instance, you may not want this. I personally don’t think there is a need for a extensions or logs PVC on k8s as you would stream the logs to stdout anyway and can configure centralized logging better that way. If you still want to persist the logs, a dedicated PV would be needed.

In regards to the storage class to be used and the errors that you see, this is more related to general k8s administration and is not specific to sonarqube. I already mentioned that you should only have 1 pod of Sonarqube running at a time, else you risk database corruption, loss of session data and general inconsistency.

As for the database versions you can get these information from our documentation: Prerequisites and Overview | SonarQube Docs
As you can see, Postgresql 14 is not yet supported. This does not mean that it does not work, but only that we did not do excessive testing that everything works so that we can guarantee this.

Thank you very much Tobias.

Can we use an external elasticsearch for our sonarqube?

Nope. External elasticsearch is not supported in any edition of sonarqube. The datacenter edition can split search and app nodes but you still can not connect a external elasticsearch.

There is a feature request about that, so you might want to add your vote to it: Support external Elasticsearch cluster - #10

1 Like