You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Build, test, and deploy containers to Azure Kubernetes Service using GitHub Actions
3
-
description: Learn how to use GitHub Actions to deploy your container to Kubernetes
2
+
title: Build, test, and deploy containers to Azure Kubernetes Service (AKS) using GitHub Actions
3
+
description: Learn how to use GitHub Actions to build, test, and deploy containers to Azure Kubernetes Service (AKS).
4
4
ms.topic: article
5
-
ms.date: 08/02/2022
5
+
ms.date: 09/12/2023
6
6
ms.custom: github-actions-azure
7
7
---
8
8
9
-
# GitHub Actions for deploying to Kubernetes service
9
+
# Build, test, and deploy containers to Azure Kubernetes Service (AKS) using GitHub Actions
10
10
11
-
[GitHub Actions](https://docs.github.com/en/actions) gives you the flexibility to build an automated software development lifecycle workflow. You can use multiple Kubernetes actions to deploy to containers from Azure Container Registry to Azure Kubernetes Service with GitHub Actions.
11
+
[GitHub Actions](https://docs.github.com/en/actions) gives you the flexibility to build an automated software development lifecycle workflow. You can use multiple Kubernetes actions to deploy to containers from Azure Container Registry (ACR) to Azure Kubernetes Service (AKS) with GitHub Actions.
12
12
13
13
## Prerequisites
14
14
15
-
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
16
-
- A GitHub account. If you don't have one, sign up for [free](https://github.com/join).
17
-
- An existing AKS cluster with an attached Azure Container Registry (ACR).
15
+
- An Azure account with an active subscription. If you don't have one, [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
16
+
- A GitHub account. If you don't have one, [sign up for free](https://github.com/join).
17
+
- When using GitHub Actions, you need to configure the integration between Azure and your GitHub repository. To configure the integration, see [Use GitHub Actions to connect to Azure][connect-gh-azure].
18
+
- An existing AKS cluster with an attached ACR. If you don't have one, see [Authenticate with ACR from AKS](./cluster-container-registry-integration.md).
18
19
19
-
## Configure integration between Azure and your GitHub repository
20
+
## GitHub Actions for AKS
20
21
21
-
When using GitHub Actions, you need to configure the integration between Azure and your GitHub repository. For more details on connecting your GitHub repository to Azure, see [Use GitHub Actions to connect to Azure][connect-gh-azure].
22
+
With GiHub Actions, you can automate your software development workflows from within GitHub. For more information, see [GitHub Actions for Azure][github-actions].
22
23
23
-
## Available actions
24
-
25
-
GitHub Actions helps you automate your software development workflows from within GitHub. For more details on using GitHub Actions with Azure, see [What is GitHub Actions for Azures][github-actions].
26
-
27
-
The below table shows the available GitHub Actions that integrate specifically with AKS.
24
+
The following table lists the available actions for AKS:
28
25
29
26
| Name | Description | More details |
30
27
|---|---|---|
31
-
|`azure/aks-set-context`|Set the target AKS cluster context which will be used by other actions or run any kubectl commands.|[azure/aks-set-context][azure/aks-set-context]|
32
-
|`azure/k8s-set-context`|Set the target Kubernetes cluster context which will be used by other actions or run any kubectl commands.|[azure/k8s-set-context][azure/k8s-set-context]|
33
-
|`azure/k8s-bake`|Bake manifest file to be used for deployments using Helm, kustomize or kompose.|[azure/k8s-bake][azure/k8s-bake]|
28
+
|`azure/aks-set-context`|Set the target AKS cluster context for other actions to use or run any kubectl commands.|[azure/aks-set-context][azure/aks-set-context]|
29
+
|`azure/k8s-set-context`|Set the target Kubernetes cluster context for other actions to use or run any kubectl commands.|[azure/k8s-set-context][azure/k8s-set-context]|
30
+
|`azure/k8s-bake`|Bake manifest file to use for deployments using Helm, kustomize, or kompose.|[azure/k8s-bake][azure/k8s-bake]|
34
31
|`azure/k8s-create-secret`|Create a generic secret or docker-registry secret in the Kubernetes cluster.|[azure/k8s-create-secret][azure/k8s-create-secret]|
35
32
|`azure/k8s-deploy`|Deploy manifests to Kubernetes clusters.|[azure/k8s-deploy][azure/k8s-deploy]|
36
33
|`azure/k8s-lint`|Validate/lint your manifest files.|[azure/k8s-lint][azure/k8s-lint]|
37
34
|`azure/setup-helm`|Install a specific version of Helm binary on the runner.|[azure/setup-helm][azure/setup-helm]|
38
-
|`azure/setup-kubectl`|Installs a specific version of kubectl on the runner.|[azure/setup-kubectl][azure/setup-kubectl]|
35
+
|`azure/setup-kubectl`|Install a specific version of kubectl on the runner.|[azure/setup-kubectl][azure/setup-kubectl]|
39
36
|`azure/k8s-artifact-substitute`|Update the tag or digest for container images.|[azure/k8s-artifact-substitute][azure/k8s-artifact-substitute]|
40
37
|`azure/aks-create-action`|Create an AKS cluster using Terraform.|[azure/aks-create-action][azure/aks-create-action]|
41
38
|`azure/aks-github-runner`|Set up self-hosted agents for GitHub Actions.|[azure/aks-github-runner][azure/aks-github-runner]|
39
+
|`azure/acr-build`|Build containers using ACR.|[azure/acr-build][azure/acr-build]|
42
40
43
-
In addition, the example in the next section uses the [azure/acr-build][azure/acr-build] action.
44
-
45
-
## Example of using GitHub Actions with AKS
41
+
## Use GitHub Actions with AKS
46
42
47
43
As an example, you can use GitHub Actions to deploy an application to your AKS cluster every time a change is pushed to your GitHub repository. This example uses the [Azure Vote][gh-azure-vote] application.
48
44
49
45
> [!NOTE]
50
-
> This example uses a service principal for authentication with your ACR and AKS cluster. Alternatively, you can configure Open ID Connect (OIDC) and update the `azure/login` action to use OIDC. For more details, see [Set up Azure Login with OpenID Connect authentication][oidc-auth].
46
+
> This example uses a service principal for authentication with your ACR and AKS cluster. Alternatively, you can configure Open ID Connect (OIDC) and update the `azure/login` action to use OIDC. For more information, see [Set up Azure Login with OpenID Connect authentication][oidc-auth].
51
47
52
48
### Fork and update the repository
53
49
54
-
Navigate to the [Azure Vote][gh-azure-vote] repository and click the **Fork** button.
50
+
1. Navigate to the [Azure Vote][gh-azure-vote] repository and select **Fork**.
51
+
2. Update the `azure-vote-all-in-one-redis.yaml` to use your ACR for the `azure-vote-front` image. Replace `<registryName>` with the name of your registry.
55
52
56
-
Once the repository is forked, update `azure-vote-all-in-one-redis.yaml` to use your ACR for the `azure-vote-front` image
The following shows an example output from the above command.
85
-
86
-
```output
87
-
{
88
-
"clientId": <clientId>,
89
-
"clientSecret": <clientSecret>,
90
-
"subscriptionId": <subscriptionId>,
91
-
"tenantId": <tenantId>,
92
-
...
93
-
}
94
-
```
95
-
96
-
In your GitHub repository, create the below secrets for your action to use. To create a secret:
97
-
1. Navigate to the repository's settings, and select **Security > Secrets and variables > Actions**.
98
-
1. For each secret, click **New Repository Secret** and enter the name and value of the secret.
99
-
100
-
For more details on creating secrets, see [Encrypted Secrets][github-actions-secrets].
101
-
102
-
|Secret name |Secret value |
103
-
|---------|---------|
104
-
|AZURE_CREDENTIALS|The entire JSON output from the `az ad sp create-for-rbac` command|
105
-
|service_principal | The value of `<clientId>`|
106
-
|service_principal_password| The value of `<clientSecret>`|
107
-
|subscription| The value of `<subscriptionId>`|
108
-
|tenant|The value of `<tenantId>`|
109
-
|registry|The name of your registry|
110
-
|repository|azuredocs|
111
-
|resource_group|The name of your resource group|
112
-
|cluster_name|The name of your cluster|
113
-
65
+
1. Create a service principal to access your resource group with the `Contributor` role using the [`az ad sp create-for-rbac`][az-ad-sp-create-for-rbac] command. Replace `<SUBSCRIPTION_ID>` with the subscription ID of your Azure account and `<RESOURCE_GROUP>` with the name of the resource group containing your ACR.
> The `.github/workflows/main.yml` file must be committed to your repository before you can run the action.
171
-
172
-
The `on` section contains the event that triggers the action. In the above file, the action is triggered when a change is pushed to the `azure-vote` directory.
173
-
174
-
In the above file, the `steps` section contains each distinct action, which is executed in order:
175
-
1. *Checkout source code* uses the [GitHub Actions Checkout Action][actions/checkout] to clone the repository.
176
-
1. *ACR build* uses the [Azure Container Registry Build Action][azure/acr-build] to build the image and upload it to your registry.
177
-
1. *Azure login* uses the [Azure Login Action][azure/login] to sign in to your Azure account.
178
-
1. *Set AKS context* uses the [Azure AKS Set Context Action][azure/aks-set-context] to set the context for your AKS cluster.
179
-
1. *Setup kubectl* uses the [Azure AKS Setup Kubectl Action][azure/setup-kubectl] to install kubectl on your runner.
180
-
1. *Deploy to AKS* uses the [Azure Kubernetes Deploy Action][azure/k8s-deploy] to deploy the application to your Kuberentes cluster.
181
-
182
-
Confirm that the action is working by updating `azure-vote/azure-vote/config_file.cfg` to the following and pushing the changes to your repository:
183
-
184
-
```output
185
-
# UI Configurations
186
-
TITLE = 'Azure Voting App'
187
-
VOTE1VALUE = 'Fish'
188
-
VOTE2VALUE = 'Dogs'
189
-
SHOWHOST = 'false'
190
-
```
191
-
192
-
In your repository, click on *Actions* and confirm a workflow is running. Once complete, confirm the workflow has a green checkmark and the updated application is deployed to your cluster.
106
+
1. In your repository, create a `.github/workflows/main.yml` and paste in the following contents:
The `on` section contains the event that triggers the action. In the example file, the action triggers when a change is pushed to the `azure-vote` directory.
159
+
160
+
The `steps` section contains each distinct action:
161
+
162
+
1. *Checkout source code* uses the [GitHub Actions Checkout Action][actions/checkout] to clone the repository.
163
+
2. *ACR build* uses the [Azure Container Registry Build Action][azure/acr-build] to build the image and upload it to your registry.
164
+
3. *Azure login* uses the [Azure Login Action][azure/login] to sign in to your Azure account.
165
+
4. *Set AKS context* uses the [Azure AKS Set Context Action][azure/aks-set-context] to set the context for your AKS cluster.
166
+
5. *Setup kubectl* uses the [Azure AKS Setup Kubectl Action][azure/setup-kubectl] to install kubectl on your runner.
167
+
6. *Deploy to AKS* uses the [Azure Kubernetes Deploy Action][azure/k8s-deploy] to deploy the application to your Kubernetes cluster.
168
+
169
+
2. Commit the `.github/workflows/main.yml` file to your repository.
170
+
3. To confirm the action is working, update the `azure-vote/azure-vote/config_file.cfg` with the following contents:
171
+
172
+
```cfg
173
+
# UI Configurations
174
+
TITLE = 'Azure Voting App'
175
+
VOTE1VALUE = 'Fish'
176
+
VOTE2VALUE = 'Dogs'
177
+
SHOWHOST = 'false'
178
+
```
179
+
180
+
4. Commit the updated `azure-vote/azure-vote/config_file.cfg` to your repository.
181
+
5. In your repository, select **Actions** and confirm a workflow is running. Then, confirm the workflow has a green checkmark and the updated application is deployed to your cluster.
193
182
194
183
## Next steps
195
184
196
-
Review the following starter workflows for AKS. For more details on using starter workflows, see [Using starter workflows][use-starter-workflows].
185
+
Review the following starter workflows for AKS. For more information, see [Using starter workflows][use-starter-workflows].
197
186
198
187
- [Azure Kubernetes Service (Basic)][aks-swf-basic]
199
188
- [Azure Kubernetes Service Helm][aks-swf-helm]
@@ -206,6 +195,8 @@ Review the following starter workflows for AKS. For more details on using starte
206
195
> [!div class="nextstepaction"]
207
196
> [Learn about Azure Kubernetes Service](/azure/architecture/reference-architectures/containers/aks-start-here)
0 commit comments