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
+97-88Lines changed: 97 additions & 88 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,12 +34,14 @@ In this quickstart, you incorporate Azure App Configuration Kubernetes Provider
34
34
## Create an application running in AKS
35
35
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).
36
36
### Create an application
37
-
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 MyWebApp folder:
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:
38
+
38
39
```dotnetcli
39
40
dotnet new webapp --output MyWebApp --framework net6.0
40
41
```
41
42
42
43
1. Open *Index.cshtml* in the Pages directory, and update the content with the following code.
44
+
43
45
``` html
44
46
@page
45
47
@model IndexModel
@@ -59,33 +61,39 @@ In this section, it creates an ASP.NET Core web application that consumes enviro
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
+
64
68
``` dotnetcli
65
69
dotnet publish -c Release -o published
66
70
```
71
+
67
72
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
+
68
74
``` dockerfile
69
75
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime
70
76
WORKDIR /app
71
77
COPY published/ ./
72
78
ENTRYPOINT ["dotnet", "MyWebApp.dll"]
73
79
```
74
-
1. Build the container by running the following command.
80
+
81
+
1. Build a container image named *aspnetapp* by running the following command.
82
+
75
83
``` docker
76
84
docker build --tag aspnetapp .
77
85
```
78
86
79
-
### Push the image to the registry
80
-
1. Run the [az acr login](/cli/azure/acr#az-acr-login) command to log in to the registry.
87
+
### 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.
81
89
82
90
```azurecli
83
91
az acr login --name myregistry
84
92
```
85
93
86
94
The command returns `Login Succeeded` once login is successful.
87
95
88
-
1. Use [docker tag](https://docs.docker.com/engine/reference/commandline/tag/) to tag the image appropriate details.
96
+
1. Use [docker tag](https://docs.docker.com/engine/reference/commandline/tag/) to create a tag *myregistry.azurecr.io/aspnetapp:v1* for the image *aspnetapp*.
89
97
90
98
```docker
91
99
docker tag aspnetapp myregistry.azurecr.io/aspnetapp:v1
@@ -94,197 +102,198 @@ In this section, it creates an ASP.NET Core web application that consumes enviro
94
102
> [!TIP]
95
103
> To review the list of your existing docker images and tags, run `docker image ls`. In this scenario, you should see at least two images: `aspnetapp` and `myregistry.azurecr.io/aspnetapp`.
96
104
97
-
1. Use [docker push](https://docs.docker.com/engine/reference/commandline/push/) to push the image to the container registry. This example creates the *aspnetapp* repository in ACR containing the `aspnetapp` image. In the example below, replace the placeholders `<login-server`, `<image-name>` and `<tag>` by the ACR's log-in server value, the image name and the image tag.
98
-
99
-
Method:
100
-
101
-
```docker
102
-
docker push <login-server>/<image-name>:<tag>
103
-
```
104
-
105
-
Example:
105
+
1. Use [docker push](https://docs.docker.com/engine/reference/commandline/push/) to upload the image to the container registry. For example, the following command pushes the image to a repository named *aspnetapp* with tag *v1* under the registry *myregistry*.
106
106
107
107
```docker
108
108
docker push myregistry.azurecr.io/aspnetapp:v1
109
109
```
110
110
111
-
### Deploy the application and browser it
111
+
### Deploy and visit the application
112
112
1. Create an *AKS-AppConfiguration-Demo* directory in the root directory of your project.
113
113
114
-
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.
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.
115
+
115
116
``` yaml
116
117
apiVersion: apps/v1
117
118
kind: Deployment
118
119
metadata:
119
-
name: demo-deployment
120
+
name: aspnetapp-demo
120
121
labels:
121
-
app: configmap-demo-app
122
+
app: aspnetapp-demo
122
123
spec:
123
124
replicas: 1
124
125
selector:
125
126
matchLabels:
126
-
app: configmap-demo-app
127
+
app: aspnetapp-demo
127
128
template:
128
129
metadata:
129
130
labels:
130
-
app: configmap-demo-app
131
+
app: aspnetapp-demo
131
132
spec:
132
133
containers:
133
-
- name: configmap-demo-app
134
+
- name: aspnetapp
134
135
image: myregistry.azurecr.io/aspnetapp:v1
135
136
ports:
136
137
- containerPort: 80
137
138
env:
138
139
- name: Settings__Message
139
-
value: "Hello from the environment variable"
140
+
value: "Message from the local configuration"
140
141
- name: Settings__FontColor
141
-
value: "Orange"
142
+
value: "Black"
142
143
```
143
-
1. Create *service.yaml* in the *AKS-AppConfiguration-Demo* with the following YAML content.
144
+
145
+
1. Add a *service.yaml* to the *AKS-AppConfiguration-Demo* directory with the following content to create a LoadBalancer service.
146
+
144
147
``` yaml
145
148
apiVersion: v1
146
149
kind: Service
147
150
metadata:
148
-
name: configmap-demo-service
151
+
name: aspnetapp-demo-service
149
152
spec:
150
153
type: LoadBalancer
151
154
ports:
152
155
- port: 80
153
156
selector:
154
-
app: configmap-demo-app
157
+
app: aspnetapp-demo
155
158
```
156
159
157
-
1. Apply the YAML files to the AKS cluster
160
+
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.
168
+
164
169
``` bash
165
-
kubectl get service configmap-demo-service -n quickstart-appconfig
170
+
kubectl get service configmap-demo-service -n appconfig-demo
166
171
```
167
172
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.
173
+
1. Open a browser window, and navigate to the IP address obtained in the previous step. The web page looks like this:
169
174
170
175

171
176
172
177
## Use App Configuration Kubernetes Provider
173
-
### Configure the Azure App Configuration store
178
+
Now that you have an application running in AKS, you will deploy the App Configuration Kubernetes Provider to your AKS cluster running as a Kubernetes controller. The provider will retrieve data from your App Configuration store and create a ConfigMap, which is consumable as environment variables by your application.
179
+
### Setup the Azure App Configuration store
174
180
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).
175
181
176
182
|**Key**|**Value**|
177
183
|---|---|
178
184
|Settings__FontColor|*Green*|
179
185
|Settings__Message|*Hello from Azure App Configuration*|
180
-
181
-
> [!TIP]
182
-
> This step adds the key-values to Azure App Configuration that is supposed to be consumed by the application. We're just using application `MyWebApp` as an example. If you are using your own application, you can add the key-values that are required by your application accordingly.
183
186
184
-
1. Enable System Assigned Managed Identity of AKS NodePool
185
-
186
-
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).
187
+
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.
187
188
188
-
1. Assign Data Reader role to the System Assigned Managed Identity
189
-
190
-
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).
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).
191
190
192
191
### Install App Configuration Kubernetes Provider to AKS cluster
193
-
1. Get the credential to manage your AKS cluster, replace the `name` and `resource-group` parameters with yours:
192
+
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:
193
+
194
194
```bash
195
-
az aks get-credentials --name my_aks --resource-group my_aks_resource_group
195
+
az aks get-credentials --name <your-aks-instance-name> --resource-group <your-aks-resource-group>
196
196
```
197
197
198
198
1. Install Azure App Configuration Kubernetes Provider to your AKS cluster using `helm`:
1. Create *appConfigurationProvider.yaml* with the following YAML content. Replace the value of the `endpoint` field with the endpoint of your Azure AppConfiguration store.
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.
209
+
210
+
Replace the value of the `endpoint` field with the endpoint of your Azure App Configuration store.
211
+
206
212
``` yaml
207
213
apiVersion: azconfig.io/v1beta1
208
214
kind: AzureAppConfigurationProvider
209
215
metadata:
210
216
name: appconfigurationprovider-sample
211
217
spec:
212
-
endpoint: https://myappconfig.azconfig.io
218
+
endpoint: <your-app-configuration-store-endpoint>
213
219
target:
214
220
configMapName: demo-configmap
215
221
```
216
222
217
-
1. Apply *appConfigurationProvider.yaml* to the AKS cluster.
1. Refresh the browser, can see the page has been updated based on the configuration from App Configuration.
246
+
4. Refresh the browser. The page shows updated content.
247
+
248
+

