【问题标题】:GCP destination group instances not being checked未检查 GCP 目标组实例
【发布时间】:2017-07-18 13:30:49
【问题描述】:

我正在尝试在 GCP 上创建一个 TCP/UDP 负载平衡器以允许我的服务具有 HA,但我注意到,当我创建一个目标组时,该组中的所有实例都被标记为不正常并且没有被由谷歌检查(我已经看过机器日志来检查它)。防火墙是开放的,因为是为了测试目的,所以我确定这不是问题。

我使用具有类似检查配置的后端创建了一个 HTTP/S 负载平衡器,并且同一台机器被标记为健康,所以这台机器不是问题(即使现在日志显示谷歌是如何真正检查该实例)。

这两项检查都是 HTTP 到端口 80,所以我看不出问题出在哪里以及这两种负载平衡器检查器之间的区别。

我还检查了是否禁用运行状况检查,但该实例仍被标记为不健康,并且没有将流量发送到任何实例,因此负载均衡器并非完全有用。

是否需要任何其他配置才能使其检查实例?

谢谢和问候!!

【问题讨论】:

  • 您使用了哪种类型的 TCP/UDP 负载均衡器 TCP LBTCP Proxy LBSSL Proxy LBUDP LB
  • 在基本模式下只有第二个和第三个选项(TCP负载均衡器和UDP负载均衡器)。高级模式是转发规则(例如,这是创建 UDP 平衡器的唯一方法)。问题是谷歌不检查实例,然后永远不会是健康的。使用后端检查实例并看起来很健康,但只允许 HTTP/S、TCP 和 SSL,因此对于 UDP 端口没有用...

标签: google-cloud-platform load-balancing


【解决方案1】:

创建 TCP 负载平衡器

当您使用任何 Google Cloud 负载平衡器时,您无需将 VM 的外部端口暴露给互联网,只需您的负载平衡器能够访问它。

steps to create a TCP load balancer are described here。我发现使用gcloud 并运行命令很方便,但您也可以使用 Cloud Console UI 来实现相同的结果。

我尝试了以下步骤,它对我有用(您可以轻松修改它以使其也适用于 UDP - 请记住,即使使用 UDP 负载平衡,您仍然需要 HTTP 运行状况检查):

# Create 2 new instances
gcloud compute instances create vm1 --zone us-central1-f
gcloud compute instances create vm2 --zone us-central1-f

# Make sure you have some service running on port 80 on these VMs after creation.

# Create an address resource to act as the frontend VIP.
gcloud compute addresses create net-lb-ip-1 --region us-central1

# Create a HTTP health check (by default uses port 80).
$ gcloud compute http-health-checks create hc-1

# Create a target pool associated with the health check you just created.
gcloud compute target-pools create tp-1 --region us-central1 --http-health-check hc-1

# Add the instances to the target pool
gcloud compute target-pools add-instances tp-1 --instances vm1,vm2 --instances-zone us-central1-f

# Create a forwarding rule associated with the frontend VIP address we created earlier
# which will forward the traffic to the target pool.
$ gcloud compute forwarding-rules create fr-1 --region us-central1 --ports 80 --address net-lb-ip-1 --target-pool tp-1

# Describe the forwarding rule
gcloud compute forwarding-rules describe fr-1 --region us-central1

IPAddress: 1.2.3.4
IPProtocol: TCP
creationTimestamp: '2017-07-19T10:11:12.345-07:00'
description: ''
id: '1234567890'
kind: compute#forwardingRule
loadBalancingScheme: EXTERNAL
name: fr-1
portRange: 80-80
region: https://www.googleapis.com/compute/v1/projects/PROJECT_NAME/regions/us-central1
selfLink: https://www.googleapis.com/compute/v1/projects/PROJECT_NAME/regions/us-central1/forwardingRules/fr-1
target: https://www.googleapis.com/compute/v1/projects/PROJECT_NAME/regions/us-central1/targetPools/tp-1

# Check the health status of the target pool and verify that the
# target pool considers the backend instances to be healthy
$ gcloud compute target-pools get-health tp-1
---
healthStatus:
- healthState: HEALTHY
  instance: https://www.googleapis.com/compute/v1/projects/PROJECT_NAME/zones/us-central1-f/instances/vm1
  ipAddress: 1.2.3.4
kind: compute#targetPoolInstanceHealth
---
healthStatus:
- healthState: HEALTHY
  instance: https://www.googleapis.com/compute/v1/projects/PROJECT_NAME/zones/us-central1-f/instances/vm2
  ipAddress: 1.2.3.4
kind: compute#targetPoolInstanceHealth

非代理 TCP/UDP 负载平衡器需要 HTTP 健康检查

如果您使用的是 UDP 负载平衡器(在 Google CLoud 中被视为网络负载平衡),则除了正在侦听的服务之外,您还需要启动一个可以响应 HTTP 运行状况检查的基本 HTTP 服务器用于传入流量的 UDP 端口。

这同样适用于非基于代理的 TCP 负载平衡器(在 Google Cloud 中也被视为网络负载平衡)。

这是documented here

Health checking

运行状况检查确保 Compute Engine 仅转发新连接 到已启动并准备好接收它们的实例。计算引擎 在指定的时间向每个实例发送健康检查请求 频率;一旦实例超过其允许的健康检查次数 失败,它不再被视为符合条件的实例 接收新流量。现有的连接不会被激活 终止,允许实例正常关闭并关闭 TCP 连接。

健康检查继续查询不健康的实例,并返回 成功检查指定次数后将实例添加到池中 满足。

网络负载平衡依赖于legacy HTTP Health checks 确定实例运行状况。即使你的服务不使用 HTTP, 您至少需要在每个实例上运行一个基本的 Web 服务器 健康检查系统可以查询。

【讨论】:

  • 我将尝试使用命令而不是 Web 界面,但很奇怪,因为实例工作正常(当然也在监听端口 80),正如我所说,来自 google 的其他健康检查确实在检查那台机器说没关系。
  • @DanielCarrascoMarín - 假设您配置的健康检查 URL 是 http://host:80,您可以从同一 VM 和不同 VM 运行 curl http://VM1_IP:80 吗?另请查看gcloud compute target-pools get-health 命令的输出,了解负载均衡器的运行状况检查器的想法。
  • 谢谢!!,我试试。无论如何,其他健康检查检测到它是健康的,并且机器正在提供可通过外部 IP 访问的网页,所以我确定 nginx 服务器正在工作。
猜你喜欢
  • 2021-08-14
  • 2018-09-21
  • 1970-01-01
  • 1970-01-01
  • 2019-11-27
  • 2020-04-04
  • 1970-01-01
  • 2022-12-22
  • 2022-07-26
相关资源
最近更新 更多