Skip to content

Commit fb39d6f

Browse files
Resolve comments
1 parent 5ab6c3b commit fb39d6f

File tree

4 files changed

+97
-88
lines changed

4 files changed

+97
-88
lines changed
182 Bytes
Loading
2.22 KB
Loading
7.42 KB
Loading

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

Lines changed: 97 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ In this quickstart, you incorporate Azure App Configuration Kubernetes Provider
3434
## Create an application running in AKS
3535
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).
3636
### 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+
3839
``` dotnetcli
3940
dotnet new webapp --output MyWebApp --framework net6.0
4041
```
4142
4243
1. Open *Index.cshtml* in the Pages directory, and update the content with the following code.
44+
4345
``` html
4446
@page
4547
@model IndexModel
@@ -59,33 +61,39 @@ In this section, it creates an ASP.NET Core web application that consumes enviro
5961
<h1 class="display-4">@Configuration.GetSection("Settings")["Message"]</h1>
6062
</div>
6163
```
64+
6265
### Containerize the application
6366
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+
6468
``` dotnetcli
6569
dotnet publish -c Release -o published
6670
```
71+
6772
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+
6874
``` dockerfile
6975
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime
7076
WORKDIR /app
7177
COPY published/ ./
7278
ENTRYPOINT ["dotnet", "MyWebApp.dll"]
7379
```
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+
7583
``` docker
7684
docker build --tag aspnetapp .
7785
```
7886

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.
8189

8290
```azurecli
8391
az acr login --name myregistry
8492
```
8593
8694
The command returns `Login Succeeded` once login is successful.
8795
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*.
8997
9098
```docker
9199
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
94102
> [!TIP]
95103
> 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`.
96104
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*.
106106
107107
```docker
108108
docker push myregistry.azurecr.io/aspnetapp:v1
109109
```
110110
111-
### Deploy the application and browser it
111+
### Deploy and visit the application
112112
1. Create an *AKS-AppConfiguration-Demo* directory in the root directory of your project.
113113
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+
115116
``` yaml
116117
apiVersion: apps/v1
117118
kind: Deployment
118119
metadata:
119-
name: demo-deployment
120+
name: aspnetapp-demo
120121
labels:
121-
app: configmap-demo-app
122+
app: aspnetapp-demo
122123
spec:
123124
replicas: 1
124125
selector:
125126
matchLabels:
126-
app: configmap-demo-app
127+
app: aspnetapp-demo
127128
template:
128129
metadata:
129130
labels:
130-
app: configmap-demo-app
131+
app: aspnetapp-demo
131132
spec:
132133
containers:
133-
- name: configmap-demo-app
134+
- name: aspnetapp
134135
image: myregistry.azurecr.io/aspnetapp:v1
135136
ports:
136137
- containerPort: 80
137138
env:
138139
- name: Settings__Message
139-
value: "Hello from the environment variable"
140+
value: "Message from the local configuration"
140141
- name: Settings__FontColor
141-
value: "Orange"
142+
value: "Black"
142143
```
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+
144147
``` yaml
145148
apiVersion: v1
146149
kind: Service
147150
metadata:
148-
name: configmap-demo-service
151+
name: aspnetapp-demo-service
149152
spec:
150153
type: LoadBalancer
151154
ports:
152155
- port: 80
153156
selector:
154-
app: configmap-demo-app
157+
app: aspnetapp-demo
155158
```
156159
157-
1. Apply the YAML files to the AKS cluster
160+
1. Run the following command to deploy the application to the AKS cluster.
161+
158162
``` bash
159-
kubectl create namespace quickstart-appconfig
160-
kubectl apply -f ./AKS-AppConfiguration-Demo -n quickstart-appconfig
163+
kubectl create namespace appconfig-demo
164+
kubectl apply -f ./AKS-AppConfiguration-Demo -n appconfig-demo
161165
```
162166
163167
1. Run the following command and get the External IP that exposed by the LoadBalancer service.
168+
164169
``` bash
165-
kubectl get service configmap-demo-service -n quickstart-appconfig
170+
kubectl get service configmap-demo-service -n appconfig-demo
166171
```
167172
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:
169174
170175
![Kubernetes Provider before using configMap ](./media/quickstarts/kubernetes-provider-app-launch-before.png)
171176
172177
## 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
174180
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).
175181
176182
|**Key**|**Value**|
177183
|---|---|
178184
|Settings__FontColor|*Green*|
179185
|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.
183186
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.
187188
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).
191190
192191
### 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+
194194
```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>
196196
```
197197
198198
1. Install Azure App Configuration Kubernetes Provider to your AKS cluster using `helm`:
199+
199200
``` bash
200201
helm install azureappconfiguration.kubernetesprovider \
201-
oci://mcr.microsoft.com/azure-app-configuration/helmchart/kubernetes-provider \
202-
--version 1.0.0-preview --namespace azappconfig-system --create-namespace
202+
oci://mcr.microsoft.com/azure-app-configuration/helmchart/kubernetes-provider \
203+
--version 1.0.0-preview \
204+
--namespace azappconfig-system \
205+
--create-namespace
203206
```
204207
205-
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+
206212
``` yaml
207213
apiVersion: azconfig.io/v1beta1
208214
kind: AzureAppConfigurationProvider
209215
metadata:
210216
name: appconfigurationprovider-sample
211217
spec:
212-
endpoint: https://myappconfig.azconfig.io
218+
endpoint: <your-app-configuration-store-endpoint>
213219
target:
214220
configMapName: demo-configmap
215221
```
216222
217-
1. Apply *appConfigurationProvider.yaml* to the AKS cluster.
218-
``` bash
219-
kubectl apply -f ./AKS-AppConfiguration-Demo -n quickstart-appconfig
220-
```
221-
If namespace does not exists, run the following command to create it first.
222-
``` bash
223-
kubectl create namespace quickstart-appconfig
224-
```
225-
226-
### Update application deployment
227-
1. Update the *deployment.yaml* to use the configMap `demo-configmap` as environment variable.
223+
2. Update the *deployment.yaml* in *AKS-AppConfiguration-Demo* directory to use the configMap `demo-configmap` as environment variable.
228224
229-
Replace the whole `env` section
225+
Replace the whole `env` section
230226
``` yaml
231227
env:
232228
- name: Settings__Message
233229
value: "Hello from the environment variable"
234230
- name: Settings__FontColor
235231
value: "Orange"
236232
```
237-
with:
233+
with
238234
``` yaml
239235
envFrom:
240236
- configMapRef:
241237
name: demo-configmap
242238
```
243239
244-
1. Apply the updated *deployment.yaml* to the AKS cluster.
240+
3. Run the following command to deploy the `AzureAppConfigurationProvider` resource.
241+
245242
``` bash
246-
kubectl apply -f ./deployment.yaml -n quickstart-appconfig
243+
kubectl apply -f ./AKS-AppConfiguration-Demo -n appconfig-demo
247244
```
248245
249-
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+
![Kubernetes Provider after using configMap](./media/quickstarts/kubernetes-provider-app-launch-after.png)
250249
251-
![Kubernetes Provider after using configMap ](./media/quickstarts/kubernetes-provider-app-launch-after.png)
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.
252252
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.
255253
``` bash
256-
kubectl get configmap demo-configmap -n quickstart-appconfig
254+
kubectl get configmap demo-configmap -n appconfig-demo
257255
```
258256

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+
260259
``` bash
261-
kubectl get AppConfigurationProvider appconfigurationprovider-sample -n quickstart-appconfig -o yaml
260+
kubectl get AzureAppConfigurationProvider appconfigurationprovider-sample -n appconfig-demo -o yaml
262261
```
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.
265-
> ``` bash
266-
> kubectl logs deployment/az-appconfig-k8s-provider -n azappconfig-system
267-
> ```
268-
>
269262

