2

I am following this official k8 ingress tutorial. However I am not able to curl the minikube IP address and access the "web" application.

minikube addons enable ingress
kubectl create deployment web --image=gcr.io/google-samples/hello-app:1.0
kubectl expose deployment web --type=NodePort --port=8080
kubectl apply -f https://k8s.io/examples/service/networking/example-ingress.yaml

I'm able to curl the result of minikube service web --url

    curl http://127.0.0.1:64671 
    Hello, world!
    Version: 1.0.0
    Hostname: web-79d88c97d6-8z8tc 

But not though ingress, with kubectl apply -f https://k8s.io/examples/service/networking/example-ingress.yaml

(I don't have an external IP - just "localhost". )

NGG282 kubernetes-ingress % kubectl get ingress
NAME              CLASS   HOSTS   ADDRESS     PORTS   AGE
example-ingress   nginx   *       localhost   80      66m

This seems to be normal with minikube. Trying to curl the minikube IP:

curl $(minikube ip)
curl: (7) Failed to connect to 192.168.49.2 port 80: Operation timed out

Any help?

----------EDIT :

kubectl get deploy -n ingress-nginx -o yaml

          ports:
          - containerPort: 80
            hostPort: 80
            name: http
            protocol: TCP
          - containerPort: 443
            hostPort: 443
            name: https
            protocol: TCP
          - containerPort: 8443
            name: webhook
            protocol: TCP

kubectl get svc -n ingress-nginx -o yaml
apiVersion: v1
items:
- apiVersion: v1
  kind: Service
  metadata:
    annotations:
      kubectl.kubernetes.io/last-applied-configuration: |
        {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app.kubernetes.io/component":"controller","app.kubernetes.io/instance":"ingress-nginx","app.kubernetes.io/name":"ingress-nginx"},"name":"ingress-nginx-controller","namespace":"ingress-nginx"},"spec":{"ipFamilies":["IPv4"],"ipFamilyPolicy":"SingleStack","ports":[{"appProtocol":"http","name":"http","port":80,"protocol":"TCP","targetPort":"http"},{"appProtocol":"https","name":"https","port":443,"protocol":"TCP","targetPort":"https"}],"selector":{"app.kubernetes.io/component":"controller","app.kubernetes.io/instance":"ingress-nginx","app.kubernetes.io/name":"ingress-nginx"},"type":"NodePort"}}
    creationTimestamp: "2021-12-16T11:41:35Z"
    labels:
      app.kubernetes.io/component: controller
      app.kubernetes.io/instance: ingress-nginx
      app.kubernetes.io/name: ingress-nginx
    name: ingress-nginx-controller
    namespace: ingress-nginx
    resourceVersion: "489"
    uid: 63826bc2-5d90-42f1-861f-f7f082ccf0fb
  spec:
    clusterIP: 10.104.208.171
    clusterIPs:
    - 10.104.208.171
    externalTrafficPolicy: Cluster
    internalTrafficPolicy: Cluster
    ipFamilies:
    - IPv4
    ipFamilyPolicy: SingleStack
    ports:
    - appProtocol: http
      name: http
      nodePort: 30783
      port: 80
      protocol: TCP
      targetPort: http
    - appProtocol: https
      name: https
      nodePort: 30860
      port: 443
      protocol: TCP
      targetPort: https
    selector:
      app.kubernetes.io/component: controller
      app.kubernetes.io/instance: ingress-nginx
      app.kubernetes.io/name: ingress-nginx
    sessionAffinity: None
    type: NodePort
  status:
    loadBalancer: {}
- apiVersion: v1
  kind: Service
  metadata:
    annotations:
      kubectl.kubernetes.io/last-applied-configuration: |
        {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app.kubernetes.io/component":"controller","app.kubernetes.io/instance":"ingress-nginx","app.kubernetes.io/name":"ingress-nginx"},"name":"ingress-nginx-controller-admission","namespace":"ingress-nginx"},"spec":{"ports":[{"appProtocol":"https","name":"https-webhook","port":443,"targetPort":"webhook"}],"selector":{"app.kubernetes.io/component":"controller","app.kubernetes.io/instance":"ingress-nginx","app.kubernetes.io/name":"ingress-nginx"},"type":"ClusterIP"}}
    creationTimestamp: "2021-12-16T11:41:35Z"
    labels:
      app.kubernetes.io/component: controller
      app.kubernetes.io/instance: ingress-nginx
      app.kubernetes.io/name: ingress-nginx
    name: ingress-nginx-controller-admission
    namespace: ingress-nginx
    resourceVersion: "483"
    uid: fe797532-27c9-4dd1-a1bc-0662a3d2a4da
  spec:
    clusterIP: 10.106.175.35
    clusterIPs:
    - 10.106.175.35
    internalTrafficPolicy: Cluster
    ipFamilies:
    - IPv4
    ipFamilyPolicy: SingleStack
    ports:
    - appProtocol: https
      name: https-webhook
      port: 443
      protocol: TCP
      targetPort: webhook
    selector:
      app.kubernetes.io/component: controller
      app.kubernetes.io/instance: ingress-nginx
      app.kubernetes.io/name: ingress-nginx
    sessionAffinity: None
    type: ClusterIP
  status:
    loadBalancer: {}
kind: List
metadata:
  resourceVersion: ""
  selfLink: ""
gaut
  • 5,771
  • 1
  • 14
  • 45
  • check your service port section with the port in your deployment, I'm sure you messed something there. – hakik ayoub Dec 15 '21 at 15:45
  • I couldn't possibly miss something since I'm just using the links to the files directly from the tutorial – gaut Dec 16 '21 at 12:21

2 Answers2

4

OK so apparently this is a known issue with minikube, Ingress works properly on linux only.

The ingress, and ingress-dns addons are currently only supported on Linux. See #7332

you need to minikube tunnel on windows/macOS before being able to curl, but still there are differences:

On Windows, both 127.0.0.1 and localhost redirect to the application. On macOS, 127.0.0.1 and localhost show an "nginX not found" message, but curl hello-world.info works only after changing etc/hosts.

gaut
  • 5,771
  • 1
  • 14
  • 45
1

You need to setup your /etc/hosts, I guess the ingress controller wait for requests with an host defined to redirect them, but it's pretty strange that it didn't even respond to the http request with an error.

Could you show what these commands returns ?

kubectl get deploy -n ingress-nginx -o yaml  # only the ports section
kubectl get svc -n ingress-nginx -o yaml
Ludwig
  • 328
  • 1
  • 6
  • Sure, please see my edited answer – gaut Dec 16 '21 at 12:27
  • Thanks, looks good so far, about the curl $(minikube ip) command, is there any chance you setup some firewall rules on your LAN interfaces ? The ingress controller should be reachable right away by accessing port 80 of your host, a curl http://127.0.0.1:80 should return something. When setting /etc/hosts, you can replace whatever 172.17.*.* addresses described by the tutorial by a simple 127.0.0.1, curl commands should work using localhost or hello-world.info then. – Ludwig Dec 16 '21 at 12:42
  • Yes, this returns `curl: (7) Failed to connect to 127.0.0.1 port 80: Connection refused` The same after I disabled the firewall – gaut Dec 16 '21 at 12:43
  • Could you return what `sudo netstat -lptn` gives. I already had issues with k8s local solutions using ipv6, in this case the quickfix was to disable ipv6, restart. Although the `minikube service web --url` shows a curl command on ipv4 address, I'm still a bit suspicious. Also `kubectl get deploy -n ingress-nginx` to see if the nginx ingress deployment is running. – Ludwig Dec 16 '21 at 13:00
  • Yes, running for 80 mins `NAME READY UP-TO-DATE AVAILABLE AGE ingress-nginx-controller 1/1 1 1 80m`. `netstat -a | find "LISTENING"` gives me a bunch of lines but nothing under 127.0.0.1:80 – gaut Dec 16 '21 at 13:05
  • Have you missed the 'l' on the netstat command ? Mandatory to check listening ports. Are you on linux ? – Ludwig Dec 16 '21 at 13:10
  • On Windows for now. `netstat -a | find "LISTENING"` gives me a bunch of lines but nothing under 127.0.0.1:80 – gaut Dec 16 '21 at 13:11
  • I'm not a windows user unfortunately, try restart minikube, check `docker ps`, check with some simple web server container if docker networking (port mapping) is working. Also test the curl command `minikube service web --url` gave if it works, the port displayed should be seen in the netstat | find command. – Ludwig Dec 16 '21 at 13:37
  • yes, it is there when I use that command. Ingress doesn't work unfortunately. BTW I have the same behaviour on macOS as well – gaut Dec 16 '21 at 15:47
  • Maybe it doesn't work on windows, because the port number range 1-1024 is restricted to the system (it's the case on macOS, but avoided with root privileges tho). Also saw somewhere that docker desktop might be more appropriate to run k8s local cluster, here it's pretty difficult to deal with what's under minikube 'hood', you might try to edit the deployment with `kubectl edit deploy -n ingress-nginx *nginx_deploy_name*` and change the hostPort (port used by k8s on your host to map traffic into the pod/container) in the nginx with 80 => 30080 and 443 => 30443. – Ludwig Dec 16 '21 at 16:28