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

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

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

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel