How to access a database that is only accesible from Kubernetes cluster locally?

2/3/2021

I have a situation where I have a Kubernetes cluster that has access to a Postgres instance (which is not run in the Kubernetes cluster). The Postgres instance is not accessible from anywhere else.

What I would like to do is connect with my Database tools locally. What I have found is kubectl port-forward but I think this would only be a solution if the Postgres instance is run as a pod. What I basically need is a Pod, that forwards everything that is sent on Port 8432 to the postgres instance and then I could use the port forward.

https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/

What is the right way to do this?

-- nino
kubernetes
postgresql

2 Answers

2/3/2021

you can use the Postgres client to connect with the Postgres instance and expose that pod using the ingress and you can access the UI over the URL.

for Postgres client, you can use: https://hub.docker.com/r/dpage/pgadmin4/

you can set this as pgclient and use it

-- Harsh Manvar
Source: StackOverflow

2/3/2021

You can create service for your postgresql instance:

---
apiVersion: v1
kind: Service
metadata:
  name: postgresql
spec:
  ports:
    - port: 5432

---
apiVersion: v1
kind: Endpoints
metadata:
  name: postgresql
subsets:
  - addresses:
      - ip: ipAddressOfYourPGInstance
    ports:
      - port: 5432

And then use: kubectl port-forward service/postgresql 5432:5432

-- ITChap
Source: StackOverflow