<p>I'm fairly new to Kubernetes and I have played around with it for a few days now to get a feeling for it. Trying out to set up an Nginx Ingress controller on the google-cloud platform following <a href="https://cloud.google.com/community/tutorials/nginx-ingress-gke" rel="nofollow noreferrer">this guide</a>, I was able to set everything up as written there - no problems, I got to see the hello-app output.</p>
<p>However, when I tried replicating this in a slightly different way, I encountered a weird behavior that I am not able to resolve. Instead of using the image <code>--image=gcr.io/google-samples/hello-app:1.0</code> (as done in the tutorial) I wanted to deploy a standard <code>nginx</code> container with a custom index page to see if I understood stuff correctly. As far as I can tell, all the steps should be the same except for the exposed port: While the <code>hello-app</code> exposes port <code>8080</code> the standard port for the <code>nginx</code> container is <code>80</code>. So, naively, I thought exposing (i.e., creating a service) with this altered command should do the trick:</p>
<pre><code>kubectl expose deployment hello-app --port=8080 --target-port=80
</code></pre>
<p>where instead of having <code>target-port=8080</code> as for the hello-app, I put <code>target-port=80</code>. As far as I can tell, all other thins should stay the same, right? In any way, this does not work and when I try to access the page I get a &quot;404 - Not Found&quot; although the container is definitely running and serving the index page (I checked by using port forwarding from the google cloud which apparently directly makes the page accessible for dev purposes). In fact, I also tried several other combinations of ports (although I believe the above one should be the correct one) to no avail. Can anyone explain to my why the routing does not work here?</p>

rammelmueller
<p>If you notice the tutorial inside the ingress configuration <code>path: &quot;/hello&quot;</code></p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-resource
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
    nginx.ingress.kubernetes.io/ssl-redirect: &quot;false&quot;
spec:
  rules:
  - host: &quot;34.122.88.204.nip.io&quot;
    http:
      paths:
      - pathType: Prefix
        path: &quot;/hello&quot;
        backend:
          service:
            name: hello-app
            port:
              number: 8080
</code></pre>
<p>you might have updated <strong>port</strong> number and <strong>service</strong> name config however if path <code>/hello</code> which means you request is going to Nginx container but not able to file the page <strong>hello.html</strong> so it's giving you <strong>404</strong>.</p>
<blockquote>
<p>You hit endpoint IP/hello (Goes to Nginx ingress controller)--&gt;
checked for path <code>/hello</code> and forwarded request to service --&gt;
hello-app (service forwarded request to PODs) --&gt; Nginx POD (it
doesn't have anything at path <code>/hello</code> so 404)</p>
</blockquote>
<p><strong>404</strong> written by <strong>Nginx</strong> side, in your case either it will be <strong>Nginx ingress controller</strong> or else container(POD) itself.</p>
<p>So try you ingress config without setting <strong>path</strong> <code>path: &quot;/&quot;</code> and hit the endpoint you might see the output from Nginx.</p>
