Share the love

This workflow does the following:

  1. Triggers the workflow on push to the main branch.
  2. Logs in to Azure using the azure/login action, passing in the AZURE_CREDENTIALS secret that contains the service principal used to authenticate with Azure.
  3. Installs kubectl and Helm on the runner.
  4. Runs kubectl and helm command to deploy the application to the Azure Kubernetes Cluster.
  5. Notifies that the deployment is complete.

You’ll need to replace the my-resource-group, my-cluster, my-namespace, my-chart and k8s/deployment.yaml with your specific resource group, cluster name, namespace, chart and deployment file name.

Here is an example of a GitHub Action workflow file that you can use to deploy an application to an Azure Kubernetes Cluster:

name: Azure Deployment

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Login to Azure
      uses: azure/login@v1
      with:
        creds: ${{ secrets.AZURE_CREDENTIALS }}

    - name: Set up kubectl
      run: |
        VERSION=$(curl --silent https://storage.googleapis.com/kubernetes-release/release/stable.txt)
        curl -L --remote-name https://storage.googleapis.com/kubernetes-release/release/$VERSION/bin/linux/amd64/kubectl
        chmod +x kubectl
        sudo mv kubectl /usr/local/bin/

    - name: Set up Helm
      run: |
        VERSION=$(curl --silent https://api.github.com/repos/helm/helm/releases/latest | jq -r .tag_name)
        curl -L --remote-name https://get.helm.sh/helm-$VERSION-linux-amd64.tar.gz
        tar -zxvf helm-$VERSION-linux-amd64.tar.gz
        sudo mv linux-amd64/helm /usr/local/bin/

    - name: Deploy to Azure
      run: |
        export AKS_RESOURCE_GROUP=my-resource-group
        export AKS_CLUSTER_NAME=my-cluster
        export AKS_NAMESPACE=my-namespace

        # configure kubectl
        az aks get-credentials --resource-group $AKS_RESOURCE_GROUP --name $AKS_CLUSTER_NAME

        # deploy application
        kubectl apply -f k8s/deployment.yaml -n $AKS_NAMESPACE

        # deploy Helm chart
        helm upgrade -i my-chart charts/my-chart -n $AKS_NAMESPACE

    - name: Notify on success
      run: |
        echo "Deployment complete!"