0

I want to organize my web apis iwth kubernetes ingress tool.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: myapp-api-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    # nginx.ingress.kubernetes.io/use-regex: "true"
    # nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - host: api.myapp.com
    http:
      paths:
      - pathType: Prefix
        path: /catalog
        backend:
          service:
            name: myapp-catalog-service
            port: 
              number: 80
      - pathType: Prefix
        path: /identity
        backend:
          service:
            name: myapp-identity-service
            port: 
              number: 80

With this configuration, I can access the "api.myapp.com/catalog".

But "api.myapp.com/catalog" is 404 not found. How can fix this configuration?

barteloma
  • 6,403
  • 14
  • 79
  • 173
  • While Stack Overflow does permit certain questions about Kubernetes, we require that they (like all questions asked here) be specifically related to programming. This question does not appear to be specifically related to programming, but ingress configuration, which makes it off-topic here. You might be able to ask questions like this one on [sf] or [DevOps](https://devops.stackexchange.com/). – Turing85 Jan 01 '23 at 17:50
  • Did you mean api.myapp.com/identdity is 404 not found? Can you add to your question the result of kubectl get svc -n -o wide.? – Ralle Mc Black Jan 02 '23 at 13:16

1 Answers1

1

Seems to be an issue with rewrite annotation that might cause the 404 error. Can you give the below annotation in the yaml and give a try :

 nginx.ingress.kubernetes.io/rewrite-target: /$2

As per this rewrite target example , These $2 placeholders can be used as parameters in the rewrite-target annotation. This Target URI where the traffic must be redirected.

As per Kubernetes ingress update your yaml as below example which can be accessed from foo.bar.com/foo from port 4200 and foo.bar.com/bar from port 8080.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: simple-fanout-example
spec:
  rules:
  - host: foo.bar.com
    http:
      paths:
      - path: /foo
        pathType: Prefix
        backend:
          service:
            name: service1
            port:
              number: 4200
      - path: /bar
        pathType: Prefix
        backend:
          service:
            name: service2
            port:
              number: 8080
    

Refer to this ingress path matching doc and SO

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
Hemanth Kumar
  • 2,728
  • 1
  • 4
  • 19