16

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.

What I have:

  1. EKS cluster with its own VPC (CIDR: 192.168.0.0/16)
  2. RDS (Postgres) with its own VPC (CIDR: 172.30.0.0/16)
  3. Peering connection initiated from the RDS VPC to the EKS VPC
  4. Route table for 3 public subnets of EKS cluster is updated: route with destination 172.30.0.0/16 and target — peer connection from the step #3 is added.
  5. Route table for the RDS is updated: route with destination 192.168.0.0/16 and target — peer connection from the step #3 is added.
  6. The RDS security group is updated, new inbound rule is added: all traffic from 192.168.0.0/16 is allowed

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

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

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

UPDATE:

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

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

This fix does not work :(

5
  • 1
    Have you tried to enable "dns propagation" in the peering connection? It looks like you are not getting the internally routable dns?
    – donkeyx
    Dec 2, 2018 at 10:33
  • 1
    @donkeyx this is brilliant advice! This helped me :) So feel free to add this comment as a separate answer on this question and I'll upvote it and mark as a correct one! Dec 2, 2018 at 11:04
  • @Alex Fruzenshtein, Have you fixed the issue by launching DNS propagation feature?
    – Nick_Kh
    Dec 3, 2018 at 14:06
  • @mk_sta yep. In my case pods from the k8s cluster were not able to communicate with RDS just because "dns propagation" in the peering connection was not enables Dec 3, 2018 at 21:03
  • Have you added entry to your route table for incoming traffic on postgres port ? Feb 21, 2022 at 9:46

2 Answers 2

13

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.

2
  • 1
    Seems this DNS options are available once the PC is created.
    – bvj
    Apr 3, 2020 at 4:31
  • Thank you so much. I have been struggling for hours. It solved my problem.
    – Azerue
    Jul 21, 2022 at 15:06
0

The answer I provided here may actually apply to your case, too.

It is about using Services without selectors. Look also into ExternalName Services.

2
  • thanks for the hint! I'll check it tomorrow when will get back to the normal internet again! Dec 1, 2018 at 18:28
  • ExternalService doesn't work for me. Looks like I just mapped the original DB address to the Kubernetes Service abstraction :( Dec 2, 2018 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.