【问题标题】:GCP internal load balancerGCP 内部负载平衡器
【发布时间】:2019-02-04 09:16:29
【问题描述】:
我正在尝试从我在 GAE 中的项目访问 GKE 上的弹性搜索集群 - 灵活。由于我不想要外部负载平衡器,因此我正在遵循本指南:
https://cloud.google.com/kubernetes-engine/docs/how-to/internal-load-balancing
GKE和GAE都部署在同一个地域,但是对elasticsearch集群的调用一直超时。有没有人这样做并且可以分享一些提示将不胜感激!
我的service.yaml 文件如下所示:
apiVersion: v1
kind: Service
metadata:
name: internalloadbalancerservice
annotations:
cloud.google.com/load-balancer-type: "Internal"
labels:
app.kubernetes.io/component: elasticsearch-server
app.kubernetes.io/name: elasticsearch #label selector service
spec:
type: LoadBalancer
loadBalancerSourceRanges: # restrict access
- xxxxxxxx
ports:
- name: myport
port: 9000
protocol: TCP # default; can also specify UDP
selector:
app.kubernetes.io/name : elasticsearch # label selector for Pods
app.kubernetes.io/component: elasticsearch-server
【问题讨论】:
标签:
google-app-engine
elasticsearch
google-kubernetes-engine
internal-load-balancer
【解决方案1】:
GCP 现在有一个带有内部负载平衡器的测试版Global Access 功能,允许从同一网络中的任何区域访问内部负载平衡器。
这对您的情况也有帮助。如果两个服务使用内部 IP 地址公开,但位于不同的区域。
更新
全局访问功能现已稳定(GKE 1.16.x 及更高版本),可以通过将以下注释添加到您的服务来启用它。
networking.gke.io/internal-load-balancer-allow-global-access: "true"
例如:以下清单将使用内部 IP 地址创建您的 internalloadbalancerservice LoadBalancer,并且该 IP 可从同一 VPC 内的任何区域访问。 p>
apiVersion: v1
kind: Service
metadata:
name: internalloadbalancerservice
annotations:
cloud.google.com/load-balancer-type: "Internal"
# Required to enable global access
networking.gke.io/internal-load-balancer-allow-global-access: "true"
labels:
app.kubernetes.io/component: elasticsearch-server
app.kubernetes.io/name: elasticsearch #label selector service
spec:
type: LoadBalancer
loadBalancerSourceRanges: # restrict access
- xxxxxxxx
ports:
- name: myport
port: 9000
protocol: TCP # default; can also specify UDP
selector:
app.kubernetes.io/name : elasticsearch # label selector for Pods
app.kubernetes.io/component: elasticsearch-server
这适用于 GKE 1.16.x 及更高版本。旧版 GKE 可以参考this answer。
【解决方案2】:
为了避免其他人遇到类似情况,我将分享我的发现,说明为什么我无法从 GAE 连接到我的 GKE 应用。 GAE 位于欧洲西部地区,而 GKE 位于欧洲西部 4a 地区。我以为那会是同一个地区。但是将 GKE 区域更改为 europe-west-1b 有效。不是很明显,但在阅读文档时,GAE region europe-west 和 GKE region europe-west-1b 都在比利时。