0

I want to have an API service that I want to reach under /api, and other requests to fall back to a frontend service.

Peculiar is that this worked locally with minikube, but now that I deployed on Azure Kubernetes Service (I used this official MS tutorial to add an ingress controller), I can not get it to work.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - http:
      paths:
      - path: /api/(.*)
        pathType: Prefix
        backend:
          service:
            name: api-service
            port:
              number: 9002
      - path: /(.*)
        pathType: Prefix
        backend:
          service:
            name: frontend-service
            port:
              number: 9001

That worked just fine on minikube, but on AKS, this causes a timeout when I try to open the publicly available IP. I have tried the following things:

  • Change the frontend path to (/|$)(.*)
    Together with changing the rewrite-target to /$2. kubectl will not even deploy this because the path needs to be absolute.
  • Change the frontend path to /
    Now everything returns the frontend index.html, even if the request is for /style.css or favicon.ico etc. (unless it starts with /api).
  • Change the frontend path to / and remove the rewrite-target
    Then the frontend works fine, but the api service doesn't "fit" as intended. The api service has a call /get-employee, which I want to call under /api/get-employee, but I can't do that unless the api service itself would already have it under /api/get-employee.

How can I add a "root" or "fallback" service while still using rewrite-target?

1 Answer 1

1

I had the same issue when trying Microsofts tutorial. Adding host under the rules section worked for me.

Example:

spec:
  ingressClassName: nginx
  rules:
  - host: {your_app}.northeurope.cloudapp.azure.com
    http:
      paths:
      - path: /test(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: mockserver-service
            port:
              number: 1234
          

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.