250
249
251
-

250
+
### Troubleshooting
251
+
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
252
253
-
### Validation and troubleshooting
254
-
A configMap *demo-configmap* is supposed to be created in the *quickstart-appconfig* namespace by the Azure App Configuration Kubernetes Provider.
255
253
``` bash
256
-
kubectl get configmap demo-configmap -n quickstart-appconfig
254
+
kubectl get configmap demo-configmap -n appconfig-demo
257
255
```
258
256
259
-
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.
257
+
If the ConfigMap is not created properly, run the following command to get the data retrieval status.
258
+
260
259
```bash
261
-
kubectl get AppConfigurationProvider appconfigurationprovider-sample -n quickstart-appconfig -o yaml
260
+
kubectl get AzureAppConfigurationProvider appconfigurationprovider-sample -n appconfig-demo -o yaml
262
261
```
263
-
> [!TIP]
264
-
> If you see another status is displayed for `phase`, you are presumably confronting some issue. You can run the following command to check what happened with the provider.
If you see the error message in log with information *RESPONSE 403: 403 Forbidden*, it means that the system-assigned managed identity of AKS node pool does not have the permission to access the App Configuration store. You need to grant the permission to the managed identity 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). If you have assigned the permission, you can waitfor up to 15 minutes for the permission to take effect.
263
+
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
+
265
+

266
+
267
+
If the phase is not `COMPLETE`, the data is not downloaded from your App Configuration store properly. Run the following command to show the logs of the Azure App Configuration Kubernetes Provider.
Use the logs for further troubleshooting. For example, if you see requests to your App Configuration store are responded with *RESPONSE 403: 403 Forbidden*, it may indicate the App Configuration Kubernetes Provider doesn't have the necessary permission to access your App Configuration store. Follow the instructions in [Setup the Azure App Configuration store](#setup-the-azure-app-configuration-store) to ensure the managed identity is enabled and it's assigned the proper permission.
271
274
272
275
## Clean up resources
273
-
1. Remove the resources that have been deployed to AKS.
0 commit comments