【发布时间】:2022-01-17 23:09:57
【问题描述】:
我想做什么
在启用了 WSL 2 并使用 Powershell、Windows 上的 Docker、kubectl 和 minikube 的 Windows 11 平台上,尝试从 kubernetes pod 向 Internet/浏览器/API 公开端点。这对于解决我的开发环境至关重要。
会发生什么
根据我在文档和在线中可以找到的任何内容,我认为 Loadbalancer 是用于 的选项。隧道似乎从未发生过。我使用浏览器和 curl 进行了测试。
环境信息
- Windows:Windows 11 专业版
- Windows 上的 Docker:Docker Desktop 4.3.2 (72729)
- Kubernetes:v1.22.3
- Minikube:minikube 版本:v1.24.0
命令 - 执行
这是我为创建服务而执行的命令。
1。创建部署
~ kubectl create deployment hello-world3 --image=nginx:mainline-alpine
deployment.apps/hello-world3 created
~ kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
hello-world3 1/1 1 1 19s
2。公开出站
~ kubectl expose deployment hello-world3 --type=LoadBalancer --port=8080
service/hello-world3 exposed
~ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-world3 LoadBalancer 10.103.203.156 127.0.0.1 8080:30300/TCP 14s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 6d8h
3。创建隧道服务
~ minikube service hello-world3
|-----------|--------------|-------------|---------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|--------------|-------------|---------------------------|
| default | hello-world3 | 8080 | http://192.168.49.2:30300 |
|-----------|--------------|-------------|---------------------------|
* Starting tunnel for service hello-world3.
|-----------|--------------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|--------------|-------------|------------------------|
| default | hello-world3 | | http://127.0.0.1:62864 |
|-----------|--------------|-------------|------------------------|
* Opening service default/hello-world3 in default browser...
! Because you are using a Docker driver on windows, the terminal needs to be open to run it.
当我连接到http://127.0.0.1:8080时,我希望得到“Nginx 欢迎”页面
原来如此
无法访问此站点。连接已重置。
试试看:
检查连接
检查代理和防火墙
运行 Windows 网络诊断程序
ERR_CONNECTION_RESET
同样的情况发生在: http://127.0.0.1:62864/
使用 curl 时的输出
~ curl http://127.0.0.1:8080/* -v
VERBOSE: GET with 0-byte payload
curl : The underlying connection was closed: An unexpected error occurred on a receive.
At line:1 char:1
+ curl http://127.0.0.1:8080/ -v
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
~ curl http://127.0.0.1:62864/ -v
VERBOSE: GET with 0-byte payload
curl : The underlying connection was closed: An unexpected error occurred on a receive.
At line:1 char:1
+ curl http://127.0.0.1:62864/ -v
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
【问题讨论】:
-
很难确定,你做了什么,什么只是 cmets。你能改进你的问题吗?看看stackoverflow.com/editing-help
-
我已经尝试澄清我的问题并改进了编辑。希望读得更好
-
我编辑了你的问题。下次尝试使用代码和引用块。 :)
-
看起来您的 Web 服务 (nginx) 正在侦听端口 80(在 kubernetes 中,因为这是默认设置)。然而,您的端口映射似乎是 8080:30300。
标签: docker kubernetes minikube