【问题标题】:Not able to access a Istio enabled GKE service directly from browser but only through curl无法直接从浏览器访问启用 Istio 的 GKE 服务,只能通过 curl
【发布时间】:2020-01-25 11:55:45
【问题描述】:

我在云运行选项上部署了一个节点应用程序(启用了 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  

我可以通过以下方式访问 nodeservice1 curl -v -H“主机:nodeservice1.istio-system.example.com”34.80.18.249 但是如果我从浏览器中点击“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

【问题讨论】:

  • 1) 您正在使用两个不同的端口号(80 和 8080)。 2) HTTP 1.1 需要主机头。您的第二个请求不包含主机标头(或包含 IP 地址作为主机),因此前端不知道将请求路由到哪里。
  • 当然。我已经更新了这个问题。请检查。

标签: google-cloud-platform google-kubernetes-engine istio google-anthos


【解决方案1】:

显然,您不拥有example.com

因此,您不能指望通过浏览器访问 http://nodeservice1.istio-system.example.com,因为您没有为域配置 DNS。

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

假设您使用 Knative/Cloud Run,您应该将 example.com 中的 updating the default domain on Cloud Run on GKE 视为您拥有的东西,以便您可以为您的子域设置 DNS 记录。

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

【讨论】:

  • 正确。这意味着 IP '34.80.18.249:8080' 应该在浏览器中工作吗?它也没有用。
  • 不,请仔细阅读我的回答。如果没有 Host 在您键入域名时浏览器通常提供的标头,Istio 无法将您的流量路由到服务。当你直接在浏览器中输入 IP 时,它不会有 Host 标头。
猜你喜欢
  • 1970-01-01
  • 2020-04-09
  • 2021-05-23
  • 1970-01-01
  • 1970-01-01
  • 2013-02-14
  • 2012-06-01
  • 2021-10-12
  • 2017-12-01
相关资源
最近更新 更多