Ingress file for Angular+Springboot application

12/26/2021

I have an Angular + Spring boot microservices application where there are about 10 backend microservices. Its a pretty big application with more than may be 100 REST end points. We are thinking to move to on prem kubernetes. I wonder how do I define the ingress file, do I need to define all of the application REST end points in my spring application in ingress also? I checked a couple of examples and I could see they use ingress as kind of Spring API gateway. Is that the correct architecture? Could anyone point me to a proper example?

-- Albie Antony
angular
kubernetes
kubernetes-ingress
nginx-ingress
spring-boot

1 Answer

12/26/2021

Mostly it depends on your requirement, what you are trying to use.

If you are just planning to use the Nginx ingress with your sprint boot you can simply use the Nginx ingress controller and set the ingress.

While if you have requirements of API gateway features like reate limiting, API key, basic auth, and others you need to use the API gateway like Kong and all.

about 10 backend microservices. Its a pretty big application with more than may be 100 REST end points.

you can create the 1 ingresses for each microservice with different domain routing or else with different path-based routing.

Sub-Domain based routing

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
  rules:
    - host: service-1.example.com
      http:
        paths:
          - backend:
              serviceName: service-1
              servicePort: 9000
            path: /(.*)
    - host: service-2.example.com
      http:
        paths:
          - backend:
              serviceName: service-2
              servicePort: 8000
            path: /(.*)
    - host: service-3.example.com
      http:
        paths:
          - backend:
              serviceName: service-3
              servicePort: 8000
            path: /(.*)

Path based routing with single domain api.example.com

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  -  host: api.example.com 
     http:
      paths:
      - path: /service-1
        pathType: Prefix
        backend:
          service:
            name: service-1
            port:
              number: 80
      - path: /service-2
        pathType: Prefix
        backend:
          service:
            name: service-2
            port:
              number: 80

So domain one will route your request to service when any request goes to that specific service.

service-2.example.com ---> service-2 
service-3.example.com ---> service-3 

While in path-based Nginx will redirect requests based on path prefix in URL

api.example.com/service-2/* ---> service-2 
-- Harsh Manvar
Source: StackOverflow