【问题标题】:Unable to connect Redis Instance from GKE pod - Connection to Redis <IP:6379 >failed after 2 failures.Last Error : (110) Operation timed out无法从 GKE pod 连接 Redis 实例 - 连接到 Redis <IP:6379 > 在 2 次失败后失败。最后一个错误:(110) 操作超时
【发布时间】:2021-04-07 15:06:28
【问题描述】:

我有使用以下命令创建的 GKE 集群:

$ gcloud container clusters create stage1 \
  --enable-ip-alias \
  --release-channel stable \
  --zone us-central1 \
  --node-locations us-central1-a,us-central1-b

我还使用以下命令创建了一个 redis 实例:

$ gcloud redis instances create redisbox --size=2 --region=us-central1 --redis-version=redis_5_0

我已检索到 redis 实例的 IP 地址:

$ gcloud redis instances describe redisbox --region=us-central1

我已经在我的 PHP 应用程序中更新了这个 IP,构建了我的 docker 镜像,在 GKE 集群中创建了 pod。创建 pod 时,容器会抛出以下错误

与 Redis 的连接:6379 在 2 次失败后失败。最后一个错误:(110) 操作超时

注意 1:这是在托管环境中工作的应用程序,我们正在迁移到 Google Cloud
注 2:GKE 和 Redis 实例在同一区域
注 3:在集群中启用 IP 别名

【问题讨论】:

  • 可能是端口访问/白名单问题
  • 你有防火墙规则吗?您使用相同的 VPC 吗? GKE 网络政策已启用?
  • 除了本文中提到的以外,我没有进行任何其他配置。我没有创建防火墙规则,也没有启用 GKE 策略。我所做的是通过提供选项 --enable-ip-alias 创建 VPC-native 集群

标签: google-cloud-platform redis google-kubernetes-engine kubernetes-pod


【解决方案1】:

在使用您的 gcloud 命令复制此 VPC 原生 GKE 集群和 Redis 实例后,我可以检查节点及其 pod 是否可以访问 redisbox 主机,例如使用 ncat在 debian:latest 吊舱中:

$ REDIS_IP=$(gcloud redis instances describe redisbox --format='get(host)' --region=us-central1)
$ gcloud container clusters get-credentials stage1 --region=us-central1
$ kubectl exec -ti my-debian-pod -- /bin/bash -c "ncat $REDIS_IP 6379 <<<PING"
    +PONG

因此,我建议您尝试执行此较低级别的可达性测试,以防您的 PHP 应用程序正在执行的特定请求出现问题。

【讨论】:

  • 我已经通过直接从谷歌控制台创建 VPC 原生集群和 redis 实例解决了这个问题(无需命令)。我已经获取了用于创建 VPC 原生集群的命令,但没有获取用于创建 redis 的命令的选项。我将无法使用这种方法,因为我计划自动化这个过程
猜你喜欢
  • 1970-01-01
  • 2017-07-06
  • 2017-05-16
  • 2020-08-27
  • 2016-12-01
  • 1970-01-01
  • 2020-07-20
  • 2023-03-18
  • 2014-11-07
相关资源
最近更新 更多