Home > Enterprise >  how to divide the request using ingress?
how to divide the request using ingress?

Time:11-05

I have application "test.abc.com". I want to transfer request between different service.

Example or Expected output

  • when user hit test.abc.com --> it will go to abc-demo-frontend-external service
  • when user hit test.abc.com/main.js --> it will go to abc-demo-frontend service

I added below code but it is not working

current output when user hit test.abc.com or test.abc.com/main.js both request going to abc-demo-frontend ? why ?

apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: test-demo-frontend-ingress
      annotations:
        kubernetes.io/ingress.class: nginx
        nginx.ingress.kubernetes.io/ssl-redirect: 'false'
        nginx.ingress.kubernetes.io/use-regex: "true"
    spec:
      rules:
        - host: "test.abc.com"
          http:
            paths:
              - path: /*
                pathType: ImplementationSpecific
                backend:
                  service:
                    name: abc-demo-frontend
                    port:
                      number: 80
              - path: /
                pathType: ImplementationSpecific
                backend:
                  service:
                    name: abc-demo-frontend-external
                    port:
                      number: 80

any idea..?

CodePudding user response:

You can try

apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: test-demo-frontend-ingress
      annotations:
        kubernetes.io/ingress.class: nginx
        nginx.ingress.kubernetes.io/ssl-redirect: 'false'
        nginx.ingress.kubernetes.io/use-regex: "true"
    spec:
      rules:
        - host: "test.abc.com"
          http:
            paths:
              - path: /(. \.(css|js))
                pathType: ImplementationSpecific
                backend:
                  service:
                    name: abc-demo-frontend
                    port:
                      number: 80
              - path: /
                pathType: ImplementationSpecific
                backend:
                  service:
                    name: abc-demo-frontend-external
                    port:
                      number: 80
  • Related