1

I'm having some trouble with my AWS Kubernetes instance.

I'm trying to get my django instances to connect to the RDS service via the DB endpoint.

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': os.environ['NAME'],
        'USER': os.environ['USER'],
        'PASSWORD': os.environ['PASSWORD'],
        'HOST': os.environ['HOST'],
        'PORT': os.environ['PORT']
    }
}

The host string would resemble this service.key.region.rds.amazonaws.com and is being passed to the container via env in the deploy.yml

containers:
  - name: service
    env:
      - name: HOST
        value: service.key.region.rds.amazonaws.com

This set up works locally in kubernetes but not when I put it in the cluster I have on AWS. It returns the following error instead:

django.db.utils.OperationalError: could not translate host name

Any suggestions or am I missing something in how AWS likes handling things?

8
  • Are you using EKS? Commented Mar 10, 2018 at 17:50
  • Is there any chance your manage.py file is reading the wrong settings file? Asking because I saw this SO thread that feels possibly related to your issue, despite being about Docker. Commented Mar 10, 2018 at 17:52
  • No rolling my own with kubeadm, 1 master 1 node. Attempting to learn the hard-ish way. Commented Mar 10, 2018 at 17:53
  • Is your AWS deployment in the same VPC as your RDS now? Commented Mar 10, 2018 at 18:02
  • @ingernet I just double checked my settings files and by base.py doesn't hold any DB configs. I changed some things and rebuilt the image just to be sure and I still get the same error. Good thought though, thanks for the suggestions. Commented Mar 10, 2018 at 18:08

1 Answer 1

4

Assuming your AWS deployment is now in the same VPC as your RDS, then you will need to change your host to use the private IP.

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

5 Comments

Pardon my ignorance but where do I find the private ip of the RDS, the closest I can find in the RDS dashboard is the endpoint.
OK, before I decide this is absolutely wrong, try pinging the RDS end point to get the private IP address. Then use that in your deployment.
Awesome! I think that it's related to Kubernetes internal routing: kubernetes.io/docs/concepts/services-networking/dns-pod-service
Thanks for the help and the link. Much appreciated
what if you're in a different VPC, different account, different region?

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.