Tengo esta url base api.example.com
Entonces, ingress-nginx obtendrá la solicitud de api.example.com y debería seguir las cosas.
Reenviar api.example.com/customer a customer-srv
No funciona, reenvía mtach completo a customer-srv ie /customer/requested_url
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: ingress-service annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/use-regex: "true" spec: rules: - host: api.example.in http: paths: - path: /customer/?(.*) pathType: Prefix backend: service: name: customer-srv port: number: 3000Intenté usar la anotación de reescritura, pero eso tampoco funciona, sin embargo, funcionó, pero no es lo que quiero lograr.
paths: - path: /?(.*) pathType: Prefix backend: service: name: customer-srv port: number: 3000Por ejemplo,
api.example.com/customer debe ir a http://localhost:3000 no a http://localhost:3000/customer
Aquí está el yaml que usé:
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: ingress-service annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/rewrite-target: /$1 spec: rules: - host: api.example.in http: paths: - path: /customer/?(.*) pathType: Prefix backend: service: name: customer-srv port: number: 3000Para fines de prueba, creé un servidor de eco:
kubectl run --image mendhak/http-https-echo customerY luego un servicio:
kubectl expose po customer --name customer-srv --port 3000 --target-port 80Revisé igress ip:
$ kubectl get ingress NAME CLASS HOSTS ADDRESS PORTS AGE ingress-service <none> api.example.in 192.168.39.254 80 3m43sY le hice un curl para comprobarlo:
curl 192.168.39.254/customer/asd -H "Host: api.example.in" { "path": "/asd", "headers": { "host": "api.example.in", ... } Tenga en cuenta que el servidor de eco repitió una ruta que recibió y, dado que recibió una ruta que se reescribió de /customer/asd a /asd , muestra esta ruta exactamente (/asd).
Así que como ves esto funciona.