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?
Add a comment
|
1 Answer
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
4 Comments
efgdh
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?
Asri Badlah
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.
efgdh
Do I follow the same process to connect to MongoDB hosted in an EC2 instance?
Asri Badlah
Yes, create external service in your cluster to point MongoDB, after you confirming the DNS resolution between the two VPCs