简体   繁体   中英

Kubernetes networking confusion on google cloud

I'm fairly new to Kube.netes 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 this guide , I was able to set everything up as written there - no problems, I got to see the hello-app output.

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 --image=gcr.io/google-samples/hello-app:1.0 (as done in the tutorial) I wanted to deploy a standard nginx 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 hello-app exposes port 8080 the standard port for the nginx container is 80 . So, naively, I thought exposing (ie, creating a service) with this altered command should do the trick:

kubectl expose deployment hello-app --port=8080 --target-port=80

where instead of having target-port=8080 as for the hello-app, I put target-port=80 . 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 "404 - Not Found" 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?

If you notice the tutorial inside the ingress configuration path: "/hello"

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-resource
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - host: "34.122.88.204.nip.io"
    http:
      paths:
      - pathType: Prefix
        path: "/hello"
        backend:
          service:
            name: hello-app
            port:
              number: 8080

you might have updated port number and service name config however if path /hello which means you request is going to Nginx container but not able to file the page hello.html so it's giving you 404 .

You hit endpoint IP/hello (Goes to Nginx ingress controller)--> checked for path /hello and forwarded request to service --> hello-app (service forwarded request to PODs) --> Nginx POD (it doesn't have anything at path /hello so 404)

404 written by Nginx side, in your case either it will be Nginx ingress controller or else container(POD) itself.

So try you ingress config without setting path path: "/" and hit the endpoint you might see the output from Nginx.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM