<p>In my current non-Kubernetes environment, if I need to access the Postgres database, I just setup an SSH tunnel with:</p>

<p><code>ssh -L 5432:localhost:5432 user@domain.com</code></p>

<p>I'm trying to figure out how to do something similar in a test Kubernetes cluster I am setting up in EKS, that doesn't involve a great security risk. For example, creating a path in the ingress control to the databases port is a <em>terrible</em> idea.</p>

<p>The cluster would be setup where Postgres is in a pod, but all of the data is on persistent volume claim so that the data persists when the pod is destroyed.</p>

<p>How would one use pgAdmin to access the database in this kind of setup?</p>

cjones
<p>The <code>kubectl</code> command can <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#port-forward" rel="nofollow noreferrer">forward TCP ports</a> into a POD via the kube-api</p>

<pre><code>kubectl port-forward {postgres-pod-ID} 5432:5432
</code></pre>

<p>If you are not using a cluster-admin user, the user will need to be bound to a role that allows it to <code>create</code> <code>pods/portforward</code> in the pods namespace. </p>

<pre><code>kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: pg-portforward
rules:
  - apiGroups: [""]
    resources: ["pods/portforward"]
    verbs: ["create"]
</code></pre>
