psycopg2 connect to postgres using custom websocket

2/16/2022

I have a postgres cluster deployed in kubernetes and I am doing port-forwarding so that I can access the pod from outside the kubernetes cluster

from kubernetes.stream import portforward

pf = portforward(
  self.core_v_api.connect_get_namespaced_pod_portforward,
  name, namespace,
  ports=str(ports),
)
return pf

This returns me a websocket:

<websocket._core.WebSocket object at 0x7ff628132c50>

I have to use this WebSocket to connect with the Postgres, is there a way I can use psycopg2 with a custom WebSocket or any other way?

-- Vishrant
kubernetes
postgresql
psycopg2
websocket

0 Answers