【问题标题】:Docker for Desktop runs the Kubernetes - Ip address is not workingDocker for Desktop 运行 Kubernetes - IP 地址不起作用
【发布时间】:2022-05-02 01:56:28
【问题描述】:

kubectl describe node docker-for-desktop 这将获取适用于 Windows 的 Docker 桌面的 IP 地址。

但是我们在浏览器上用ip:nodeport 运行它却不工作。

nodeport - 是我们在kubernetes集群的services文件中提到的端口号。

请在代码部分找到myservice.yaml文件。

apiVersion: v1
kind: Service
metadata:
  name: xxxx

spec:
  # This defines which pods are going to be represented by this Service
  # The service becomes a network endpoint for either other services
  # or maybe external users to connect to (eg browser)
  selector:
    mykey: webapp
    release: "0-5"

  ports:
    - name: http
      port: 80
      nodePort: 30080
      #this is port number greater than 30000, and it is port of the Node where this cluster is present.

  type: NodePort

http://<dockerDesktopIdaddress>:<nodeport>

nodeport是kubernetes集群服务文件中的端口号。

总是报错。

【问题讨论】:

  • 刚刚编辑了问题以使其更具可读性。也许您想描述您遇到的哪个错误,以便有人可以帮助您。
  • 是的,请添加错误描述。 Docker for Desktop 公开了localhost 上的所有内容,因此应该没有问题。

标签: docker kubernetes ip desktop


【解决方案1】:

我遇到了同样的问题,解决方法很简单。 卷曲 l​​ocalhost:$NODE_PORT

Docker for Mac 在同一主机上运行,​​您可以通过 localhost 调用该服务。

【讨论】:

  • 你们是我的英雄!我整天都在努力获取 k8s 节点外部 IP,但我应该使用简单的 'localhost' ::facepalm::。早些时候我使用的是 Minikube,在那里我必须找出外部 IP,在 Docker for Windows 上没有必要!非常感谢!
  • 谢谢。这个问题让我很困惑,因为使用 Docker Desktop Kubernetes,我可以使用 localhost: 访问,而使用 Minikube,我不能这样做。使用 Minikube,我必须使用 minikube service <my-service> --url 来获取 URL,然后才能访问它
【解决方案2】:

另一个好用的命令是kubectl describe service your-service-name。这样就可以看到所有的kubernetes网络对象了

kubectl describe service configuration-service-service

Name:                     configuration-service-service
Namespace:                default
Labels:                   none
Annotations:              none
Selector:                 app=configuration-service-deployment
Type:                     NodePort
IP:                       10.109.61.232
LoadBalancer Ingress:     localhost
Port:                     <unset>  8080/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  30001/TCP
Endpoints:                10.1.0.40:8080,10.1.0.41:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

【讨论】:

    【解决方案3】:

    仔细检查是否为节点定义了外部 IP。

    kubectl get nodes -o wide
    

    查找服务中定义的 LoadBalancer Ingress

    kubectl describe svc service_name 
    

    记下 LoadBalancer Ingress:在本例中为“localhost”

    所以最后,你可以试试:

    curl http://localhost:PORT 
    

    【讨论】:

      【解决方案4】:

      Docker For Windows , Docker For MAC , or Docker for anything 使用 minikube for kubernetes ,你需要获取 minikube 机器的外部 ip。

      您需要外部 IP 而不是内部 IP,kubectl 只显示内部 IP。

      C02W84XMHTD5:test iahmad$ 
      C02W84XMHTD5:test iahmad$ 
      C02W84XMHTD5:test iahmad$ 
      C02W84XMHTD5:test iahmad$ kubectl describe node minikube | grep -i ip
        InternalIP:  10.0.2.15
      C02W84XMHTD5:test iahmad$ 
      C02W84XMHTD5:test iahmad$ 
      C02W84XMHTD5:test iahmad$ kubectl get svc
      NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
      kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP        30d
      nginx        NodePort    10.107.66.154   <none>        80:32622/TCP   4m
      C02W84XMHTD5:test iahmad$ 
      C02W84XMHTD5:test iahmad$ 
      C02W84XMHTD5:test iahmad$ curl 10.0.2.15:32622
      
      
      çççç^C
      C02W84XMHTD5:test iahmad$ 
      C02W84XMHTD5:test iahmad$ 
      C02W84XMHTD5:test iahmad$ minikube ssh
                               _             _            
                  _         _ ( )           ( )           
        ___ ___  (_)  ___  (_)| |/')  _   _ | |_      __  
      /' _ ` _ `\| |/' _ `\| || , <  ( ) ( )| '_`\  /'__`\
      | ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )(  ___/
      (_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)
      
      $ 
      $ ip a s | grep eth0
      2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
          inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic eth0
      $ 
      $ ip a s | grep eth1
      3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
          inet 192.168.99.105/24 brd 192.168.99.255 scope global dynamic eth1
      $ 
      $ logout
      C02W84XMHTD5:test iahmad$ 
      C02W84XMHTD5:test iahmad$ curl 192.168.99.105:32622
      <!DOCTYPE html>
      <html>
      <head>
      <title>Welcome to nginx!</title>
      <style>
          body {
              width: 35em;
              margin: 0 auto;
              font-family: Tahoma, Verdana, Arial, sans-serif;
          }
      </style>
      </head>
      <body>
      <h1>Welcome to nginx!</h1>
      <p>If you see this page, the nginx web server is successfully installed and
      working. Further configuration is required.</p>
      
      <p>For online documentation and support please refer to
      <a href="http://nginx.org/">nginx.org</a>.<br/>
      Commercial support is available at
      <a href="http://nginx.com/">nginx.com</a>.</p>
      
      <p><em>Thank you for using nginx.</em></p>
      </body>
      </html>
      

      编辑:

      按照cmets的建议,如果不想看minikube机器内部,可以使用如下命令获取外部IP:

       minikube ip
      

      【讨论】:

      • 难道没有minikube ip 命令来获取IP,这样您就不必执行那些额外的步骤了吗?此外,由于最初的问题似乎是使用 Dock for Windows,因此有助于显示该上下文的正确 IP 地址而不是 minikube。
      • Docker 用于 windows 或 docker 用于任何东西都是一样的,我使用 Docker for MAC 来管理 minikube,任何东西的 Docker 对于 kubernetes 都需要 minikube,这是正确的获取方法正确的 ip,无论 Docker 用于什么
      • 不,它们是使用不同虚拟化和管理策略的两个不同的东西。至少在 macOS 上,Docker for Mac 使用 xhyve 运行底层 VM,而 minikube 使用 VirtualBox。两者都将以不同的方式管理和处理网络。
      • 是的,但对于用户来说,它们是相同的,尤其是在这个问题的上下文中。我保证这个解决方案也适用于 docker for windows
      • 你已经在内部ip上运行了curl命令,如何在windows机器上运行。?由于 curl 在 Windows 中不可用。如果可能的话,请你帮我在 windows 中获取 docker-for-desktop 的外部 ip
      猜你喜欢
      • 2019-10-26
      • 2019-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-14
      • 1970-01-01
      • 2016-04-18
      • 1970-01-01
      相关资源
      最近更新 更多