<p>This might be very basic question but I can't find anywhere so I apologize..</p>

<p>I have installed postresql using helm on Google Kubernetes Engine</p>

<pre><code>$ helm install --name staging stable/postgresql
</code></pre>

<p>My deployments:</p>

<pre><code>$ kubectl get deployments
NAME                 DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
staging-backend      7         7         7            0           3h
staging-postgresql   1         1         1            0           3h
</code></pre>

<p>And my services:</p>

<pre><code>$ kubectl get services
NAME                 TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)    AGE
staging-postgresql   ClusterIP   xx.x.xxx.xx   &lt;none&gt;        5432/TCP   3h
</code></pre>

<p>I tried to connect <code>staging-backend</code> with <code>staging-postgresql</code> using cluster IP but it doesn't seem to work. Or should I use external IP..?? Where can I find external IP..??</p>

<p>thank Youu..</p>

<p>In Kubernetes you have two options to find IP of your service.</p>

<ol>
<li>Environment variables</li>
</ol>

<p>Kubernetes generates automatically environment variables with all the data you need to access a service. If you run <code>env</code> command inside a pod, then you should see similar output to:</p>

<pre><code>KUBERNETES_SERVICE_PORT=443
STAGING_POSTGRESQL_SERVICE_HOST=10.0.162.149
KUBERNETES_SERVICE_HOST=10.0.0.1
STAGING_POSTGRESQL_SERVICE_PORT=5432
KUBERNETES_SERVICE_PORT_HTTPS=443
</code></pre>

<p>Use <code>STAGING_POSTGRESQL_SERVICE_HOST</code> environment variable in your app to get the IP of service.</p>

<ol start="2">
<li>DNS (preferred)</li>
</ol>

<p>Kubernetes automatically assigns DNS names to all services. Use your service name instead of IP and it will be resolved to service IP. </p>

<p>For example run <code>ping staging-postgresql</code> inside any pod.</p>

<p>You can read more about using service <a href="https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/" rel="noreferrer">here</a>.</p>
