Skip to content

Commit ef1b8bf

Browse files
Refactor the structure according to the comments
1 parent d617b37 commit ef1b8bf

File tree

4 files changed

+112
-84
lines changed

4 files changed

+112
-84
lines changed

articles/azure-app-configuration/index.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ landingContent:
8282
url: quickstart-resource-manager.md
8383
- text: Azure Container Apps
8484
url: quickstart-container-apps.md
85-
- text: Azure Kubernetes Service
86-
url: quickstart-azure-kubernetes-service.md
8785
- linkListType: tutorial
8886
links:
8987
- text: Use dynamic config in ASP.NET Core
23.7 KB
Loading
22.2 KB
Loading

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

Lines changed: 112 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -31,51 +31,35 @@ In this quickstart, you will incorporate Azure App Configuration Kubernetes Prov
3131
> The Azure Cloud Shell is a free, interactive shell that you can use to run the command line instructions in this article. It has common Azure tools preinstalled, including the .NET Core SDK. If you're logged in to your Azure subscription, launch your [Azure Cloud Shell](https://shell.azure.com) from shell.azure.com. You can learn more about Azure Cloud Shell by [reading our documentation](../cloud-shell/overview.md)
3232
>
3333
34-
## Create an application consumes environment variables
35-
If you already have an application that is consuming environment variables as configuration, you can just skip this step. We just create an ASP.NET Core Web App `MyWebApp` as an example.
36-
34+
## Create an application running in AKS
35+
In this section, we present how to create an ASP.NET Core web application that consumes environment variables as configuration and run it in Azure Kubernetes Service. This part 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 as configuration in Kubernetes, you can just skip this and go to [Use App Configuration Kubernetes Provider](#use-app-configuration-kubernetes-provider).
36+
### Create an application
3737
1. Use the .NET Core command-line interface (CLI) to create a new ASP.NET Core web app project. Run the following command to create an ASP.NET Core web app in a new TestAppConfig folder:
3838
``` dotnetcli
3939
dotnet new webapp --output MyWebApp --framework net6.0
4040
```
4141
42-
1. Open *Index.cshtml.cs* in the Pages directory, and update the `IndexModel` class with the following code.
43-
``` csharp
44-
public class IndexModel : PageModel
45-
{
46-
private readonly IConfiguration _configuration;
47-
48-
public IndexModel(IConfiguration configuration)
49-
{
50-
_configuration = configuration;
51-
}
52-
public void OnGet()
53-
{
54-
ViewData["Message"] = _configuration.GetSection("Settings")["Message"];
55-
ViewData["FontColor"] = _configuration.GetSection("Settings")["FontColor"];
56-
}
57-
}
58-
```
5942
1. Open *Index.cshtml* in the Pages directory, and update the content with the following code.
6043
``` html
6144
@page
6245
@model IndexModel
46+
@using Microsoft.Extensions.Configuration
47+
@inject IConfiguration Configuration
6348
@{
6449
ViewData["Title"] = "Home page";
6550
}
6651
6752
<style>
6853
h1 {
69-
color: @ViewData["FontColor"];
54+
color: @Configuration.GetSection("Settings")["FontColor"];
7055
}
7156
</style>
57+
7258
<div class="text-center">
73-
<h1 class="display-4">@ViewData["Message"]</h1>
59+
<h1 class="display-4">@Configuration.GetSection("Settings")["Message"]</h1>
7460
</div>
7561
```
76-
77-
## Containerize the application
78-
If you already have an application, you can containerize it in a way that depends on your application. We just show you how to build the `MyWebApp` project to an image.
62+
### Containerize the application
7963
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.
8064
``` dotnetcli
8165
dotnet publish -c Release -o published
@@ -92,7 +76,7 @@ If you already have an application, you can containerize it in a way that depend
9276
docker build --tag aspnetapp .
9377
```
9478

95-
## Push the image to Azure Container Registry
79+
### Push the image to the registry
9680
1. Run the [az acr login](/cli/azure/acr#az-acr-login) command to log in to the registry.
9781

9882
```azurecli
@@ -124,47 +108,9 @@ If you already have an application, you can containerize it in a way that depend
124108
docker push myregistry.azurecr.io/aspnetapp:v1
125109
```
126110
127-
## Configure the Azure App Configuration store
128-
1. Add the key-values to your Azure App Configuration that should be consumed as environment variables by your application. We're just using key-values that be consumed by `MyWebApp` as an example, 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).
129-
130-
|**Key**|**Value**|
131-
|---|---|
132-
|Settings__FontColor|*Red*|
133-
|Settings__Message|*Hello from Azure App Configuration*|
134-
135-
1. Enable System Assigned Managed Identity of AKS NodePool
136-
137-
Go to the corresponding Virtual Machine Scale Sets resource of AKS, and enable system-assigned managed identity on the Virtual Machine Scale Sets by following this [doc](/azure/active-directory/managed-identities-azure-resources/qs-configure-portal-windows-vmss#enable-system-assigned-managed-identity-on-an-existing-virtual-machine-scale-set).
138-
139-
1. Assign Data Reader role to the System Assigned Managed Identity
140-
141-
Once the system-assigned managed identity has been enabled, you need to grant it read access to Azure AppConfiguration. You can do it by following the instructions in this [doc](/azure/azure-app-configuration/howto-integrate-azure-managed-service-identity?tabs=core5x&pivots=framework-dotnet#grant-access-to-app-configuration).
142-
143-
## Install App Configuration Kubernetes Provider to your AKS cluster
144-
145-
1. Get the credential to manage your AKS cluster, replace the `name` and `resource-group` parameters with yours:
146-
```bash
147-
az aks get-credentials --name my_aks --resource-group my_aks_resource_group
148-
```
149-
1. Install Azure App Configuration Kubernetes Provider to your AKS cluster using `helm`:
150-
``` bash
151-
helm install azureappconfiguration.kubernetesprovider oci://mcr.microsoft.com/azure-app-configuration/helmchart/kubernetes-provider --version 1.0.0-alpha --namespace azappconfig-system --create-namespace
152-
```
153-
154-
## Create and deploy Kubernetes resources
111+
### Deploy the application and browser it
112+
1. Create an *AKS-AppConfiguration-Demo* directory in the root directory of your project.
155113
156-
1. Create a *AKS-AppConfiguration-Demo* directory in the root directory of your project.
157-
1. Create *appConfigurationProvider.yaml* in the *AKS-AppConfiguration-Demo* directory with the following YAML content. Replace the value of the `endpoint` field with the endpoint of your Azure AppConfiguration store.
158-
``` yaml
159-
apiVersion: azconfig.io/v1beta1
160-
kind: AzureAppConfigurationProvider
161-
metadata:
162-
name: appconfigurationprovider-sample
163-
spec:
164-
endpoint: https://myappconfig.azconfig.io
165-
target:
166-
configMapName: demo-configmap
167-
```
168114
1. Create *deployment.yaml* in the *AKS-AppConfiguration-Demo* directory with the following YAML content. Replace the value of `template.spec.containers.image` with the image you created in the previous step.
169115
``` yaml
170116
apiVersion: apps/v1
@@ -188,9 +134,11 @@ If you already have an application, you can containerize it in a way that depend
188134
image: myregistry.azurecr.io/aspnetapp:v1
189135
ports:
190136
- containerPort: 80
191-
envFrom:
192-
- configMapRef:
193-
name: demo-configmap
137+
env:
138+
- name: Settings__Message
139+
value: "Hello from the environment variable"
140+
- name: Settings__FontColor
141+
value: "Orange"
194142
```
195143
1. Create *service.yaml* in the *AKS-AppConfiguration-Demo* with the following YAML content.
196144
``` yaml
@@ -205,15 +153,108 @@ If you already have an application, you can containerize it in a way that depend
205153
selector:
206154
app: configmap-demo-app
207155
```
156+
208157
1. Apply the YAML files to the AKS cluster
209158
``` bash
210159
kubectl create namespace quickstart-appconfig
211160
kubectl apply -f ./AKS-AppConfiguration-Demo -n quickstart-appconfig
212161
```
213162
214-
## Validate ConfigMap creation
163+
1. Run the following command and get the External IP that exposed by the LoadBalancer service.
164+
``` bash
165+
kubectl get service configmap-demo-service -n quickstart-appconfig
166+
```
167+
168+
1. Open a browser window, use the External IP of the service you get in previous step to visit the app. Your browser should display a page similar to the image below.
169+
170+
![Kubernetes Provider after using configMap ](./media/quickstarts/kubernetes-provider-app-launch-before.png)
171+
172+
## Use App Configuration Kubernetes Provider
173+
### Configure the Azure App Configuration store
174+
1. Add the key-values to your Azure App Configuration that should be consumed as environment variables by your application. We're just using key-values that be consumed by `MyWebApp` as an example, 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).
175+
176+
|**Key**|**Value**|
177+
|---|---|
178+
|Settings__FontColor|*Green*|
179+
|Settings__Message|*Hello from Azure App Configuration*|
180+
181+
1. Enable System Assigned Managed Identity of AKS NodePool
182+
183+
Go to the corresponding Virtual Machine Scale Sets resource of AKS, and enable system-assigned managed identity on the Virtual Machine Scale Sets by following this [doc](/azure/active-directory/managed-identities-azure-resources/qs-configure-portal-windows-vmss#enable-system-assigned-managed-identity-on-an-existing-virtual-machine-scale-set).
184+
185+
1. Assign Data Reader role to the System Assigned Managed Identity
186+
187+
Once the system-assigned managed identity has been enabled, you need to grant it read access to Azure AppConfiguration. You can do it by following the instructions in this [doc](/azure/azure-app-configuration/howto-integrate-azure-managed-service-identity?tabs=core5x&pivots=framework-dotnet#grant-access-to-app-configuration).
188+
189+
### Install App Configuration Kubernetes Provider to AKS cluster
190+
1. Get the credential to manage your AKS cluster, replace the `name` and `resource-group` parameters with yours:
191+
```bash
192+
az aks get-credentials --name my_aks --resource-group my_aks_resource_group
193+
```
194+
195+
1. Install Azure App Configuration Kubernetes Provider to your AKS cluster using `helm`:
196+
``` bash
197+
helm install azureappconfiguration.kubernetesprovider \
198+
oci://mcr.microsoft.com/azure-app-configuration/helmchart/kubernetes-provider \
199+
--version 1.0.0-preview --namespace azappconfig-system --create-namespace
200+
```
201+
202+
1. Create *appConfigurationProvider.yaml* with the following YAML content. Replace the value of the `endpoint` field with the endpoint of your Azure AppConfiguration store.
203+
``` yaml
204+
apiVersion: azconfig.io/v1beta1
205+
kind: AzureAppConfigurationProvider
206+
metadata:
207+
name: appconfigurationprovider-sample
208+
spec:
209+
endpoint: https://myappconfig.azconfig.io
210+
target:
211+
configMapName: demo-configmap
212+
```
213+
214+
1. Apply *appConfigurationProvider.yaml* to the AKS cluster.
215+
``` bash
216+
kubectl apply -f ./AKS-AppConfiguration-Demo -n quickstart-appconfig
217+
```
218+
If namespace does not exists, run the following command to create it first.
219+
``` bash
220+
kubectl create namespace quickstart-appconfig
221+
```
222+
223+
### Update application deployment
224+
1. Update the *deployment.yaml* to use the configMap `demo-configmap` as environment variable.
225+
226+
Replace the whole `env` section
227+
``` yaml
228+
env:
229+
- name: Settings__Message
230+
value: "Hello from the environment variable"
231+
- name: Settings__FontColor
232+
value: "Orange"
233+
```
234+
with:
235+
``` yaml
236+
envFrom:
237+
- configMapRef:
238+
name: demo-configmap
239+
```
215240
216-
To check the synchronization status of AppConfigurationProvider, run the following command in your terminal. If the `phase` property in the `status` section of the output is `COMPLETE` , it means that the key-values have been successfully synced from Azure App Configuration.
241+
1. Apply the updated *deployment.yaml* to the AKS cluster
242+
``` bash
243+
kubectl apply -f ./deployment.yaml -n quickstart-appconfig
244+
```
245+
246+
### Reload the application
247+
Refresh the browser, the page shows with updated content.
248+
249+
![Kubernetes Provider after using configMap ](./media/quickstarts/kubernetes-provider-app-launch-after.png)
250+
251+
### Validation and troubleshooting
252+
A configMap *demo-configmap* is supposed to be created in the *quickstart-appconfig* namespace by the Azure App Configuration Kubernetes Provider.
253+
``` bash
254+
kubectl get configmap demo-configmap -n quickstart-appconfig
255+
```
256+
257+
In addition to check the existence of target configMap, you can also check the synchronization status of AppConfigurationProvider, run the following command in your terminal. If the `phase` property in the `status` section of the output is `COMPLETE` , it means that the key-values have been successfully synced from Azure App Configuration.
217258
``` bash
218259
kubectl get AppConfigurationProvider appconfigurationprovider-sample -n quickstart-appconfig -o yaml
219260
```
@@ -223,17 +264,6 @@ kubectl get AppConfigurationProvider appconfigurationprovider-sample -n quicksta
223264
> kubectl logs deployment/az-appconfig-k8s-provider -n azappconfig-system
224265
> ```
225266
>
226-
227-
A configMap *demo-configmap* is being created in the *quickstart-appconfig* namespace
228-
``` bash
229-
kubectl get configmap demo-configmap -n quickstart-appconfig
230-
```
231-
232-
## Validate key-values from Azure App Configuration are affecting the app.
233-
Run the following command and get the External IP that exposed by the LoadBalancer service. Use it to visit the web app, you'll see that the configuration settings from the Azure App Configuration store are affecting the page.
234-
``` bash
235-
kubectl get service configmap-demo-service -n quickstart-appconfig
236-
```
237267
238268
## Clean up resources
239269
1. Remove the resources that have been deployed to AKS

0 commit comments

Comments
 (0)