1

我在云运行选项上部署了一个节点应用程序(启用了 Istio 的 GKE 集群)。我检查了使用“kubectl get services -n istio-system”运行的服务,它显示

NAME                         TYPE           CLUSTER-IP    EXTERNAL-IP     PORT(S) 
istio-ingressgateway         LoadBalancer   10.4.15.63    34.80.18.249    15020:30228/TCP,80:31380/TCP,443:31390/TCP
nodeservice1                 ExternalName   <none>        istio-ingressgateway.istio-system.svc.cluster.local                              
nodeservice1-qdvk6           ClusterIP      10.4.12.102   <none>      80/TCP                                                    
nodeservice1-qdvk6-metrics   ClusterIP      10.4.8.162    <none>  9090/TCP                                                           
nodeservice1-qdvk6-priv      ClusterIP      10.4.14.49    <none>   80/TCP  

我可以通过 curl -v -H "Host: nodeservice1.istio-system.example.com" 34.80.18.249 访问 nodeservice1 但如果我从浏览器中点击“ http://34.80.18.249:8080 ”,它就不起作用。

如果我不选择云运行平台并设置一个普通的 kubernete 集群,那么我可以选择公开 nodeservice1 以公开为 LoadBalancer 类型并且可以从浏览器访问。

curl 命令的输出:curl -v -H "Host: nodeservice1.istio-system.example.com" 34.80.18.249/restcall

*   Trying 34.80.18.249:80...
* TCP_NODELAY set
* Connected to 34.80.18.249 (34.80.18.249) port 80 (#0)
> GET //restcall HTTP/1.1
> Host: nodeservice1.istio-system.example.com
> User-Agent: curl/7.65.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
< content-security-policy: default-src 'none'
< content-type: text/html; charset=utf-8
< date: Wed, 25 Sep 2019 09:24:15 GMT
< x-content-type-options: nosniff
< x-powered-by: Express
< x-envoy-upstream-service-time: 5349
< server: istio-envoy
< Accept-Ranges: none
< Content-Length: 148
< Via: HTTP/1.1 forward.http.proxy:3128
< Connection: keep-alive
<
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET //restcall</pre>
</body>
</html>
* Connection #0 to host 34.80.18.249 left intact
4

1 回答 1

2

显然,您不拥有example.com.

所以你不能指望从你的浏览器访问http://nodeservice1.istio-system.example.com工作,因为你没有为域配置 DNS。

当你这样做时curl -H "Host: foo" http://ip,它不需要通过DNS(因为你ip直接给出地址)。Istio 入口网关随后使用您提供的Host标头(通常由浏览器提供,从 URL 推断)将流量路由到正确的服务。

假设您使用 Knative/Cloud Run,您应该考虑将 GKE 上 Cloud Run 上的默认域从 example.com 更新为您拥有的域名,以便您可以为子域设置 DNS 记录。

或者,您可以将本地 DNS 记录添加到/etc/hosts文件中,将该主机名指向您的 istio-ingressgateway 的外部 IP 地址,并且您的浏览器将使用本地 hack 将该主机名解析为该 IP。

于 2019-09-26T07:22:01.383 回答