0
votes

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

2
can you post the ingress yamlArghya Sadhu
posted by editing it.Gabriel García Garrido
what is the correct link your spring boot app/service are listening to serve the requests? / /ui or /admin/ui ??Will R.O.F.

2 Answers

1
votes

The problem is that your spring boot admin interface has no way to know that you're using "/admin" suburl.

nginx.ingress.kubernetes.io/rewrite-target: /$1 ask nginx to rewrite your url matching the second group. So when you're hitting: https://XXXXX/admin/ui nginx rewrite your url to https://XXXXXX/ui and then send it to spring boot.

I don't know well spring boot but you should have a way to provide him a suburl so instead of serving to /ui it server to /$BASE_URL/ui.

Then weather how it works you might need to change how nginx rewrite the url by something like:

  • path: ^(/admin/)(.+)\
  • nginx.ingress.kubernetes.io/rewrite-target: $1/$2
0
votes

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é