Testing Azure SQL Server connection with Python

Testing connectivity from AKS clusters to Azure Micrsoft SQL Server Endpoint can be a cumbersome task as we need to download and install different tools to work with respective Database. In this example, we will use a simple python script that use the pymssql official library to execute a connection on the provided endpoint with the username, password and database name provided as environment variables.

We will use a nginx based Pod/VM where will install the following components:

  • Python3
  • Python3-pip
  • pymssql (pip Library)

# Installation

We can use a standard nginx Pod or a preconfigured one as described in the Source Code section

Adding the Environment Variables that holds our SQL endpoint, username, password and database name along with the time interval in second:

Run your script with the following command:

If successful connection, it will output the following:

Otherwise, it will throw an error like this:

It will also log the requests in a local file on Pod, azsqltest.log. For data persistency please mount an emptyDir and share the script’s folder with the underlying Node.

Ready to run Pod environment

Script Content:

GitHub Repository: https://github.com/OvidiuBorlean/azsqltest



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store