Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not access Kubernetes Ingress in Browser on Windows Home with Minikube?

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.

like image 362
yogihosting Avatar asked Feb 19 '21 10:02

yogihosting


People also ask

How do I use minikube on Windows?

To install the latest minikube beta release on x86-64 Windows using .exe download: Download and run the installer for the latest beta release. Add the minikube.exe binary to your PATH . Make sure to run PowerShell as Administrator.

What is minikube ingress DNS?

The ingress-dns addon acts as a DNS service that runs inside your Kubernetes cluster. All you have to do is install the service and add the minikube ip as a DNS server on your host machine. Each time the DNS service is queried, an API call is made to the Kubernetes master service for a list of all the ingresses.

How do I enable Nginx ingress in Kubernetes?

Enable the Ingress controller. To enable the NGINX Ingress controller, run the following command: minikube addons enable ingress. Verify that the NGINX Ingress controller is running. kubectl get pods -n kube-system. Note: This can take up to a minute.

Why is the ingress addon not working in minikube?

Enabling Ingress If you follow the instructions from the minikube site that ask you to enablethe ingress addon, you will face either that the addon is not supported or uses the internal WSL2 IP for the LoadBalancer. Enabling the ingress addon will not work, as the IP used is not accessible from your Windows environment.

How do I run a minikube tunnel on Windows?

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.

Does Nginx ingress controller work with minikube and Docker?

However, using WSL2 with Docker and Minikube brought not few challenges to make it work smoothly. In this post, I will cover how to make the Nginx Ingress controller work with Minikube when creating a cluster that is running on Docker instead of the traditional virtual machine.


3 Answers

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

like image 153
fanngalinga Avatar answered Oct 22 '22 20:10

fanngalinga


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)
like image 31
Antonimus Avatar answered Oct 22 '22 18:10

Antonimus


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
like image 24
Karan Kumar Avatar answered Oct 22 '22 19:10

Karan Kumar