270-
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 wait for 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+
![Kubernetes Provider get provider status](./media/quickstarts/kubernetes-provider-get-provider-status.png)
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.
268+
269+
``` bash
270+
kubectl logs deployment/az-appconfig-k8s-provider -n azappconfig-system
271+
```
272+
273+
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.
271274

272275
## Clean up resources
273-
1. Remove the resources that have been deployed to AKS.
274-
``` bash
275-
kubectl delete -f ./AKS-AppConfiguration-Demo -n quickstart-appconfig
276-
kubectl delete namespace quickstart-appconfig
277-
```
278-
1. Uninstall the Azure App Configuration Kubernetes Provider.
279-
``` bash
280-
helm uninstall azureappconfiguration.kubernetesprovider --namespace azappconfig-system
281-
```
282276

283-
## Next steps
277+
[!INCLUDE[Azure App Configuration cleanup](../../includes/azure-app-configuration-cleanup.md)]
278+
279+
Remove the resources that have been deployed to AKS.
280+
281+
``` bash
282+
kubectl delete -f ./AKS-AppConfiguration-Demo -n appconfig-demo
283+
kubectl delete namespace appconfig-demo
284+
```
285+
286+
Follow the steps below to uninstall the Azure App Configuration Kubernetes Provider from your AKS cluster.
287+
288+
``` bash
289+
helm uninstall azureappconfiguration.kubernetesprovider --namespace azappconfig-system
290+
```
291+
292+
## Summary
284293

285294
In this quickstart, you:
286295

287296
* Provisioned a new App Configuration store.
288-
* Connected to your App Configuration store in Kubernetes using the App Configuration Kubernetes Provider Operator.
289-
* Sync your App Configuration store's key-values to a ConfigMap.
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.
290299
* Displayed a web page in Kubernetes using the settings you configured in your App Configuration store.

0 commit comments

Comments
 (0)