Kubernetes:无法从 EKS pod 访问 RDS Postgres [英] Kubernetes: Have no access from EKS pod to RDS Postgres

查看:33
本文介绍了Kubernetes:无法从 EKS pod 访问 RDS Postgres的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 AWS 上设置 kubernetes.为此,我根据 AWS 官方教程创建了一个具有 3 个节点 (t2.small) 的 EKS 集群.然后我想用一些与 Postgres(不同 VPC 中的 RDS)通信的应用程序运行一个 pod.

I'm trying to setup kubernetes on AWS. For this I created an EKS cluster with 3 nodes (t2.small) according to official AWS tutorial. Then I want to run a pod with some app which communicates with Postgres (RDS in different VPC).

但不幸的是,该应用无法连接到数据库.

But unfortunately the app doesn't connect to the database.

我有什么:

  1. 具有自己的 VPC 的 EKS 集群(CIDR:192.168.0.0/16)
  2. 具有自己 VPC 的 RDS (Postgres) (CIDR: 172.30.0.0/16)
  3. 从 RDS VPC 发起到 EKS VPC 的对等连接
  4. 更新了 EKS 集群的 3 个公共子网的路由表:目的地为 172.30.0.0/16 的路由和目标 - 添加了第 3 步中的对等连接.
  5. RDS 的路由表已更新:目的地为 192.168.0.0/16 的路由和目标 - 添加了第 3 步中的对等连接.
  6. 更新了 RDS 安全组,添加了新的入站规则:允许来自 192.168.0.0/16 的所有流量

完成所有这些步骤后,我执行 kubectl 命令:

After all these steps I execute kubectl command:

kubectl exec -it my-pod-app-6vkgm nslookup rds-vpc.unique_id.us-east-1.rds.amazonaws.com
nslookup: can't resolve '(null)': Name does not resolve

Name:      rds-vpc.unique_id.us-east-1.rds.amazonaws.com
Address 1: 52.0.109.113 ec2-52-0-109-113.compute-1.amazonaws.com

然后我连接到 3 个节点之一并执行命令:

Then I connect to one of the 3 nodes and execute a command:

getent hosts rds-vpc.unique_id.us-east-1.rds.amazonaws.com
52.0.109.113    ec2-52-0-109-113.compute-1.amazonaws.com rds-vpc.unique_id.us-east-1.rds.amazonaws.com

为了从 Pod 访问 RDS,我在 EKS 设置中遗漏了什么?

What I missed in EKS setup in order to have access from pods to RDS?

更新:

我尝试通过 Service 解决问题:

I tried to fix the problem by Service:

apiVersion: v1
kind: Service
metadata:
  name: postgres-service
spec:
  type: ExternalName
  externalName: rds-vpc.unique_id.us-east-1.rds.amazonaws.com

所以我在 EKS 中创建了这个服务,然后尝试将 postgres-service 引用为 DB URL 而不是直接的 RDS 主机地址.

So I created this service in EKS, and then tried to refer to postgres-service as DB URL instead of direct RDS host address.

此修复不起作用:(

推荐答案

您是否尝试过在对等连接中启用dns 传播"?看起来您没有获得内部可路由的 dns.您可以通过进入对等连接的设置并选中 dns 传播框来启用它.我通常会在我控制的所有对等连接中执行此操作.

Have you tried to enable "dns propagation" in the peering connection? It looks like you are not getting the internally routable dns. You can enable it by going into the setting for the peering connection and checking the box for dns propagation. I generally do this will all of the peering connections that I control.

这篇关于Kubernetes:无法从 EKS pod 访问 RDS Postgres的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