<p>My web api cannot connect to a PostgreSQL database on the same cluster in AKS. I created a ClusterIP for postgres, then used the IP address from that ClusterIP as the host in my database connection. I used the default port, 5432.</p>
<p>Do note that it was working when I use NodePort before.</p>
<p>Here is PostgreSQL ClusterIP service yaml:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: postgres-service
  labels:
    app: portal
spec:  
  type: ClusterIP
  ports:  
  - port: 5432
  selector:
    app: portal
    tier: postgres
</code></pre>
<p>Below is the services that are running. I used the Cluster-IP of the postgres-service as the host on my database connection string in my web ap.</p>
<p>This is part of my connection string:
<code>&quot;portal&quot;: &quot;host=10.0.....;port=5432;</code></p>
<p><a href="https://i.stack.imgur.com/eVrE3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eVrE3.png" alt="enter image description here" /></a></p>
<p>Not sure what's wrong with this but the web api cannot connect to the database. Below is the error.</p>
<p><code>Cannot connect to database. Error: Npgsql.NpgsqlException (0x80004005): Exception while connecting\n ---&gt; System.TimeoutException: The operation has timed out.\n   at Npgsql.TaskExtensions.WithTimeout(Task task, NpgsqlTimeout timeout)\n  at Npgsql.NpgsqlConnector.ConnectAsync(NpgsqlTimeout timeout, CancellationToken cancellationToken)\n   at Npgsql.NpgsqlConnector.ConnectAsync(NpgsqlTimeout timeout, CancellationToken cancellationToken)\n   at Npgsql.NpgsqlConnector.RawOpen(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)\n   at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)\n   at Npgsql.NpgsqlConnection.&lt;&gt;c__DisplayClass32_0.&lt;&lt;Open&gt;g__OpenLong|0&gt;d.MoveNext()\n--- End of stack trace from previous location where exception was thrown ---\n   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.ExistsAsync(CancellationToken cancellationToken)\n   at</code></p>
<p>Here is the desribe for the postgres-service</p>
<pre><code>Name:              postgres-service
Namespace:         default
Labels:            app=portal
Annotations:       &lt;none&gt;
Selector:          app=portal,tier=postgres
Type:              ClusterIP
IP:                10.0.xxx.xxx
Port:              &lt;unset&gt;  5432/TCP
TargetPort:        5432/TCP
Endpoints:         10.xxx.xxx.xxx:5432
Session Affinity:  None
Events:            &lt;none&gt;
</code></pre>

Rod Talingting
<p>I was able to make it work now. The issue was not the ClusterIP but it was my API deployment to AKS not working properly.</p>
<p>After fixing my release pipeline, everything is working again.</p>
