Failed to connect PosgresDB Flexible Server From a private AKS

Huynh, Huu Thang 20 Reputation points
2025-01-13T09:22:14.5+00:00

Hi all,

I am experiencing an issue with connecting to a PostgreSQL database from a private AKS cluster. The AKS and the database are located in two different virtual networks and subscriptions.

To debug the connection, I created a pod using the following command:

kubectl run -i --

However, when I try to connect to the database using common psql commands, I receive the following error:

psql: error: could not translate host name "xxxxxxxxxxxxxxxxxxx-flexible.postgres.database.azure.com" to address: Name or service not known

The connection is successful when the database is in the same virtual network as the AKS cluster. However, it fails when the database is in a different subscription.

Upon investigation, I found that running nslookup in a pod of the AKS cluster returns a result missing the IP address of the database’s private endpoint. Is this normal behavior? When I perform the same action with other databases located in the same subscription as the AKS, the IP address values are returned correctly. The only difference is that the problematic database is in a different subscription.

User's image

Any help with this would be greatly appreciated.

Thanks,

Thang

Azure Database for PostgreSQL
{count} votes

1 answer

Sort by: Most helpful
  1. Vijayalaxmi Kattimani 1,065 Reputation points Microsoft Vendor
    2025-01-13T16:36:51.36+00:00

    Hi @Huynh, Huu Thang,

    Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.

    As we understand that, you are experiencing an issue with connecting to a PostgreSQL database from a private AKS cluster. Based on the error message you provided, it seems like the hostname of the database is not being resolved to an IP address.

    Regarding your issue, about nslookup returning a result missing the IP address of the database's private endpoint, this could be due to the DNS resolution is not configured correctly for the virtual network where the database is located. Another possibility is that there is a firewall rule blocking the traffic between the AKS cluster and the database.

    To troubleshoot this issue, I would suggest the following steps:

    • Check the DNS resolution settings for the virtual network where the database is located. Make sure that the DNS server is configured correctly, and that the DNS resolution is working as expected.
    • Check the firewall rules for the virtual network where the database is located. Make sure that the firewall rules are not blocking the traffic between the AKS cluster and the database.
    • Check the network security group (NSG) settings for the virtual network where the database is located. Make sure that the NSG is not blocking the traffic between the AKS cluster and the database.
    • Check the connection string for the PostgreSQL database. Make sure that the hostname is correct and that the port number is specified correctly.
    • Try connecting to the PostgreSQL database from a different location, such as a virtual machine in the same virtual network as the AKS cluster. This will help you determine if the issue is specific to the AKS cluster or if it is a more general networking issue.

    Please refer to the below mentioned links for more information.

    https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/how-to-manage-virtual-network-portal

    https://docs.azure.cn/en-us/postgresql/flexible-server/concepts-networking-private-link

    https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/quickstart-create-connect-server-vnet

    I hope this information helps. Please do let us know if you have any further queries.

    If the answer is helpful, please click "Accept Answer" and "Upvote it".


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.