<p>I just deployed a docker with Postgres on it on AWS EKS. </p>

<p>Below is the description<a href="https://i.stack.imgur.com/O7HxL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O7HxL.png" alt="enter image description here"></a> details.</p>

<p>How do i access or test if postgres is working. I tried accessing both IP with post within VPC from worker node. </p>

<pre><code> psql -h #IP -U #defaultuser -p 55432
</code></pre>

<p>Below is the deployment. </p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: postgres
spec:
  replicas: 1
  template:
    metadata:
      labels:
    app: postgres
spec:
  containers:
    - name: postgres
      image: postgres:10.4
      imagePullPolicy: "IfNotPresent"
      ports:
        - containerPort: 55432
      # envFrom:
      #   - configMapRef:
      #       name: postgres-config
      volumeMounts:
        - mountPath: /var/lib/postgresql/data
          name: postgredb
  volumes:
    - name: postgredb
      persistentVolumeClaim:
        claimName: efs
</code></pre>

<p>Surprisingly I am able to connect to psql but on 5432. :( Not sure what I am doing wrong. I passed containerPort as 55432</p>

<p>In short, you need to run the following command to expose your database on 55432 port.</p>

<pre><code>kubectl expose deployment postgres --port=55432 --target-port=5432 --name internal-postgresql-svc
</code></pre>

<p>From now on, you can connect to it via port 55432 from inside your cluster by using the service name as a hostname, or via its ClusterIP address:</p>

<pre><code>kubectl get internal-postgresql-svc
</code></pre>

<p>What you did in your deployment manifest file, you just attached additional information about the network connections a container uses, between misleadingly, because your container exposes 5432 port only (you can verify it by your self <a href="https://github.com/docker-library/postgres/blob/cc305ee1c59d93ac1808108edda6556b879374a4/10/Dockerfile#L174" rel="nofollow noreferrer">here</a>). <br><br>You should use a Kubernetes <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">Service</a> - abstraction which enables access to your PODs, and does the necessary port mapping behind the scene. <br><br>
Please check also <a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types" rel="nofollow noreferrer">different</a> port Types, if you want to expose your postgresql database outside of the Kubernetes cluster.
<br></p>

<hr>

<p>To test if progress is running fine inside POD`s container:</p>

<pre><code>kubectl run postgresql-postgresql-client --rm --tty -i --restart='Never' --namespace default --image bitnami/postgresql --env="PGPASSWORD=&lt;HERE_YOUR_PASSWORD&gt;" --command -- psql --host &lt;HERE_HOSTNAME=SVC_OR_IP&gt; -U &lt;HERE_USERNAME&gt; 
</code></pre>
