My test web app is showing up error, I am using nginx in Dockerfile - ingress in kubernetes minikube

1/17/2019

I am trying ingress resource in kubernetes (minikube). I have created pod and NodePort service and it works fine when I curl 192.168.99.100:30290

then I created ingress with / path and it still works fine if I add curl **-kL** 192.168.99.100

But when I add /anypath in ingress paths path it return error page when I curl **-kL** 192.168.99.100/anypath

kind: Pod apiVersion: v1 metadata: name: test-web labels: app: test-web spec: containers: - name: test-web image: aamirpinger/test-web ports: - containerPort: 80 # default nginx port

---

kind: Service apiVersion: v1 metadata: name: test-web-service spec: selector: app: test-web ports: - port: 8080 targetPort: 80 # default nginx port type: NodePort

---

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: pwa-ingress spec: rules: - http: paths: - path: /anypath backend: serviceName: test-web-service servicePort: 8080

Resource List

kubectl get pod,svc,ingress NAME READY STATUS RESTARTS AGE pod/test-web 1/1 Running 0 7m

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 11m service/test-web-service NodePort 10.98.17.107 <none> 8080:30290/TCP 7m NAME HOSTS ADDRESS PORTS AGE ingress.extensions/pwa-ingress * 10.0.2.15 80 7m

curl -kL 192.168.99.100/anypath

Received following Result

<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.15.5</center>
</body>
</html>

Expected following Result

<html>
<head>
<title>Test Page</title>

</head>
<body>
<h1>Hello World</h1>
</body>
</html>

anyone who know what I am missing in above to make it work properly?

-- A-P
kubernetes
kubernetes-ingress
minikube
nginx
nginx-ingress

3 Answers

1/17/2019

Ahhhh!!! Finally got my answer. annotation: "nginx.ingress.kubernetes.io/rewrite-target: /" I was doing annotation but missing "nginx." in the start which was only cause of error and took my whole day. The purpose of this line is actually to redirect to root from any route we write ahead of curl . As root is the place where normally we have our entry point i.e. index.html in my case.

-- A-P
Source: StackOverflow

1/17/2019

If you manually start the docker container with nginx with port 80 exposed as some local port, does it work navigating to /anypath ? Do you have access to nginx access logs from your pod ?

-- Andrei Dascalu
Source: StackOverflow

1/17/2019

Does your web app handle this path? From the nginx side everything seems to be ok, it handles the request. You could try the "nginx.ingress.kubernetes.io/rewrite-target: /" annotation so the nginx will rewrite the desired target in the request.

-- Artem Timchenko
Source: StackOverflow