This sample creates a multi-container application in an Azure Kubernetes Service (AKS) cluster through GitHub Actions. The application interface has been built using Python / Flask. The data component is using Redis. This code is packaged into container images, uploaded to Azure Container Registry, and then run in an AKS cluster..
- Fork this repo.
- Create a free Azure Account with $200 credit (you can use your GitHub account): https://azure.microsoft.com/en-us/free/
- Go to the Azure Portal: https://ms.portal.azure.com/#home and open the Cloud Shell.
- Create a resource group
az group create --name <RESOURCEGROUPNAME> --location westeurope
- Create an Azure Container Registry (ACR)
az acr create --resource-group <RESOURCEGROUPNAME> --name <ACRNAME> --sku Basic
- Get username & password from ACR
az acr update -n <ACRNAME> --admin-enabled true
az acr credential show -n <ACRNAME>
- In GitHub, browse to your repository, select Settings > Secrets > Add a new secret and add the username and password from the last step in the following secret variables: REGISTRY_USERNAME REGISTRY_PASSWORD
- Create an AKS cluster (you have to wait a few minutes)
az aks create \
--resource-group <RESOURCEGROUPNAME> \
--name <AKSNAME> \
--node-count 2 \
--generate-ssh-keys \
--attach-acr <ACRNAME>
- Create a Service Principal. You can create a service principal by using the az ad sp create-for-rbac command.
az ad sp create-for-rbac --name <APPNAME> --role contributor --scopes /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP> --sdk-auth
You can obtain the <SUBSCRIPTION_ID> by using > az account list
- Copy this JSON object, which you can use to authenticate from GitHub. Add it to the following secret variable: AZURE_CREDENTIALS
- GitHub Actions gives you the flexibility to build an automated software development lifecycle workflow. The Kubernetes action azure/aks-set-context@v1 facilitate deployments to Azure Kubernetes Service clusters. The action sets the target AKS cluster context, which could be used by other actions like azure/k8s-deploy, azure/k8s-create-secret etc. or run any kubectl commands. Check: https://github.com/Azure/actions-workflow-samples/tree/master/Kubernetes
In this example, the workflow is already created in .github/workflows/main.yml. Check this file and change the values for the REGISTRY_NAME, CLUSTER_NAME, CLUSTER_RESOURCE_GROUP and NAMESPACE environment variables.