Question

Kubernetes pods not able to connect to the hosted postgres instance

I was following the Django kubernetes series (How To Deploy a Scalable and Secure Django Application with Kubernetes | DigitalOcean

But I ran into a problem where the Django app that works fine in Docker can’t no connect to the digital ocean postgres after being deployed into Kubernetes. I then did some further exploration and launched postgresql-client pod, and I can’t seem to connect from it either, even though name lookup and so on seem to work. When trying to run this

psql -p 25060 -U sammy -d polls -h databasenamestring-0.b.db.ondigitalocean.com

from inside a pod it hangs, while the same command works from both a linuxvm droplet and also from my home comp. Also the name lookup for the database does work, nor does it work if I give the host ip address directly.

And of course most critically, the Django app can’t connect the database but hangs whenever it tries to access the DB in the back.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
March 2, 2023
Accepted Answer

Hi there,

Adding the Kubernetes external IP would also work, but what you need to do is, in the section titled Trusted Sources, click Edit to open the Add trusted sources text box, you can enter Droplets, Kubernetes clusters, tags, apps, or specific IP addresses. Entering a tag provides access to the database for any Droplets or Kubernetes nodes containing that tag. At this time, DigitalOcean Cloud Firewalls are not supported.

Best,

Bobby

Found the solution: I just had to go to my database settings and add the Kubernetes external ip to the list of trusted ips

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.