Windows10 上无法通过 NodePort 或 ClusterIP 访问 Minikube 服务
Minikube Services cannot be accessed over NodePort or ClusterIP on Windows10
我正在 Windows10 机器上的本地 minikube 集群上测试一些东西。我在我的本地 minikube 集群上部署了我的测试部署并向其添加了一个服务以通过 NodePort 访问它,但我无法访问它。
PS C:\Users\Admin> kubectl get all -n web -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/nginx-webserver-deploy-79b6588b5f-mllnf 1/1 Running 0 134m 172.17.0.5 minikube <none> <none>
pod/nginx-webserver-deploy-79b6588b5f-rvtxt 1/1 Running 0 134m 172.17.0.7 minikube <none> <none>
pod/nginx-webserver-deploy-79b6588b5f-xqzwz 1/1 Running 0 134m 172.17.0.6 minikube <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/nginx-webserver-service NodePort 10.96.115.194 <none> 80:30008/TCP 132m app=nginx-webserver,tier=frontend
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
deployment.apps/nginx-webserver-deploy 3/3 3 3 134m nginx-webserver nginx:1.20.2 app=nginx-webserver,tier=frontend
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
replicaset.apps/nginx-webserver-deploy-79b6588b5f 3 3 3 134m nginx-webserver nginx:1.20.2 app=nginx-webserver,pod-template-hash=79b6588b5f,tier=
frontend
PS C:\Users\Admin> kubectl describe svc nginx-webserver-service -n web
Name: nginx-webserver-service
Namespace: web
Labels: <none>
Annotations: <none>
Selector: app=nginx-webserver,tier=frontend
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.96.115.194
IPs: 10.96.115.194
Port: http 80/TCP
TargetPort: 80/TCP
NodePort: http 30008/TCP
Endpoints: 172.17.0.5:80,172.17.0.6:80,172.17.0.7:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
但是我无法使用 nodeport 方法连接:
PS C:\Users\Admin> curl 10.96.115.194:30008
curl : Unable to connect to the remote server
At line:1 char:1
+ curl 10.96.115.194:30008
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
我尝试完全禁用 Windows 防火墙,但没有成功。
我一定是遗漏了一些核心但还没有弄清楚的东西。
我找到了解决方案。
与 Linux 不同,在 Windows10.
上使用服务定义 yaml 文件上的指定端口访问 NodePort 并不是一件简单的事情
在 Windows10 上,必须按如下方式完成:
PS C:\Users\Admin> minikube service nginx-webserver-service -n web
|-----------|-------------------------|-------------|---------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|-------------------------|-------------|---------------------------|
| web | nginx-webserver-service | http/80 | http://192.168.49.2:30008 |
|-----------|-------------------------|-------------|---------------------------|
* Starting tunnel for service nginx-webserver-service.
|-----------|-------------------------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|-------------------------|-------------|------------------------|
| web | nginx-webserver-service | | http://127.0.0.1:61410 |
|-----------|-------------------------|-------------|------------------------|
* Opening service web/nginx-webserver-service in default browser...
! Because you are using a Docker driver on windows, the terminal needs to be open to run it.
* Stopping tunnel for service nginx-webserver-service.
这将在您的默认网络浏览器上自动打开公开的服务。
否则,您可以让它直接生成 URL 而不是自动打开。
PS C:\Users\Admin> minikube service nginx-webserver-service -n web --url
* Restarting the docker service may improve performance.
* Starting tunnel for service nginx-webserver-service.
|-----------|-------------------------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|-------------------------|-------------|------------------------|
| web | nginx-webserver-service | | http://127.0.0.1:52665 |
|-----------|-------------------------|-------------|------------------------|
http://127.0.0.1:52665
! Because you are using a Docker driver on windows, the terminal needs to be open to run it.
* Stopping tunnel for service nginx-webserver-service.
我正在 Windows10 机器上的本地 minikube 集群上测试一些东西。我在我的本地 minikube 集群上部署了我的测试部署并向其添加了一个服务以通过 NodePort 访问它,但我无法访问它。
PS C:\Users\Admin> kubectl get all -n web -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/nginx-webserver-deploy-79b6588b5f-mllnf 1/1 Running 0 134m 172.17.0.5 minikube <none> <none>
pod/nginx-webserver-deploy-79b6588b5f-rvtxt 1/1 Running 0 134m 172.17.0.7 minikube <none> <none>
pod/nginx-webserver-deploy-79b6588b5f-xqzwz 1/1 Running 0 134m 172.17.0.6 minikube <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/nginx-webserver-service NodePort 10.96.115.194 <none> 80:30008/TCP 132m app=nginx-webserver,tier=frontend
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
deployment.apps/nginx-webserver-deploy 3/3 3 3 134m nginx-webserver nginx:1.20.2 app=nginx-webserver,tier=frontend
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
replicaset.apps/nginx-webserver-deploy-79b6588b5f 3 3 3 134m nginx-webserver nginx:1.20.2 app=nginx-webserver,pod-template-hash=79b6588b5f,tier=
frontend
PS C:\Users\Admin> kubectl describe svc nginx-webserver-service -n web
Name: nginx-webserver-service
Namespace: web
Labels: <none>
Annotations: <none>
Selector: app=nginx-webserver,tier=frontend
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.96.115.194
IPs: 10.96.115.194
Port: http 80/TCP
TargetPort: 80/TCP
NodePort: http 30008/TCP
Endpoints: 172.17.0.5:80,172.17.0.6:80,172.17.0.7:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
但是我无法使用 nodeport 方法连接:
PS C:\Users\Admin> curl 10.96.115.194:30008
curl : Unable to connect to the remote server
At line:1 char:1
+ curl 10.96.115.194:30008
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
我尝试完全禁用 Windows 防火墙,但没有成功。
我一定是遗漏了一些核心但还没有弄清楚的东西。
我找到了解决方案。
与 Linux 不同,在 Windows10.
上使用服务定义 yaml 文件上的指定端口访问 NodePort 并不是一件简单的事情在 Windows10 上,必须按如下方式完成:
PS C:\Users\Admin> minikube service nginx-webserver-service -n web
|-----------|-------------------------|-------------|---------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|-------------------------|-------------|---------------------------|
| web | nginx-webserver-service | http/80 | http://192.168.49.2:30008 |
|-----------|-------------------------|-------------|---------------------------|
* Starting tunnel for service nginx-webserver-service.
|-----------|-------------------------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|-------------------------|-------------|------------------------|
| web | nginx-webserver-service | | http://127.0.0.1:61410 |
|-----------|-------------------------|-------------|------------------------|
* Opening service web/nginx-webserver-service in default browser...
! Because you are using a Docker driver on windows, the terminal needs to be open to run it.
* Stopping tunnel for service nginx-webserver-service.
这将在您的默认网络浏览器上自动打开公开的服务。
否则,您可以让它直接生成 URL 而不是自动打开。
PS C:\Users\Admin> minikube service nginx-webserver-service -n web --url
* Restarting the docker service may improve performance.
* Starting tunnel for service nginx-webserver-service.
|-----------|-------------------------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|-------------------------|-------------|------------------------|
| web | nginx-webserver-service | | http://127.0.0.1:52665 |
|-----------|-------------------------|-------------|------------------------|
http://127.0.0.1:52665
! Because you are using a Docker driver on windows, the terminal needs to be open to run it.
* Stopping tunnel for service nginx-webserver-service.