How can I connect a Kubernetes Cluster to a Postgres DB

Linode Staff

I have a node that I have created a postgres DB on.
I was also interested in using the managed Kubernetes.
So I understand that I need to allow Postgres to accept connections from the Kubernetes cluster.
Do you have any steps or config that could help with this ?
Is there a subnet that I can allow connections from (in Postgres) so that Kubernetes can connect but no external connections can ? (no connections outside LINode) ?

2 Replies

Hey there!

Since you have a few questions, I'll go through them each individually.

I have a node that I have created a postgres DB on.
I was also interested in using the managed Kubernetes.
So I understand that I need to allow Postgres to accept connections from the Kubernetes cluster.
Do you have any steps or config that could help with this ?

It looks like all you'll need to do is update postgres.conf and pg_hba.conf, restart your DB, and make sure that your firewall allows access on port 5432. You can see all the steps in this guide to setting up your Postgres Server. I'd also recommend checking out this Kubernetes guide on accessing external services.

Is there a subnet that I can allow connections from (in Postgres) so that Kubernetes can connect but no external connections can ? (no connections outside LINode) ?

I'm not 100% sure if it's possible to connect to a Kubernetes cluster over our private IP space, so I'm going to reach out to our Kubernetes team to see if they help answer this one. I'll be sure to follow up as soon as I hear back from them.

One thing that I'd recommend, especially if you're thinking about using Linode Kubernetes Engine, would be to check out something like KubeDB. This will let you not only ensure your Postgres instance is communicating securely with your application since it is inside the Kubernetes Cluster, it will also let you take advantage of the high availability that Kubernetes offers.

I hope this helps. As soon as I hear back from our Dev team on the private IP connection, I'll be sure to reach back out!

Ryan L.
Linode Support Staff

Hey there,

It looks like it is possible to connect an external DB to a Kubernetes cluster running on LKE. This requires some additional configuration on your end. This guide on connecting Kubernetes to external services may be able to help!

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct