问题描述
我正在尝试使用 wsl2 和 docker 桌面在本地运行 bookinfo 示例。我在尝试通过网关访问 productpage 服务时遇到问题,因为我的连接被拒绝。我不确定我是否错过了什么。这是我在互联网上搜索了很多之后所做的
- 部署了 bookinfo 示例中的所有服务并全部运行,我可以使用 kubectl exec 从其他服务卷曲 productpage
- 使用示例中的文件部署 bookinfo-gateway,在默认命名空间下没有任何更改
Name: bookinfo-gateway
Namespace: default
Labels: <none>
Annotations: <none>
API Version: networking.istio.io/v1beta1
Kind: Gateway
Metadata:
Creation Timestamp: 2021-06-06T20:47:18Z
Generation: 1
Managed Fields:
API Version: networking.istio.io/v1alpha3
Fields Type: FieldsV1
fieldsV1:
f:Metadata:
f:annotations:
.:
f:kubectl.kubernetes.io/last-applied-configuration:
f:spec:
.:
f:selector:
.:
f:istio:
f:servers:
Manager: kubectl-client-side-apply
Operation: Update
Time: 2021-06-06T20:47:18Z
Resource Version: 2053564
Self Link: /apis/networking.istio.io/v1beta1/namespaces/default/gateways/bookinfo-gateway
UID: aa390a1d-2e34-4599-a1ec-50ad7aa9bdc6
Spec:
Selector:
Istio: ingressgateway
Servers:
Hosts:
*
Port:
Name: http
Number: 80
Protocol: HTTP
Events: <none>
-
istio-ingressgateway 可以在 80 上通过 localhost 暴露给外部(不确定在 istio 安装期间部署时如何配置),据我所知,bookinfo-gateway 将使用它 kubectl get svc istio-ingressgateway -n istio-system
-
遵循 the instruction 中的确定入口 IP 和端口部分。
我的 INGRESS_HOST=127.0.0.1 和 INGRESS_PORT 是 80
- curl -v -s http://127.0.0.1:80/productpage | grep -o ".*"
* Trying 127.0.0.1:80...
* TCP_NODELAY set
* connect to 127.0.0.1 port 80 Failed: Connection refused
* Failed to connect to 127.0.0.1 port 80: Connection refused
* Closing connection 0
-
在浏览器上尝试此 http://127.0.0.1/productpage,返回 404。此 404 是否意味着网关已启动但虚拟服务不起作用??
-
进一步询问是否相关。我有点困惑 wsl2 现在是如何工作的。看起来windows浏览器上的localhost和wsl2终端不是一回事,尽管我知道有一种从windows到wsl2服务器的转发(我可以从/etc/resolv.conf获取它的IP)。如果相同,为什么一个返回连接被拒绝,另一个返回 404
-
在 Windows 上,我尝试禁用 IIS 或在端口 80 上运行的任何内容(net stop http)。不知何故,我仍然可以看到一些监听 80 端口的内容
netstat -aon | findstr :80
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 4
tasklist /svc /FI "PID eq 4"
Image Name PID Services
========================= ======== ============================================
System 4 N/A
我想知道这是否是导致第 7 点差异的原因?由于 Windows 在端口 80 上的另一个 http 服务器上运行?
我知道这个问题问了很多。我相信我们很多刚接触 istio 和 wsl2 的人可能会有类似的问题。希望这对其他人也有帮助。请指教。
解决方法
WSL2 本身似乎有问题,可能与 Local sites running in WSL2 not accessible in browser #5298 有关。
你可以通过发布来解决这个问题
ip addr show
在您的 WSL 发行版中,并将 127.0.0.1
/localhost
替换为 eth0
地址。就我而言,它是 172.21.29.254
- 所以 URL 是 http://172.21.29.254/productpage
这个解决方法对我有用。
,我设法让它发挥作用:这就是我所做的。 Shell 进入发行版(我的是 Ubuntu 20.04 LTS)
运行:
sudo apt-get -y install socat
sudo apt update
sudo apt upgrade
exit
以上将添加 socat(我在查看 istio 日志时遇到错误 - 连接被拒绝)并将发行版更新为最新更新(并升级它们)
现在您必须运行端口转发才能托管本地主机:使用以下命令访问 istio 网关:
kubectl port-forward svc/istio-ingressgateway 8080:80 -n istio-system
如果您已经在使用 8080,只需将其从命令中删除,只需使用 :80,端口转发将选择一个空闲端口。
现在去
http://localhost:8080/productpage
你应该点击页面并且端口转发应该输出
Handling connection for 8080
希望有帮助... 好消息是现在我不必使用 Hyper-V 或其他集群安装程序,如 minikube/microk8s 并使用 docker 桌面中的内置 kubernetes 和......我的笔记本电脑似乎没有负载我正在做的事情