Redirect resource path with Nginx Ingress

5/15/2019

My deployment and service, which is working fine,is available via http://my.server.net:32142 - returns the JSON

Here is the output of Service

NAME              TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
ok                NodePort    10.104.118.110   <none>        8080:32142/TCP   92m

Ingress:

NAME          HOSTS                    ADDRESS   PORTS   AGE
ok            my.server.net            80      86m

But i have a challenge with the Ingress which does not redirect me to my desired resource

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ok
  labels:
    app: ok
    system: test
spec:
  rules:
  - host: my.server.net
    http:
      paths:
      - path: /test
        backend:
          serviceName: ok
          servicePort: 8080

Expected Output: http://my.server.net/test and http://my.server.net:32142/test should return the JSON at the moment it returns only a 404 error

-- Mchoeti
kubernetes
kubernetes-ingress
nginx-ingress

1 Answer

5/15/2019

Please try to use custom header in the request, so that your Ingress Controller can find routes for the right host for incoming traffic, otherwise you are hitting default backend (404), like this:

curl http://<IP_ADDRESS*>/test -H 'Host:my.server.net'

where IP_ADDRESS is the IP of LoadBalancer - your Ingress Controller's frontend, eventually you can try to use form <IP_OF_NODE>:<NodePort>, but it depends how you exposed your Ingress Controller.

Please read here more about Ingress configuration for so called: "Name based virtual hosting"

-- Nepomucen
Source: StackOverflow