How do I run ysqlsh or psql queries externally?

I started a yugabyte cluster in minikube using the helm chart in - how can I run psql or ysqlsh queries against this cluster from outside? I don’t see the load balancer specified in the page.

Hi @CharlieORiley,

You can use port forwarding I believe. For example, you could do one of the following.

  • Forward the ports for the entire yb-tserver service:

    kubectl port-forward svc/yb-tserver-service 5433:5433
  • Forward the ports from just one pod:

    kubectl port-forward pod/yb-tserver-0 5433:5433

Subsequently, you can run psql or ysqlsh pointing to localhost port 5433 as follows:

ysqlsh -h localhost -p 5433

NOTE #1: Get the exact service name by running the following commands:

kubectl get pods -A
kubectl get svc -A`

NOTE #2: The port 5433 needs to be unused on the machine.

If it is already in use, you could get an error as follows:

❯ kubectl port-forward svc/yb-tservers 5433:5433

Unable to listen on port 5433: 
Listeners failed to create with the following errors: 
  [unable to create listener: 
     Error listen tcp4 
       bind: address already in use unable to create listener: 
     Error listen tcp6 [::1]:5433: bind: address already in use
error: unable to listen on any of the requested ports: [{5433 5433}]

NOTE #3: Use a Kubernetes load balancer in production

In production. you would typically use a kubernetes load balancer as described in our docs.

Hope that helps. cc @sanketh @arnav in case I have something wrong.

I keep getting connection refused when running from pgadmin4. Has anyone encountered this?

@asevans48 This was fixed in thread Cannot seem to connect on minikube at forwarded port.