19

I am facing the problem which is that I could not access the Kubernetes Ingress on the Browser using it's IP. I have installed K8s and Minikube on Windows 10 Home.

I am following this official document - https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/

  1. First I created the deployment by running this below command on Minikube.

    kubectl create deployment web --image=gcr.io/google-samples/hello-app:1.0

The deployment get created which can be seen on the below image: enter image description here

  1. Next, I exposed the deployment that I created above. For this I ran the below command.

    kubectl expose deployment web --type=NodePort --port=8080

This created a service which can be seen by running the below command:

kubectl get service web

The screenshot of the service is shown below: enter image description here

  1. I can now able to visit the service on the browser by running the below command:

    minikube service web

In the below screenshot you can see I am able to view it on the browser. enter image description here

  1. Next, I created an Ingress by running the below command:

    kubectl apply -f https://k8s.io/examples/service/networking/example-ingress.yaml

By the way the ingress yaml code is:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    spec:
      rules:
        - host: hello-world.info
          http:
            paths:
              - path: /
                pathType: Prefix
                backend:
                  service:
                    name: web
                    port:
                      number: 8080

The ingress gets created and I can verify it by running the below command:

kubectl get ingress

The screenshot for this is given below: enter image description here

The ingress ip is listed as 192.168.49.2. So that means if I should open it in the browser then it should open, but unfortunately not. It is showing site can't be reached. See the below screeshot.

enter image description here

What is the problem. Please provide me a solution for it?

I also added the mappings on etc\hosts file.

192.168.49.2 hello-world.info

Then I also tried opening hello-world.info on the browser but no luck.

In the below picture I have done ping to hello-world.info which is going to IP address 192.168.49.2. This shows etc\hosts mapping is correct:

enter image description here

I also did curl to minikube ip and to hello-world.info and both get timeout. See below image: enter image description here

The kubectl describe services web provides the following details:

Name:                     web
Namespace:                default
Labels:                   app=web
Annotations:              <none>
Selector:                 app=web
Type:                     NodePort
IP:                       10.100.184.92
Port:                     <unset>  8080/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  31880/TCP
Endpoints:                172.17.0.4:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

The kubectl describe ingress example-ingress gives the following output:

Name:             example-ingress
Namespace:        default
Address:          192.168.49.2
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host              Path  Backends
  ----              ----  --------
  hello-world.info
                    /   web:8080   172.17.0.4:8080)
Annotations:        nginx.ingress.kubernetes.io/rewrite-target: /$1
Events:             <none>

Kindly help. Thank you.

yogihosting
  • 5,494
  • 8
  • 47
  • 80
  • On running `minikube service web --url `, it gives me `http://127.0.0.1:42459`. The port gets changed every time I run tthe `minikube service web --url ` command. About the ports - I am just following the URL of the offcial docs (link given at the question itself). – yogihosting Feb 20 '21 at 19:19
  • The `kubectl describe services web` shows service details. I have added its details on the question. Please have a look to it. Thank you. – yogihosting Feb 20 '21 at 19:51
  • having the exact same issue as OP. I tried the same set of yamls which work perfectly fine in macbook but windows. In macbook, I can simply access things via browser with the domain name specified in host table; In windows, ingress is not working except `minikube ssh` and `curl domain-name-in-host` then it returns data back – fanngalinga Feb 21 '21 at 14:47

9 Answers9

7

Having same issue as OP and things only work in minikube ssh, sharing the ingress.yaml below.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: frontend-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  defaultBackend:
    service:
      name: default-http-backend
      port:
        number: 80
  rules:
    - host: myapp-com # domain (i.e. need to change host table)
      http:
        paths: # specified path below, only be working when there is more than 1 path; If only having 1 path, it's always using / as path
          - path: /
            pathType: Prefix
            backend:
              service: 
                name: frontend-service # internal service
                port: 
                  number: 8080 # port number that internal service exposes
          - path: /e($|/)(.*)
            pathType: Prefix
            backend:
              service: 
                name: express-service # internal service
                port: 
                  number: 3000 # port number that internal service exposes

fanngalinga
  • 186
  • 2
  • 6
  • can you explain me, how to use minikube ssh in my case? What I did is simply updated your ingress with needed changes for my case. Then i checked by putting ingress ip address on the browser, but still nothing changed. The problem persists. – yogihosting Feb 21 '21 at 18:08
  • 3
    hi @yogihosting, sorry for replying you late. Once you setup the ingress with necessary change, i guess you are in the powershell of windows with minikube running right? Make sure you ‘enable addons ingress’ and have a separate console running ‘minikube tunnel’ as well. Also, add the hostname and ip address to windows’ host table. Then type ‘minikue ssh’ in powershell, it gives you command line. Then you can ‘curl myapp.com’ then you should get response as expected – fanngalinga Feb 25 '21 at 13:25
  • 4
    Thank you. Worked for me. So conclusion is that on the browser it will not open. However we can curl it from minikube ssh – yogihosting Mar 01 '21 at 10:30
