ASB
ASB

Reputation: 31

404 Error with GKE ingress. I am on a Google Kubernetes cluster

404 Error with GKE ingress. I am on a Google Kubernetes cluster.

  1. Created a deployment

kubectl create deployment my-deploy --image=nginx

  1. Exposed it to a NodePort service

kubectl expose deployment my-deploy --name=my-svc --type=NodePort --port=80

  1. Created an Ingress resource
kind: Ingress
metadata:
  name: my-ingress
spec:
  rules:
  - host: foo.bar.com
    http:
      paths:
      - path: /bar
        backend:
          serviceName: my-svc 
          servicePort: 80

ingress description

This automatically created a LoadBalancer as expected with IP 34.95.98.151

  1. Added an entry to my windows hosts file located under “C:\Windows\System32\drivers\etc”

  2. On accessing http://foo.bar.com/bar from my local machine, I get the following 404 error

404 Error

I was hoping for NGINX main page to show up. I would very much appreciate it if someone can help me with this.

Upvotes: 0

Views: 1125

Answers (1)

Olivercodes
Olivercodes

Reputation: 1058

If NGINX itself is not serving the /bar path it would be expected to return a 404, beacuse your ingress is just passing that path along. You would get the same 404 running nginx on your computer (no k8s involved) if it wasn't serving anything on /bar.


Here I have an ingress with the /bar set in path enter image description here

Change path in your yaml from: /bar to just /

Here I have an ingress with path set to / enter image description here

Or, you can create a rewrite, but I think that's more complex than you need.

https://kubernetes.github.io/ingress-nginx/examples/rewrite/#rewrite-target

Upvotes: 1

Related Questions