AKS - web api cannot connect to database using ClusterIP on the same cluster

0

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.

Do note that it was working when I use NodePort before.

Here is PostgreSQL ClusterIP service yaml:

apiVersion: v1
kind: Service
metadata:
  name: postgres-service
  labels:
    app: portal
spec:  
  type: ClusterIP
  ports:  
  - port: 5432
  selector:
    app: portal
    tier: postgres

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.

This is part of my connection string: "portal": "host=10.0.....;port=5432;

enter image description here

Not sure what's wrong with this but the web api cannot connect to the database. Below is the error.

Cannot connect to database. Error: Npgsql.NpgsqlException (0x80004005): Exception while connecting\n ---> 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.<>c__DisplayClass32_0.<<Open>g__OpenLong|0>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

Here is the desribe for the postgres-service

Name:              postgres-service
Namespace:         default
Labels:            app=portal
Annotations:       <none>
Selector:          app=portal,tier=postgres
Type:              ClusterIP
IP:                10.0.xxx.xxx
Port:              <unset>  5432/TCP
TargetPort:        5432/TCP
Endpoints:         10.xxx.xxx.xxx:5432
Session Affinity:  None
Events:            <none>
postgresql
kubernetes
azure-aks
asked on Stack Overflow Jul 3, 2020 by Rod Talingting • edited Jul 3, 2020 by Rod Talingting

1 Answer

1

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.

After fixing my release pipeline, everything is working again.

answered on Stack Overflow Jul 3, 2020 by Rod Talingting

User contributions licensed under CC BY-SA 3.0