{"meta":{"title":"Deploying to Azure Kubernetes Service","intro":"Learn how to deploy a project to Azure Kubernetes Service (AKS) as part of a continuous deployment (CD) workflow.","product":"GitHub Actions","breadcrumbs":[{"href":"/en/actions","title":"GitHub Actions"},{"href":"/en/actions/how-tos","title":"How-tos"},{"href":"/en/actions/how-tos/deploy","title":"Deploy"},{"href":"/en/actions/how-tos/deploy/deploy-to-third-party-platforms","title":"Deploy to third-party platforms"},{"href":"/en/actions/how-tos/deploy/deploy-to-third-party-platforms/azure-kubernetes-service","title":"Azure Kubernetes Service"}],"documentType":"article"},"body":"# Deploying to Azure Kubernetes Service\n\nLearn how to deploy a project to Azure Kubernetes Service (AKS) as part of a continuous deployment (CD) workflow.\n\n## Prerequisites\n\nBefore creating your GitHub Actions workflow, you will first need to complete the following setup steps:\n\n1. Create a target AKS cluster and an Azure Container Registry (ACR). For more information, see [Quickstart: Deploy an AKS cluster by using the Azure portal - Azure Kubernetes Service](https://docs.microsoft.com/azure/aks/kubernetes-walkthrough-portal) and [Quickstart - Create registry in portal - Azure Container Registry](https://docs.microsoft.com/azure/container-registry/container-registry-get-started-portal) in the Azure documentation.\n\n1. Create a secret called `AZURE_CREDENTIALS` to store your Azure credentials. For more information about how to find this information and structure the secret, see [the `Azure/login` action documentation](https://github.com/Azure/login#configure-a-service-principal-with-a-secret).\n\n## Creating the workflow\n\nOnce you've completed the prerequisites, you can proceed with creating the workflow.\n\nThe following example workflow demonstrates how to build and deploy a project to Azure Kubernetes Service when code is pushed to your repository.\n\nUnder the workflow `env` key, change the following values:\n* `AZURE_CONTAINER_REGISTRY` to the name of your container registry\n* `PROJECT_NAME` to the name of your project\n* `RESOURCE_GROUP` to the resource group containing your AKS cluster\n* `CLUSTER_NAME` to the name of your AKS cluster\n\nThis workflow uses the `helm` render engine for the [`azure/k8s-bake` action](https://github.com/Azure/k8s-bake). If you will use the `helm` render engine, change the value of `CHART_PATH` to the path to your helm file. Change `CHART_OVERRIDE_PATH` to an array of override file paths. If you use a different render engine, update the input parameters sent to the `azure/k8s-bake` action.\n\n```yaml copy\n# This workflow uses actions that are not certified by GitHub.\n# They are provided by a third-party and are governed by\n# separate terms of service, privacy policy, and support\n# documentation.\n\n# GitHub recommends pinning actions to a commit SHA.\n# To get a newer version, you will need to update the SHA.\n# You can also reference a tag or branch, but the action may change without warning.\n\nname: Build and deploy to Azure Kubernetes Service\n\nenv:\n  AZURE_CONTAINER_REGISTRY: MY_REGISTRY_NAME # set this to the name of your container registry\n  PROJECT_NAME: MY_PROJECT_NAME              # set this to your project's name\n  RESOURCE_GROUP: MY_RESOURCE_GROUP          # set this to the resource group containing your AKS cluster\n  CLUSTER_NAME: MY_CLUSTER_NAME              # set this to the name of your AKS cluster\n  REGISTRY_URL: MY_REGISTRY_URL              # set this to the URL of your registry\n  # If you bake using helm:\n  CHART_PATH: MY_HELM_FILE                   # set this to the path to your helm file\n  CHART_OVERRIDE_PATH: MY_OVERRIDE_FILES     # set this to an array of override file paths\n\non: [push]\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n    steps:\n    - uses: actions/checkout@v6\n\n    - name: Azure Login\n      uses: azure/login@14a755a4e2fd6dff25794233def4f2cf3f866955\n      with:\n        creds: ${{ secrets.AZURE_CREDENTIALS }}\n\n    - name: Build image on ACR\n      uses: azure/CLI@61bb69d64d613b52663984bf12d6bac8fd7b3cc8\n      with:\n        azcliversion: 2.29.1\n        inlineScript: |\n          az configure --defaults acr=${{ env.AZURE_CONTAINER_REGISTRY }}\n          az acr build -t -t ${{ env.REGISTRY_URL }}/${{ env.PROJECT_NAME }}:${{ github.sha }}\n\n    - name: Gets K8s context\n      uses: azure/aks-set-context@94ccc775c1997a3fcfbfbce3c459fec87e0ab188\n      with:\n          creds: ${{ secrets.AZURE_CREDENTIALS }}\n          resource-group: ${{ env.RESOURCE_GROUP }}\n          cluster-name: ${{ env.CLUSTER_NAME }}\n      id: login\n\n    - name: Configure deployment\n      uses: azure/k8s-bake@61041e8c2f75c1f01186c8f05fb8b24e1fc507d8\n      with:\n        renderEngine: 'helm'\n        helmChart: ${{ env.CHART_PATH }}\n        overrideFiles: ${{ env.CHART_OVERRIDE_PATH }}\n        overrides: |\n          replicas:2\n        helm-version: 'latest'\n      id: bake\n\n    - name: Deploys application\n      uses: Azure/k8s-deploy@dd4bbd13a5abd2fc9ca8bdcb8aee152bb718fa78\n      with:\n        manifests: ${{ steps.bake.outputs.manifestsBundle }}\n        images: |\n          ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.PROJECT_NAME }}:${{ github.sha }}\n        imagepullsecrets: |\n          ${{ env.PROJECT_NAME }}\n```\n\n## Further reading\n\n* For the original workflow template, see [`azure-kubernetes-service.yml`](https://github.com/actions/starter-workflows/blob/main/deployments/azure-kubernetes-service.yml) in the GitHub Actions `starter-workflows` repository.\n* The actions used to in this workflow are the official Azure [`Azure/login`](https://github.com/Azure/login),[`Azure/aks-set-context`](https://github.com/Azure/aks-set-context), [`Azure/CLI`](https://github.com/Azure/CLI), [`Azure/k8s-bake`](https://github.com/Azure/k8s-bake), and [`Azure/k8s-deploy`](https://github.com/Azure/k8s-deploy)actions.\n* For more examples of GitHub Action workflows that deploy to Azure, see the [actions-workflow-samples](https://github.com/Azure/actions-workflow-samples) repository."}