3

In my case (win10 + minikube + ingress minikube addon) the following helped:

  1. Set custom domain IP to 127.0.01 in %WINDIR%\System32\drivers\etc\hosts file, i.e. by adding line 127.0.0.1 my-k8s.com
  2. Get ingress pod name: kubectl get pods -n ingress-nginx
  3. Start port forwarding: kubectl -n ingress-nginx port-forward pod/ingress-nginx-controller-5d88495688-dxxgw --address 0.0.0.0 80:80 443:443, where you should replace ingress-nginx-controller-5d88495688-dxxgw with your ingress pod name.
  4. Enjoy using ingress on custom domain in any browser (but only when port forwarding is active)
Antonimus
  • 31
  • 2
3
  1. Make sure pod to pod communication is open in minikube cluster. You can enable it by running below commands
    minikube ssh 
    sudo ip link set docker0 promisc on 
    
  2. Make sure to install minikube ingress, ingress dns.
    minikube addons enable ingress
    minikube addons enable ingress-dns
    
2

For those wondering, this is a known issue with minikube, ingress is supported out-of-the-box on linux only.

minikube tunnel is a good fix, see this answer.

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

Try removing this annotation. nginx.ingress.kubernetes.io/rewrite-target: /$1

And add this annotation:

annotations:
    nginx.ingress.kubernetes.io/default-backend: ingress-nginx-controller
    kubernetes.io/ingress.class: nginx
    ## tells ingress to check for regex in the config file
    nginx.ingress.kubernetes.io/use-regex: "true"

Also, update your route as:

 - path: /?(.*) ## instead of just '/'
   backend:
     serviceName: web
     servicePort: 8080
Karan Kumar
  • 2,678
  • 5
  • 29
  • 65
  • The ingress IP and minikube IP is coming out to be same for me which is 192.168.49.2. So it makes no difference. – yogihosting Feb 20 '21 at 19:34
1

I was in the same problem, the easiest solution that I found was modified the host windows file, but instead using the "minikube ip" use 127.0.0.1, and in ahotner terimnal run $ minikube tunnel With this you can open hello-world.info in the browser

Facuellarg
  • 96
  • 3
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 08 '22 at 04:34
1

If you're running an Ingress controller on any OS other than Linux you need to pay attention to the message displayed when you enable the Ingress addon. To wit...

PS C:\Development\kubernetes\service\ingress> minikube addons enable ingress
    �  ingress is an addon maintained by Kubernetes. For any concerns contact minikube on GitHub.
    You can view the list of minikube maintainers at: https://github.com/kubernetes/minikube/blob/master/OWNERS
    �  After the addon is enabled, please run "minikube tunnel" and your ingress resources would be available at "
    127.0.0.1"
        ▪ Using image k8s.gcr.io/ingress-nginx/controller:v1.2.1
        ▪ Using image k8s.gcr.io/ingress-nginx/kube-webhook-certgen:v1.1.1
        ▪ Using image k8s.gcr.io/ingress-nginx/kube-webhook-certgen:v1.1.1
    �  Verifying ingress addon...
    �  The 'ingress' addon is enabled
    PS C:\Development\kubernetes\service\ingress>

The thing to take away from this is that - on an O/S other than Linux - the IP address is 127.0.0.1 NOT whatever IP you see when you run > kubectl get ingress. This is because - on an OS other than Linux - you need minikube tunnel running as a 'bridge' between 127.0.0.1 and whatever IP the Ingress controller is using. It's 127.0.0.1 you need to reference in your hosts file, not the IP shown in > kubectl get ingress. Luck.

Clarius
  • 1,183
  • 10
  • 10
0

I believe that if you check the ingress details you will find the right IP

kubectl describe ingress example-ingress

Check the Docs for more details about ingress

If the above doesn't help try this manifest. Check this Source

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    # If the class annotation is not specified it defaults to "gce".
    kubernetes.io/ingress.class: "gce"
spec:
  rules:
  - http:
      paths:
      - path: /*
        backend:
          serviceName: test
          servicePort: 1111
Aris
  • 984
  • 8
  • 22
  • 1
    Your code is based on Google Kubernetes Engine which will not work for me since I am doing it on locally in my pc. – yogihosting Feb 21 '21 at 05:11
0

Not only these might be needed

minikube ssh 
sudo ip link set docker0 promisc on 

minikube addons enable ingress
minikube addons enable ingress-dns

but I would also try:

minikube delete 

and start from scratch, especially if you deployed something before.

Sayaman
  • 1,145
  • 4
  • 14
  • 35