Docker for Desktop 运行 Kubernetes - Ip 地址不起作用

Raj*_*san 13 ip desktop docker kubernetes

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
Run Code Online (Sandbox Code Playgroud)

http://<dockerDesktopIdaddress>:<nodeport>

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

总是给出错误。

Cha*_*aya 25

我遇到了同样的问题,解决方法很简单。卷曲本地主机:$NODE_PORT

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

  • 你们是我的英雄!我一整天都在努力获取 k8s 节点外部 IP,但我应该使用简单的“localhost”::facepalm::。早些时候我使用 Minikube,在那里我必须找出外部 IP,在 Windows 版 Docker 上这是没有必要的!多谢! (2认同)
  • 谢谢。这个问题让我很困惑,因为使用 Docker Desktop Kubernetes,我可以使用 localhost:&lt;port&gt; 访问,而使用 Minikube,我不能这样做。使用 Minikube,我必须使用“minikube service &lt;my-service&gt; --url” 来获取 URL,然后才能访问它 (2认同)

小智 5

另一个很好用的命令是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>
Run Code Online (Sandbox Code Playgroud)


Ija*_*han -7

Docker For Windows、Docker For MAC 或 Docker for everything 使用 minikube for kubernetes ,并且您需要获取 minikube 机器的外部 ip。

\n\n

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

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

编辑:

\n\n

根据评论中的建议,如果您不想看到 minikube 机器内部,可以使用以下命令获取外部 IP:

\n\n
 minikube ip\n
Run Code Online (Sandbox Code Playgroud)\n

  • 不,它们是两个不同的东西,使用不同的虚拟化和管理策略。至少在 macOS 上,Docker for Mac 使用 xhyve 来运行底层 VM,而 minikube 使用 VirtualBox。两者都会以不同的方式管理和处理网络。 (5认同)