I have a postgres database hosted on kubernetes and I wanted to access it on the internet. I followed this guide, https://microk8s.io/docs/addon-ingress, and was able to connect to the database using my IP address but I wanted to connect using my subdomain.
Let’s say I own example.io
and I wanted the database to be at postgres.example.io:5432
instead of my ip address at port 5432. For my other apps, I am using an ingress to host application-one.example.io
and application-two.example.io
but according to this, /a/60048509, an Ingress only looks at port 80 and 443 traffic. I have multiple applications and databases that I want to expose to the internet and want to use a subdomain. An ingress works for the APIs and applications but what about the databases?
What is the best way to use both the ingress controller and several subdomains to route traffic to multiple postgres databases instead of using my IP and a different port for each. I would rather have a different subdomain for each database then a different port.
I tried using the following ingress but it did not work as an ingress will not work with psql.
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: postgres-ingress
namespace: mynamespace
ingressClassName: nginx
rules:
- host: postgres-dev.example.io
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: postgres-dev
port:
number: 5432
- host: postgres.example.io
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: postgres-prod
port:
number: 5432
After some research, I found the following posts that talk about why this did not work.
- /a/72401697
- /a/60048509