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?

macintoshPrime
  • 244
  • 4
  • 12
  • Are you using EKS? – the4thv Mar 10 '18 at 17:50
  • Is there any chance your manage.py file is reading the wrong settings file? Asking because I saw [this SO thread](https://stackoverflow.com/questions/41573313/docker-compose-with-django-could-not-translate-host-name-db-to-address-name-o) that feels possibly related to your issue, despite being about Docker. – ingernet Mar 10 '18 at 17:52
  • No rolling my own with kubeadm, 1 master 1 node. Attempting to learn the hard-ish way. – macintoshPrime Mar 10 '18 at 17:53
  • Is your AWS deployment in the same VPC as your RDS now? – the4thv Mar 10 '18 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. – macintoshPrime Mar 10 '18 at 18:08
  • @the4thv ya they clusters are in the same VPC as the RDS – macintoshPrime Mar 10 '18 at 18:09
  • Never thought to check that. I can psql into the RDS service with no issue. Hmm might be a django issue... – macintoshPrime Mar 10 '18 at 18:33
  • I would still guess it's more Kubernetes, as it has it's own DNS service. – the4thv Mar 10 '18 at 18:49

1 Answers1

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.

the4thv
  • 581
  • 2
  • 13