1

I want to deploy my full stack application using AWS EKS, with the backend pod connected to the databases(MongoDB hosted in an EC2 instance and a RDS Postgres) outside of the cluster. If the EKS cluster and the databases are in different VPC, how should I configure the pod to connect to the databases after the VPC peer connection, do I just have to specify the external DNS name of the databases in the pod's deployment yaml?

1 Answer 1

1

You need to create a kubernetes Service named for example rds-postgres-service of type ExternalName aliasing the RDS endpoint your_RDS_endpoint_URL.

Run kubectl apply -f rds_postgres_service.yaml to create the service. in your rds_postgres_service.yaml your code should be like this example:

apiVersion: v1
kind: Service
metadata:
  labels:
    app: rds-postgres-service
  name: rds-postgres-service
spec:
  externalName: your_RDS_endpoint_URL
  selector:
    app: rds-postgres-service
  type: ExternalName
status:
  loadBalancer: {}

# Replace your_RDS_endpoint_URL with your RDS endpoint

Now, clients running inside the pods within the cluster can connect to the RDS instance using: rds-postgres-service

Sign up to request clarification or add additional context in comments.

4 Comments

Hey Asri thanks for the solution! In the pod's deployment yaml, do I just specify the external DNS name of the databases as rds-postgres-service.<namespace>.svc.cluster.local? Or should I use the RDS_endpoint_URL? Also, how should I include the secret(credentials to the RDS instance)to the rds_postgres_service.yaml?
Enable "dns propagation" in the peering connection, and use the rds enpoint url. For PostgreSQL credentials you can use config maps for storing PostgreSQL related Configureation.
Do I follow the same process to connect to MongoDB hosted in an EC2 instance?
Yes, create external service in your cluster to point MongoDB, after you confirming the DNS resolution between the two VPCs

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.