<p>I installed a Postgresql database with Kubernetes into one of my pod. The communication works fine beetwen application in the other pods and my database and I can access it with those commands:</p>
<pre><code>kubectl exec -it name_of_my_pod -n name_of_my_namespace -- &quot;/bin/bash&quot;
psql
</code></pre>
<p>I would like now to access the database with IntelliJ, pgAdmin or something like that. How can I do this?</p>
<p><em>Secondary question: Is it really recommended to do it this way (postgres into a pod)? Or is better to have the database out of Kubernetes</em>?</p>

Antoine Grenard
<p>To access the database, you can expose the pgadmin tool via a Load-Balancer or Ingress controller. This is not always ideal from a security standpoint- as you are trusting the pgadmin tool to properly handle security. Another way to do this is to expose the pgadmin tool via cluster IP - or an internal IP address. This means, that those people outside of your clusters network, cannot access it. Then for you to access the tool, you would have to add a ssh/vpn tunnel or use kubernetes <a href="https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/" rel="nofollow noreferrer">port-forwarding</a> tool.</p>
<p>For deployment, <a href="https://hub.kubeapps.com/charts/cetic/pgadmin" rel="nofollow noreferrer">this</a> helm chart seems to be fairly reasonable, and you can control how you expose the admin utility.</p>
<p>Personally, if security is not of the upmost importance, I would expose pgadmin via an ingress controller. This would be the most convenient way to access the tool.</p>
<p>As for your second question, you can run postgress inside of a pod - but you need to make sure you have a persistent volume setup as the datastore location - as pods should be considered ephemeral. If you are struggling with how to start, I usually find Bitnami's offerings (free) a really good place to begin. <a href="https://github.com/bitnami/charts/tree/master/bitnami/postgresql/#installing-the-chart" rel="nofollow noreferrer">Here</a> is the link to the helm chart for postgress SQL. With Bitnami's charts, make sure to set the passwords and accounts during the deployment process- otherwise the deployment will work the first time, but not if you have to redeploy - as the randomly generated passwords will change.</p>
<p>As a note, with some helm charts I use the <code>--dry-run</code> flag to get the raw yaml which I use to do a more standard kubernetes deployment. Make sure to set your helm options properly, and then add that flag.  This can be easier if you are just starting and are trying to customize something that does not have a built-in argument.</p>
