无法使用 Minikube 在 Windows Home 上的浏览​​器中访问 Kubernetes Ingress? [英] Could not access Kubernetes Ingress in Browser on Windows Home with Minikube?

查看:29
本文介绍了无法使用 Minikube 在 Windows Home 上的浏览​​器中访问 Kubernetes Ingress?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临的问题是我无法使用其 IP 访问浏览器上的 Kubernetes Ingress.我已经在 Windows 10 Home 上安装了 K8s 和 Minikube.

我正在关注这个官方文档 -

  1. 接下来,我公开了我在上面创建的部署.为此,我运行了以下命令.

    kubectl 公开部署 web --type=NodePort --port=8080

这创建了一个可以通过运行以下命令看到的服务:

kubectl 获取服务网站

服务截图如下:

  1. 我现在可以通过运行以下命令在浏览器上访问该服务:

    minikube 服务网站

在下面的屏幕截图中,您可以看到我可以在浏览器上查看它.

  1. 接下来,我通过运行以下命令创建了一个 Ingress:

    kubectl apply -f

    入口 ip 列为 192.168.49.2.所以这意味着如果我应该在浏览器中打开它,那么它应该会打开,但不幸的是没有.显示网站无法访问.请参阅下面的截图.

    有什么问题.请给我一个解决方案?

    我还在 etchosts 文件中添加了映射.

    192.168.49.2 hello-world.info

    然后我也尝试在浏览器上打开 hello-world.info 但没有成功.

    在下图中,我对 hello-world.info 执行 ping 操作,IP 地址为 192.168.49.2.这表明 etchosts 映射是正确的:

    我也 curl 到 minikube ip 和 hello-world.info 并且都超时.见下图:

    kubectl describe services web 提供了以下详细信息:

    名称:web命名空间:默认标签:应用程序=网络注释:<none>选择器:app=web类型:节点端口IP:10.100.184.92端口:<unset>8080/TCP目标端口:8080/TCP节点端口:<unset>31880/TCP端点:172.17.0.4:8080会话亲和力:无外部流量策略:集群事件:<无>

    kubectl describe ingress example-ingress 给出以下输出:

    名称:example-ingress命名空间:默认地址:192.168.49.2默认后端:default-http-backend:80(<错误:未找到端点default-http-backend">)规则:主机路径后端---- ---- --------hello-world.info/web:8080 172.17.0.4:8080)注解:nginx.ingress.kubernetes.io/rewrite-target:/$1事件:<无>

    请帮忙.谢谢.

    解决方案

    和 OP 有同样的问题,只能在 minikube ssh 中工作,分享下面的 ingress.yaml.

    apiVersion:networking.k8s.io/v1种类:入口元数据:名称:前端入口注释:nginx.ingress.kubernetes.io/rewrite-target:/$2规格:默认后端:服务:名称:default-http-backend港口:数量:80规则:- 主机:myapp-com # 域(即需要更改主机表)网址:path: # 下面指定路径,只有在超过1条路径时才有效;如果只有 1 条路径,则始终使用/作为路径- 小路:/路径类型:前缀后端:服务:名称:frontend-service # 内部服务港口:number: 8080 # 内部服务暴露的端口号- 路径:/e($|/)(.*)路径类型:前缀后端:服务:name: express-service # 内部服务港口:number: 3000 # 内部服务暴露的端口号

    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:

    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:

    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.

    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:

    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.

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

    I also added the mappings on etchosts 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 etchosts mapping is correct:

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

    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.

    解决方案

    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
    
    

    这篇关于无法使用 Minikube 在 Windows Home 上的浏览​​器中访问 Kubernetes Ingress?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