Skip to content

Commit eae4f38

Browse files
Add note for declarative API
1 parent e74398c commit eae4f38

File tree

2 files changed

+73
-43
lines changed

2 files changed

+73
-43
lines changed

articles/azure-app-configuration/quickstart-azure-kubernetes-service.md

Lines changed: 73 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ ms.date: 04/06/2023
1111
ms.author: junbchen
1212
#Customer intent: As an Azure Kubernetes Service user, I want to manage all my app settings in one place using Azure App Configuration.
1313
---
14+
1415
# 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.
1618

1719
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.
1820

1921
## Prerequisites
2022

21-
* An Azure account with an active subscription. [Create one for free](https://azure.microsoft.com/free/).
2223
* 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).
2526
* [.NET Core SDK](https://dotnet.microsoft.com/download)
2627
* [Azure CLI](/cli/azure/install-azure-cli)
2728
* [helm](https://helm.sh/docs/intro/install/)
@@ -32,17 +33,20 @@ In this quickstart, you incorporate Azure App Configuration Kubernetes Provider
3233
>
3334
3435
## Create an application running in AKS
36+
3537
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+
3639
### 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:
3842

39-
``` dotnetcli
43+
```dotnetcli
4044
dotnet new webapp --output MyWebApp --framework net6.0
4145
```
4246
4347
1. Open *Index.cshtml* in the Pages directory, and update the content with the following code.
4448
45-
``` html
49+
```html
4650
@page
4751
@model IndexModel
4852
@using Microsoft.Extensions.Configuration
@@ -63,15 +67,16 @@ In this section, it creates an ASP.NET Core web application that consumes enviro
6367
```
6468
6569
### Containerize the application
70+
6671
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.
6772
68-
``` dotnetcli
73+
```dotnetcli
6974
dotnet publish -c Release -o published
7075
```
7176
7277
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.
7378
74-
``` dockerfile
79+
```dockerfile
7580
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime
7681
WORKDIR /app
7782
COPY published/ ./
@@ -80,12 +85,13 @@ In this section, it creates an ASP.NET Core web application that consumes enviro
8085
8186
1. Build a container image named *aspnetapp* by running the following command.
8287
83-
``` docker
88+
```docker
8489
docker build --tag aspnetapp .
8590
```
8691

8792
### 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.
8995

9096
```azurecli
9197
az acr login --name myregistry
@@ -108,12 +114,13 @@ In this section, it creates an ASP.NET Core web application that consumes enviro
108114
docker push myregistry.azurecr.io/aspnetapp:v1
109115
```
110116
111-
### Deploy and visit the application
117+
### Deploy the application
118+
112119
1. Create an *AKS-AppConfiguration-Demo* directory in the root directory of your project.
113120
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.
115122
116-
``` yaml
123+
```yaml
117124
apiVersion: apps/v1
118125
kind: Deployment
119126
metadata:
@@ -142,9 +149,9 @@ In this section, it creates an ASP.NET Core web application that consumes enviro
142149
value: "Black"
143150
```
144151
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.
146153
147-
``` yaml
154+
```yaml
148155
apiVersion: v1
149156
kind: Service
150157
metadata:
@@ -159,14 +166,14 @@ In this section, it creates an ASP.NET Core web application that consumes enviro
159166
160167
1. Run the following command to deploy the application to the AKS cluster.
161168
162-
``` bash
169+
```console
163170
kubectl create namespace appconfig-demo
164171
kubectl apply -f ./AKS-AppConfiguration-Demo -n appconfig-demo
165172
```
166173
167-
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.
168175
169-
``` bash
176+
```console
170177
kubectl get service configmap-demo-service -n appconfig-demo
171178
```
172179
@@ -175,8 +182,11 @@ In this section, it creates an ASP.NET Core web application that consumes enviro
175182
![Kubernetes Provider before using configMap ](./media/quickstarts/kubernetes-provider-app-launch-before.png)
176183
177184
## Use App Configuration Kubernetes Provider
185+
178186
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+
179188
### Setup the Azure App Configuration store
189+
180190
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).
181191
182192
|**Key**|**Value**|
@@ -186,7 +196,7 @@ Now that you have an application running in AKS, you'll deploy the App Configura
186196
187197
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.
188198
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).
190200
191201
### Install App Configuration Kubernetes Provider to AKS cluster
192202
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
197207
198208
1. Install Azure App Configuration Kubernetes Provider to your AKS cluster using `helm`:
199209
200-
``` bash
210+
```console
201211
helm install azureappconfiguration.kubernetesprovider \
202212
oci://mcr.microsoft.com/azure-app-configuration/helmchart/kubernetes-provider \
203213
--version 1.0.0-preview \
204214
--namespace azappconfig-system \
205215
--create-namespace
206216
```
207217
208-
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.
209219
210220
Replace the value of the `endpoint` field with the endpoint of your Azure App Configuration store.
211221
212-
``` yaml
222+
```yaml
213223
apiVersion: azconfig.io/v1beta1
214224
kind: AzureAppConfigurationProvider
215225
metadata:
216226
name: appconfigurationprovider-sample
217227
spec:
218228
endpoint: <your-app-configuration-store-endpoint>
219229
target:
220-
configMapName: demo-configmap
230+
configMapName: configmap-created-by-appconfig-provider
221231
```
222-
223-
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.
224242
225243
Replace the whole `env` section
226-
``` yaml
244+
```yaml
227245
env:
228246
- name: Settings__Message
229247
value: "Message from the local configuration"
230248
- name: Settings__FontColor
231249
value: "Black"
232250
```
233251
with
234-
``` yaml
252+
```yaml
235253
envFrom:
236254
- configMapRef:
237-
name: demo-configmap
255+
name: configmap-created-by-appconfig-provider
238256
```
239257
240-
3. Run the following command to deploy the `AzureAppConfigurationProvider` resource.
258+
1. Run the following command to deploy the `AzureAppConfigurationProvider` resource.
241259
242-
``` bash
260+
```console
243261
kubectl apply -f ./AKS-AppConfiguration-Demo -n appconfig-demo
244262
```
245263
246-
4. Refresh the browser. The page shows updated content.
264+
1. Refresh the browser. The page shows updated content.
247265
248266
![Kubernetes Provider after using configMap](./media/quickstarts/kubernetes-provider-app-launch-after.png)
249267
250268
### Troubleshooting
269+
251270
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.
252271
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
255274
```
256275

257276
If the ConfigMap is not created properly, run the following command to get the data retrieval status.
258277

259-
``` bash
278+
```console
260279
kubectl get AzureAppConfigurationProvider appconfigurationprovider-sample -n appconfig-demo -o yaml
261280
```
262281

263282
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.
264283

265-
![Kubernetes Provider get provider status](./media/quickstarts/kubernetes-provider-get-provider-status.png)
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+
```
266296

267297
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.
268298

269-
``` bash
299+
```console
270300
kubectl logs deployment/az-appconfig-k8s-provider -n azappconfig-system
271301
```
272302

@@ -278,22 +308,22 @@ Use the logs for further troubleshooting. For example, if you see requests to yo
278308

279309
Remove the resources that have been deployed to AKS.
280310

281-
``` bash
311+
```console
282312
kubectl delete -f ./AKS-AppConfiguration-Demo -n appconfig-demo
283313
kubectl delete namespace appconfig-demo
284314
```
285315

286316
Follow the steps below to uninstall the Azure App Configuration Kubernetes Provider from your AKS cluster.
287317

288-
``` bash
318+
```console
289319
helm uninstall azureappconfiguration.kubernetesprovider --namespace azappconfig-system
290320
```
291321

292322
## Summary
293323

294324
In this quickstart, you:
295325

296-
* Provisioned a new App Configuration store.
297-
* Connected to your App Configuration store in Kubernetes using the App Configuration Kubernetes Provider controller.
298-
* Download your App Configuration store's key-values to a ConfigMap.
299-
* Displayed a web page in Kubernetes using the settings you configured in your App Configuration store.
326+
* Created an application running in Azure Kubernetes Service (AKS).
327+
* Connected your AKS cluster to your App Configuration store using the App Configuration Kubernetes Provider.
328+
* Created a ConfigMap with data from your App Configuration store.
329+
* Ran the application with configuration from your App Configuration store without changing your application code.

0 commit comments

Comments
 (0)