Sonar and ingress-nginx controller

Hi,
I am deploying Sonarqube onto an AKS cluster using the Helm chart
I am using the kubernetes ingress-nginx controller

if i deploy everything with a standard ingress just on ‘/’ of my host, it appears to all work fine.
if i deploy the ingress using the target-rewrite, when i browse to sonarqube it just sits on a loading page.

the ingress controller logs show:

    • [04/Aug/2023:12:09:45 +0000] “GET /api/features/list HTTP/2.0” 404 548 “https:/myapp.co.uk/sonarqube/” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36” 32 0.001 [upstream-default-backend] 127.0.0.1:8181 548 0.001 404 7bd950927105823607011c5f5c307648

my ingress config is:
ingress:
enabled: true
ingressClassName: nginx
hosts:
- name: myapp.co.uk
path: /sonarqube(/|$)(.*)
pathType: Prefix
annotations:
# – Additional ingress labels
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/force-ssl-redirect: “true”
nginx.ingress.kubernetes.io/backend-protocol: “HTTP”
nginx.ingress.kubernetes.io/protocol: http
nginx.ingress.kubernetes.io/proxy-body-size: “64m”

thanks :slight_smile:

Hi @Joe_Miles.

Sorry for the delayed response.

Is the snippet you posted your entire values.yaml file? Are you setting the sonarWebContext property? It is defined in the global section of the default values.yaml.

Could you clarify your use case and what you want to achieve? If I understood correctly, you want to be able to have Sonar running on myapp.co.uk/sonarqube.

1 Like

thanks for the response… no i don’t have this set, i must of missed that in my initial pass of the values file…
would i set to:
sonarWebContext: “/sonarqube”
or:
sonarWebContext: “myapp.co.uk/sonarqube

thanks :slight_smile:

@davi.vidal I have tried both but am still getting 404s from the Sonar pod… do i need to not have the ingress controller do the target re-write and pass the full path to the app and let sonar handle it?

You should set sonarWebContext to /sonarqube/ if you want it to be accessible through myapp.co.uk/sonarqube. :slight_smile:

This is a snippet from an example that I used for a local kind setup:

sonarWebContext: /sonarqube/

nginx:
  enabled: true

ingress:
  enabled: true
  ingressClassName: nginx

  hosts:
    - name: sonar.local
      path: /

  annotations:
    kubernetes.io/ingress.class: nginx
    kubernetes.io/tls-acme: "false"
    nginx.ingress.kubernetes.io/proxy-body-size: "128m"
    nginx.ingress.kubernetes.io/proxy-http-version: "1.1"
    nginx.ingress.kubernetes.io/cors-allow-headers: "X-Forwarded-For"
    nginx.ingress.kubernetes.io/enable-cors: "true"
    nginx.ingress.kubernetes.io/configuration-snippet: |
      rewrite ^/(?!sonarqube)(.*)$ http://sonar.local/sonarqube/$1 permanent;

Unrelated tip: you can use ``` for code blocks. :slight_smile:

2 Likes

thanks got it working this way
strange that the target re-write function of the ingress-nginx controller doesn’t seem to work with sonarqube…

sonarWebContext: /sonar/
ingress:
  enabled: true
  ingressClassName: nginx
  hosts:
    - name: myapp.co.uk
      path: /sonar(/|$)(.*)
      pathType: Prefix

  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
     nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
    nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
    nginx.ingress.kubernetes.io/protocol: http
    nginx.ingress.kubernetes.io/proxy-body-size: "128m"

but the solution you provided is working so thanks :slight_smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.