Cannot connect to Cosmos DB API for Mongo DB From AKS Cluster\Container

2/26/2022

I am trying to connect my python flask application running on AKS cluster to my Cosmos DB instance using the connection string within the code. My cosmos db setting are configured to be open for all networks and not restricted but somehow I am getting a time out error.

I am using Cosmos DB Mongo API , and the url connection string is as follows:

     "url": mongodb://dbname:[pass]-==@dbname.mongo.cosmos.azure.com:port/?ssl=true&retrywrites=false&replicaSet=globaldb&maxIdleTimeMS=120000&appName=@appname@ 


      client = MongoClient(cfg.db['url'])
      client_string = cfg.db['url']

I looked at the container logs and am getting the following error
''' raise ServerSelectionTimeoutError( pymongo.errors.ServerSelectionTimeoutError: chatbotmongodb.mongo.cosmos.azure.com:10255: Errno -3 Temporary failure in name resolution, Timeout: 30s, Topology Description: <TopologyDescription id: 621a9db116a435c37e59500c, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('chatbotmongodb.mongo.cosmos.azure.com', 10255) server_type: Unknown, rtt: None, error=AutoReconnect('chatbotmongodb.mongo.cosmos.azure.com:10255: Errno -3 Temporary failure in name resolution')>]> '''

I ran the Image locally and its runs properly ,its within the kubernetes cluster that there is a problem, I think its because of the NSG rules, I added rules to allow cosmos db access to my vnet as well, but its not working.

Any insight on this is appreciated.

-- data2505
azure
azure-aks
azure-cosmosdb-mongoapi
containers
kubernetes

1 Answer

2/28/2022

The above was resolved, it seemed NSG related issue which was blocking the pod interaction , once the rules were modified they started working

-- data2505
Source: StackOverflow