This guide walks you through deploying and running Kong on Microsoft Azure Container Instances.

We will be using either Azure Database for PostgreSQL or Cosmos DB to store the gateway configuration.

Running Kong on Azure Container Instances

Azure Container Instances is a great way to run lightweight containers in a serverless fashion.

Running Kong on Azure Container Instances is super easy:

  1. Provision a datastore

    Provision the datastore that you want to use:

    1. Running Cassandra on Azure with Azure Cosmos DB
    2. Running PostgreSQL on Azure with Azure Database for PostgreSQL
  2. Open the Cloud Shell or Azure CLI

  3. Run the migrations

     $ az container create --name kong-migrations \
                           --resource-group kong-sandbox \
                           --image kong:latest \
                           --restart-policy Never \
                           --environment-variables KONG_PG_HOST="<instance-name>.postgres.database.azure.com" \
                                                   KONG_PG_USER="<username>" \
                                                   KONG_PG_PASSWORD="<password>" \
                           --command-line "kong migrations up"
    

    In this example, we are using a PostgreSQL database running on Azure Database for PostgreSQL.

  4. Start Kong

     $ az container create --name kong-gateway /
                           --dns-name-label kong-gateway /
                           --resource-group kong-sandbox /
                           --image kong:latest /
                           --port 8000 8443 8001 8444 /
                           --environment-variables KONG_PG_HOST="<instance-name>.postgres.database.azure.com" /
                                                   KONG_PG_USER="<username>" /
                                                   KONG_PG_PASSWORD="<password>" /
                                                   KONG_PROXY_ACCESS_LOG="/dev/stdout" /
                                                   KONG_ADMIN_ACCESS_LOG="/dev/stdout" /
                                                   KONG_PROXY_ERROR_LOG="/dev/stderr" /
                                                   KONG_ADMIN_ERROR_LOG="/dev/stderr" /
                                                   KONG_ADMIN_LISTEN="0.0.0.0:8001, 0.0.0.0:8444 ssl"
    

    The 8000, 8001, 8443, and 8444 will be forwarded to the container.

    Note: This will expose both the proxy and the Admin API on the default ports. This can have security implications.
  5. Use Kong

    That’s it - You can now use Kong by browsing to <dns-label>.westeurope.azurecontainer.io.

    Quickly learn how to use Kong with the 5-minute Quickstart.