Search code examples
spring-booturlkubernetesadminkubernetes-ingress

Spring boot admin Kubernetes Ingress


I'm trying to add an spring boot admin interface to some microservice that are deployed in kubernetes cluster. the spring boot admin app has the following configuration:

spring:
        application:
          name: administrator-interface
        boot:
          admin:
            context-path: "/ui"
      server:
        use-forward-headers: true

The kubernetes cluster has an ingress that works as an api gateway:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ template "fullname" . }}
  labels:
    app: {{ template "name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
  annotations:
    {{- range $key, $value := .Values.ingress.annotations }}
    {{ $key }}: {{ $value | quote }}
    {{- end }}
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
    {{- range $host := .Values.ingress.hosts }}
    - host: {{ $host }}
      http:
        paths:
          - path: /admin/(.+)
            backend:
              serviceName: administrator-interface-back
              servicePort: 8080
    {{- end -}}
  {{- if .Values.ingress.tls }}
  tls:
{{ toYaml .Values.ingress.tls | indent 4 }}
  {{- end -}}
{{- end -}}

when I try to see the spring boot admin ui I had the following error:

URL in explorer: https://XXXXXX(thisisgivenBYDNS)/admin/ui

GET https://XXXXXX/ui/assets/css/chunk-common.6aba055e.css net::ERR_ABORTED 404

The URL is wrong because it should be https://XXXXXX/admin/ui/assets/css/chunk-common.6aba055e.css

It is not adding the /admin path that is given by the ingess

How can i solve this and configure an aditional path to serve the static content in the request from the right URL?

Thanks in advance


Solution

  • Finally I found the solution.

    Spring boot admin has a tool for that called "public URL"

          spring:
            application:
              name: administrator-interface
            boot:
              admin:
                context-path: "/ui"
                ui:
                  public-url: "https://XXX/admin/ui"
          server:
            use-forward-headers: true
    

    whith such configuration I am telling spring boot admin that i want to connect with a context /ui but when trying to load resources it should make the request to /admin/ui.

    Now i can connect with the interface trought https:/XXX/ui and is sending request to load resources from https://XXX/admin/ui adding the prefix set by ingress

    Thank you @Noé