简体   繁体   English

GCP 内部负载平衡器

[英]GCP internal load balancer

I'm trying access elasticsearch cluster on GKE from my project in GAE - flexible.我正在尝试从我在 GAE 中的项目访问 GKE 上的 elasticsearch 集群 - 灵活。 Since I don't want an external load-balancer, I'm following this guide: https://cloud.google.com/kubernetes-engine/docs/how-to/internal-load-balancing Both GKE and GAE are deployed in the same region, but the calls to the elasticsearch cluster timeout all the time.由于我不想要外部负载平衡器,我正在遵循本指南: https ://cloud.google.com/kubernetes-engine/docs/how-to/internal-load-balancing GKE 和 GAE 均已部署在同一地区,但对elasticsearch集群的调用一直超时。 Has anyone done this and can share some tips would be much appreciated!有没有人做过这个并且可以分享一些技巧将不胜感激!

My service.yaml file looks like this:我的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

GCP now has a beta Global Access feature with Internal Load balancers which will allow the internal load balancers to be accessible from any region within the same network. GCP 现在具有带有内部负载平衡器的 Beta 全局访问功能,这将允许从同一网络中的任何区域访问内部负载平衡器。

This will be helpful for your case too.这对您的情况也有帮助。 If two services are exposed using internal IP addresses but located in different regions.如果两个服务使用内部 IP 地址公开但位于不同的区域。

UPDATE更新

Global Access feature is now stable (for GKE 1.16.x and above) and it can be enabled by adding the below annotation to your service.全局访问功能现已稳定(适用于GKE 1.16.x及更高版本),可以通过将以下注释添加到您的服务来启用它。

networking.gke.io/internal-load-balancer-allow-global-access: "true"

For Example : The below manifest will create your internalloadbalancerservice LoadBalancer with internal IP address and that IP will be accessible from any region within the same VPC.例如:以下清单将使用内部 IP 地址创建您的internalloadbalancerservice LoadBalancer,并且可以从同一 VPC 内的任何区域访问该 IP。

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

This works well for GKE 1.16.x and above.这适用于GKE 1.16.x及更高版本。 For older GKE versions, you can refer to this answer .对于较旧的 GKE 版本,您可以参考这个答案

To save anyone else from a similar situation, I will share my findings of why I couldn't connect to my GKE app from GAE.为了让其他人免于类似的情况,我将分享我的发现,为什么我无法从 GAE 连接到我的 GKE 应用程序。 The GAE was in region europe-west, while GKE was in region europe-west-4a. GAE 位于欧洲西部区域,而 GKE 位于欧洲西部 4a 区域。 I thought that would be the same region.我认为那将是同一个地区。 But changing GKE region to europe-west-1b worked.但是将 GKE 区域更改为 europe-west-1b 有效。 Not very obvious but when reading the documentation GAE region europe-west and GKE region europe-west-1b are both in Belgium.不是很明显,但在阅读文档时,GAE region europe-west 和 GKE region europe-west-1b 都在比利时。

Assuming that the GAE app and the GKE cluster are in the same region, and in the same VPC network, I would suggest to make sure you have created Ingress allow firewall rules that apply to the GKE nodes as targets with the GAE app VMs as sources.假设 GAE 应用程序和 GKE 集群在同一个区域,并且在同一个 VPC 网络中,我建议确保您已经创建了Ingress 允许防火墙规则,这些规则适用于 GKE 节点作为目标,GAE 应用程序虚拟机作为源.

Remember Ingress to VMs is denied by the implied deny Ingress rule.请记住,虚拟机的入口被隐含的拒绝入口规则拒绝。 So unless you create Ingress allow firewall rules, you'll not be able to send packets to any VMs.因此,除非您创建 Ingress 允许防火墙规则,否则您将无法向任何 VM 发送数据包。 And to use an Internal Load Balancing (ILB) , both the client and the backend VMs must be in the same:并且要使用内部负载平衡 (ILB) ,客户端和后端 VM 必须在同一个中:
- Region - 地区
- VPC network - VPC 网络
- Project - 项目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM