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
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/quickstart-azure-kubernetes-service.md
+73-43Lines changed: 73 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,17 +11,18 @@ ms.date: 04/06/2023
11
11
ms.author: junbchen
12
12
#Customer intent: As an Azure Kubernetes Service user, I want to manage all my app settings in one place using Azure App Configuration.
13
13
---
14
+
14
15
# Quickstart: Use Azure App Configuration in Azure Kubernetes Service (preview)
15
-
In Kubernetes, you set up pods to consume ConfigMaps for configuration. It lets you decouple configuration from your container images, making your applications easily portable. [Azure App Configuration Kubernetes Provider](https://mcr.microsoft.com/product/azure-app-configuration/kubernetes-provider/about) can construct ConfigMaps based on your data in Azure App Configuration. It enables you to take advantage of Azure App Configuration for the centralized storage and management of your configuration without any changes to your application code.
16
+
17
+
In Kubernetes, you set up pods to consume configuration from ConfigMaps. It lets you decouple configuration from your container images, making your applications easily portable. [Azure App Configuration Kubernetes Provider](https://mcr.microsoft.com/product/azure-app-configuration/kubernetes-provider/about) can construct ConfigMaps and Secrets from your key-values and Key Vault references in Azure App Configuration. It enables you to take advantage of Azure App Configuration for the centralized storage and management of your configuration without any changes to your application code.
16
18
17
19
In this quickstart, you incorporate Azure App Configuration Kubernetes Provider in an Azure Kubernetes Service workload where you run a simple ASP.NET Core app consuming configuration from environment variables.
18
20
19
21
## Prerequisites
20
22
21
-
* An Azure account with an active subscription. [Create one for free](https://azure.microsoft.com/free/).
22
23
* An App Configuration store. [Create a store](./quickstart-azure-app-configuration-create.md#create-an-app-configuration-store).
23
-
* An Azure Container Registry. [Create a registry](/azure/aks/tutorial-kubernetes-prepare-acr?tabs=azure-cli#create-an-azure-container-registry).
24
-
* An Azure Kubernetes Service (AKS) cluster that integrates with the Azure Container Registry you created. [Create an AKS cluster](/azure/aks/tutorial-kubernetes-deploy-cluster?tabs=azure-cli#create-a-kubernetes-cluster).
24
+
* An Azure Container Registry. [Create a registry](/azure/aks/tutorial-kubernetes-prepare-acr#create-an-azure-container-registry).
25
+
* An Azure Kubernetes Service (AKS) cluster that integrates with the Azure Container Registry you created. [Create an AKS cluster](/azure/aks/tutorial-kubernetes-deploy-cluster#create-a-kubernetes-cluster).
@@ -32,17 +33,20 @@ In this quickstart, you incorporate Azure App Configuration Kubernetes Provider
32
33
>
33
34
34
35
## Create an application running in AKS
36
+
35
37
In this section, it creates an ASP.NET Core web application that consumes environment variables as configuration and run it in Azure Kubernetes Service. This section has nothing to do with Azure App Configuration or Azure App Configuration Kubernetes Provider, it just for demonstrating the end-to-end usage scenario of Azure App Configuration Kubernetes Provider later. If you already have an application that is consuming environment variables in Kubernetes, you can just skip this section and go to [Use App Configuration Kubernetes Provider](#use-app-configuration-kubernetes-provider).
38
+
36
39
### Create an application
37
-
1. Use the .NET Core command-line interface (CLI) and run the following command to create a new ASP.NET Core web app project in a new MyWebApp folder:
40
+
41
+
1. Use the .NET Core command-line interface (CLI) and run the following command to create a new ASP.NET Core web app project in a new MyWebApp directory:
38
42
39
-
```dotnetcli
43
+
```dotnetcli
40
44
dotnet new webapp --output MyWebApp --framework net6.0
41
45
```
42
46
43
47
1. Open *Index.cshtml* in the Pages directory, and update the content with the following code.
44
48
45
-
```html
49
+
```html
46
50
@page
47
51
@model IndexModel
48
52
@using Microsoft.Extensions.Configuration
@@ -63,15 +67,16 @@ In this section, it creates an ASP.NET Core web application that consumes enviro
63
67
```
64
68
65
69
### Containerize the application
70
+
66
71
1. Run the [dotnet publish](/dotnet/core/tools/dotnet-publish) command to build the app in release mode and create the assets in the published folder.
67
72
68
-
```dotnetcli
73
+
```dotnetcli
69
74
dotnet publish -c Release -o published
70
75
```
71
76
72
77
1. Create a file named *Dockerfile* in the directory containing your .csproj file, open it in a text editor, and enter the following content. A Dockerfile is a text file that doesn't have an extension and that is used to create a container image.
73
78
74
-
```dockerfile
79
+
```dockerfile
75
80
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime
76
81
WORKDIR /app
77
82
COPY published/ ./
@@ -80,12 +85,13 @@ In this section, it creates an ASP.NET Core web application that consumes enviro
80
85
81
86
1. Build a container image named *aspnetapp* by running the following command.
82
87
83
-
```docker
88
+
```docker
84
89
docker build --tag aspnetapp .
85
90
```
86
91
87
92
### Push the image to Azure Container Registry
88
-
1. Run the [az acr login](/cli/azure/acr#az-acr-login) command to login your container registry. The following example login a registry named *myregistry*. Replace the registry name with yours.
93
+
94
+
1. Run the [az acr login](/cli/azure/acr#az-acr-login) command to login your container registry. The following example logs into a registry named *myregistry*. Replace the registry name with yours.
89
95
90
96
```azurecli
91
97
az acr login --name myregistry
@@ -108,12 +114,13 @@ In this section, it creates an ASP.NET Core web application that consumes enviro
108
114
docker push myregistry.azurecr.io/aspnetapp:v1
109
115
```
110
116
111
-
### Deploy and visit the application
117
+
### Deploy the application
118
+
112
119
1. Create an *AKS-AppConfiguration-Demo* directory in the root directory of your project.
113
120
114
-
1. Add a *deployment.yaml* to the *AKS-AppConfiguration-Demo* directory with the following content to create a deployment. Replace the value of `template.spec.containers.image` with the image you created in the previous step.
121
+
1. Add a *deployment.yaml* file to the *AKS-AppConfiguration-Demo* directory with the following content to create a deployment. Replace the value of `template.spec.containers.image` with the image you created in the previous step.
115
122
116
-
```yaml
123
+
```yaml
117
124
apiVersion: apps/v1
118
125
kind: Deployment
119
126
metadata:
@@ -142,9 +149,9 @@ In this section, it creates an ASP.NET Core web application that consumes enviro
142
149
value: "Black"
143
150
```
144
151
145
-
1. Add a *service.yaml* to the *AKS-AppConfiguration-Demo* directory with the following content to create a LoadBalancer service.
152
+
1. Add a *service.yaml* file to the *AKS-AppConfiguration-Demo* directory with the following content to create a LoadBalancer service.
146
153
147
-
```yaml
154
+
```yaml
148
155
apiVersion: v1
149
156
kind: Service
150
157
metadata:
@@ -159,14 +166,14 @@ In this section, it creates an ASP.NET Core web application that consumes enviro
159
166
160
167
1. Run the following command to deploy the application to the AKS cluster.
1. Run the following command and get the External IP that exposed by the LoadBalancer service.
174
+
1. Run the following command and get the External IP address exposed by the LoadBalancer service.
168
175
169
-
``` bash
176
+
```console
170
177
kubectl get service configmap-demo-service -n appconfig-demo
171
178
```
172
179
@@ -175,8 +182,11 @@ In this section, it creates an ASP.NET Core web application that consumes enviro
175
182

176
183
177
184
## Use App Configuration Kubernetes Provider
185
+
178
186
Now that you have an application running in AKS, you'll deploy the App Configuration Kubernetes Provider to your AKS cluster running as a Kubernetes controller. The provider retrieves data from your App Configuration store and creates a ConfigMap, which is consumable as environment variables by your application.
187
+
179
188
### Setup the Azure App Configuration store
189
+
180
190
1. Add following key-values to the App Configuration store and leave **Label** and **Content Type** with their default values. For more information about how to add key-values to a store using the Azure portal or the CLI, go to [Create a key-value](./quickstart-azure-app-configuration-create.md#create-a-key-value).
181
191
182
192
|**Key**|**Value**|
@@ -186,7 +196,7 @@ Now that you have an application running in AKS, you'll deploy the App Configura
186
196
187
197
1. [Enabling the system-assigned managed identity on the Virtual Machine Scale Sets of your AKS cluster](/azure/active-directory/managed-identities-azure-resources/qs-configure-portal-windows-vmss#enable-system-assigned-managed-identity-on-an-existing-virtual-machine-scale-set). This allows the App Configuration Kubernetes Provider to use the managed identity to connect to your App Configuration store.
188
198
189
-
1. Grant read access to your App Configuration store by [assigning the managed identity the App Configuration Data Reader role](/azure/azure-app-configuration/howto-integrate-azure-managed-service-identity?tabs=core5x&pivots=framework-dotnet#grant-access-to-app-configuration).
199
+
1. Grant read access to your App Configuration store by [assigning the managed identity the App Configuration Data Reader role](/azure/azure-app-configuration/howto-integrate-azure-managed-service-identity#grant-access-to-app-configuration).
190
200
191
201
### Install App Configuration Kubernetes Provider to AKS cluster
192
202
1. Run the following command to get access credentials for your AKS cluster. Replace the value of the `name` and `resource-group` parameters with your AKS instance:
@@ -197,76 +207,96 @@ Now that you have an application running in AKS, you'll deploy the App Configura
197
207
198
208
1. Install Azure App Configuration Kubernetes Provider to your AKS cluster using `helm`:
1. Add an *appConfigurationProvider.yaml* file to the *AKS-AppConfiguration-Demo* directory with the following content to create an `AzureAppConfigurationProvider` resource. `AzureAppConfigurationProvider` is a custom resource that defines how to retrieve key-values from an Azure App Configuration store.
218
+
1. Add an *appConfigurationProvider.yaml* file to the *AKS-AppConfiguration-Demo* directory with the following content to create an `AzureAppConfigurationProvider` resource. `AzureAppConfigurationProvider` is a custom resource that defines how to retrieve key-values from an Azure App Configuration store and create a configMap.
209
219
210
220
Replace the value of the `endpoint` field with the endpoint of your Azure App Configuration store.
2. Update the *deployment.yaml* in *AKS-AppConfiguration-Demo* directory to use the configMap `demo-configmap` as environment variable.
232
+
233
+
> [!NOTE]
234
+
> `AzureAppConfigurationProvider` is a declarative API, it defines the desired state of the configMap that retrieves the key-values from the App Configuration store with following behavior:
235
+
>
236
+
> - The provider creates a configMap according to the definition of an `AzureAppConfigurationProvider`.
237
+
> - The provider doesn't update a configMap that is not created by the provider.
238
+
> - The provider keeps the data of configMap as a mirror of key-values from Azure App Configuration. Any changes to the configMap through other approaches will be reverted.
239
+
> - Deleting provider will delete the corresponding configMap along with it. If the configMap is deleted solely, the provider will recreate it.
240
+
241
+
1. Update the *deployment.yaml* in *AKS-AppConfiguration-Demo* directory to use the configMap `configmap-created-by-appconfig-provider` as environment variable.
224
242
225
243
Replace the whole `env` section
226
-
```yaml
244
+
```yaml
227
245
env:
228
246
- name: Settings__Message
229
247
value: "Message from the local configuration"
230
248
- name: Settings__FontColor
231
249
value: "Black"
232
250
```
233
251
with
234
-
```yaml
252
+
```yaml
235
253
envFrom:
236
254
- configMapRef:
237
-
name: demo-configmap
255
+
name: configmap-created-by-appconfig-provider
238
256
```
239
257
240
-
3. Run the following command to deploy the `AzureAppConfigurationProvider` resource.
258
+
1. Run the following command to deploy the `AzureAppConfigurationProvider` resource.
4. Refresh the browser. The page shows updated content.
264
+
1. Refresh the browser. The page shows updated content.
247
265
248
266

249
267
250
268
### Troubleshooting
269
+
251
270
If you don't see your application picking up the data from your App Configuration store, run the following command to validate that the ConfigMap is created properly.
252
271
253
-
``` bash
254
-
kubectl get configmap demo-configmap -n appconfig-demo
272
+
```console
273
+
kubectl get configmap configmap-created-by-appconfig-provider -n appconfig-demo
255
274
```
256
275
257
276
If the ConfigMap is not created properly, run the following command to get the data retrieval status.
258
277
259
-
```bash
278
+
```console
260
279
kubectl get AzureAppConfigurationProvider appconfigurationprovider-sample -n appconfig-demo -o yaml
261
280
```
262
281
263
282
If the Azure App Configuration Kubernetes Provider retrieved data from your App Configuration store successfully, the `phase` property under the status section of the output should be `COMPLETE`, as shown in the following example.
264
283
265
-

284
+
```console
285
+
$ kubectl get AzureAppConfigurationProvider appconfigurationprovider-sample -n appconfig-demo -o yaml
286
+
287
+
apiVersion: azconfig.io/v1beta1
288
+
kind: AzureAppConfigurationProvider
289
+
... ... ...
290
+
status:
291
+
lastReconcileTime: "2023-04-06T06:17:06Z"
292
+
lastSyncTime: "2023-04-06T06:17:06Z"
293
+
message: Complete sync settings to ConfigMap or Secret
294
+
phase: COMPLETE
295
+
```
266
296
267
297
If the phase is not `COMPLETE`, the data isn't downloaded from your App Configuration store properly. Run the following command to show the logs of the Azure App Configuration Kubernetes Provider.
0 commit comments