Skip to content

Commit e01c573

Browse files
authored
Added DNS role assignment and updated placeholders
1 parent 3fee4a7 commit e01c573

File tree

1 file changed

+61
-37
lines changed

1 file changed

+61
-37
lines changed

articles/aks/web-app-routing.md

Lines changed: 61 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ az extension update --name aks-preview
4646

4747
### Create and export a self-signed SSL certificate (if you don't already own one)
4848

49-
If you already have an SSL certificate, you can skip this step, otherwise you can use these commands to create a self-signed SSL certificate to use with the Ingress. You will need to replace `<YOUR HOSTNAME>` with the DNS name that you will be using.
49+
If you already have an SSL certificate, you can skip this step, otherwise you can use these commands to create a self-signed SSL certificate to use with the Ingress. You will need to replace *`<Hostname>`* with the DNS name that you will be using.
5050

5151
```bash
5252
# Create a self-signed SSL certificate
53-
openssl req -new -x509 -nodes -out aks-ingress-tls.crt -keyout aks-ingress-tls.key -subj "/CN=<YOUR HOSTNAME>" -addext "subjectAltName=DNS:<YOUR HOSTNAME>"
53+
openssl req -new -x509 -nodes -out aks-ingress-tls.crt -keyout aks-ingress-tls.key -subj "/CN=<Hostname>" -addext "subjectAltName=DNS:<Hostname>"
5454

5555
# Export the SSL certificate, skipping the password prompt
5656
openssl pkcs12 -export -in aks-ingress-tls.crt -inkey aks-ingress-tls.key -out aks-ingress-tls.pfx
@@ -61,15 +61,15 @@ openssl pkcs12 -export -in aks-ingress-tls.crt -inkey aks-ingress-tls.key -out a
6161
If you don't already have an Azure Key Vault, use this command to create one. Azure Key Vault is used to securely store the SSL certificates that will be loaded into the Ingress.
6262

6363
```azurecli-interactive
64-
az keyvault create -g <RESOURCE GROUP NAME> -l <LOCATION> -n <KEYVAULT NAME>
64+
az keyvault create -g <ResourceGroupName> -l <Location> -n <KeyVaultName>
6565
```
6666

6767
### Import certificate to Azure Key Vault
6868

6969
Import the SSL certificate into Azure Key Vault.
7070

7171
```azurecli-interactive
72-
az keyvault certificate import --vault-name <KEYVAULT NAME> -n <KEYVAULT CERTIFICATE NAME> -f aks-ingress-tls.pfx
72+
az keyvault certificate import --vault-name <KeyVaultName> -n <KeyVaultCertificateName> -f aks-ingress-tls.pfx
7373
```
7474

7575
### Create an Azure DNS zone (optional)
@@ -78,7 +78,7 @@ If you want the add-on to automatically managed creating hostnames, you need to
7878

7979
```azurecli-interactive
8080
# Create a DNS zone
81-
az network dns zone create -g <RESOURCE GROUP NAME> -n <ZONE NAME ex: contoso.com>
81+
az network dns zone create -g <ResourceGroupName> -n <ZoneName>
8282
```
8383

8484
## Enable Web Application Routing via the Azure CLI
@@ -95,13 +95,13 @@ The following additional add-ons are required:
9595
> To enable the add-on to reload certificates from Azure Key Vault when they change, you should to enable the [secret autorotation feature](/azure/aks/csi-secrets-store-driver#enable-and-disable-autorotation) of the Secret Store CSI driver with the `--enable-secret-rotation` argument. When the autorotation is enabled, the driver updates the pod mount and the Kubernetes secret by polling for changes periodically, based on the rotation poll interval you can define. The default rotation poll interval is 2 minutes.
9696
9797
```azurecli-interactive
98-
az aks create --resource-group myResourceGroup --name myAKSCluster --enable-addons azure-keyvault-secrets-provider,open-service-mesh,web_application_routing --generate-ssh-keys --enable-secret-rotation
98+
az aks create -g <ResourceGroupName> -n <ClusterName> -l <Location> --enable-addons azure-keyvault-secrets-provider,open-service-mesh,web_application_routing --generate-ssh-keys --enable-secret-rotation
9999
```
100100

101101
To enable Web Application Routing on an existing cluster, add the `--addons` parameter and specify *web_application_routing* as shown in the following example:
102102

103103
```azurecli-interactive
104-
az aks enable-addons --resource-group myResourceGroup --name myAKSCluster --addons azure-keyvault-secrets-provider,open-service-mesh,web_application_routing --enable-secret-rotation
104+
az aks enable-addons -g <ResourceGroupName> -n <ClusterName> --addons azure-keyvault-secrets-provider,open-service-mesh,web_application_routing --enable-secret-rotation
105105
```
106106

107107
> [!NOTE]
@@ -117,36 +117,26 @@ The following additional add-on is required:
117117
> To enable the add-on to reload certificates from Azure Key Vault when they change, you should to enable the [secret autorotation feature](/azure/aks/csi-secrets-store-driver#enable-and-disable-autorotation) of the Secret Store CSI driver with the `--enable-secret-rotation` argument. When the autorotation is enabled, the driver updates the pod mount and the Kubernetes secret by polling for changes periodically, based on the rotation poll interval you can define. The default rotation poll interval is 2 minutes.
118118
119119
```azurecli-interactive
120-
az aks create --resource-group myResourceGroup --name myAKSCluster --enable-addons azure-keyvault-secrets-provider,web_application_routing --generate-ssh-keys --enable-secret-rotation
120+
az aks create -g <ResourceGroupName> -n <ClusterName> -l <Location> --enable-addons azure-keyvault-secrets-provider,web_application_routing --generate-ssh-keys --enable-secret-rotation
121121
```
122122

123123
To enable Web Application Routing on an existing cluster, add the `--addons` parameter and specify *web_application_routing* as shown in the following example:
124124

125125
```azurecli-interactive
126-
az aks enable-addons --resource-group myResourceGroup --name myAKSCluster --addons azure-keyvault-secrets-provider,web_application_routing --enable-secret-rotation
126+
az aks enable-addons-g <ResourceGroupName> -n <ClusterName> --addons azure-keyvault-secrets-provider,web_application_routing --enable-secret-rotation
127127
```
128128

129129
---
130130

131-
> [!TIP]
132-
> If you are going to use Azure DNS, update the add-on to pass in the `--dns-zone-resource-id`
131+
## Retrieve the add-on's managed identity object ID
133132

134-
```azurecli-interactive
135-
# Retrieve the resource ID
136-
ZONEID=$(az network dns zone show --vault-name <KEYVAULT NAME> --name <ZONE NAME> -o jsonc | jq .id)
137-
138-
# Update the add-on
139-
az aks addon update --resource-group myResourceGroup --name myAKSCluster --addon web_application_routing --dns-zone-resource-id=$ZONEID`
140-
```
141-
142-
## Grant the add-on permissions to retrieve certficates from Azure Key Vault
143-
The Web Application Routing add-on creates a user created managed identity in the cluster resource group. This managed identity will need to be granted permissions to retrieve SSL certificates from the Azure Key Vault. Provide your `<RESOURCE GROUP NAME>`, `<CLUSTER NAME>`, and `<LOCATION>` in the script below which will retrieve the managed identity's object ID.
133+
Retrieve user managed identity object ID for the add-on. This will be used in the next steps to grant permissions against the Azure DNS zone and the Azure Key Vault. Provide your *`<ResourceGroupName>`*, *`<ClusterName>`*, and *`<Location>`* in the script below which will retrieve the managed identity's object ID.
144134

145135
```azurecli-interactive
146136
# Provide values for your environment
147-
RGNAME=<RESOURCE GROUP NAME>
148-
CLUSTERNAME=<CLUSTER NAME>
149-
LOCATION=<LOCATION>
137+
RGNAME=<ResourceGroupName>
138+
CLUSTERNAME=<ClusterName>
139+
LOCATION=<Location>
150140
151141
# Retrieve user managed identity object ID for the add-on
152142
SUBSCRIPTION_ID=$(az account show --query id --output tsv)
@@ -156,9 +146,37 @@ USERMANAGEDIDENTITY_RESOURCEID="/subscriptions/${SUBSCRIPTION_ID}/resourceGroups
156146
MANAGEDIDENTITY_OBJECTID=$(az resource show --id $USERMANAGEDIDENTITY_RESOURCEID --query "properties.principalId" -o tsv | tr -d '[:space:]')
157147
```
158148

149+
## Configure the add-on to use Azure DNS to manage creating DNS zones
150+
151+
If you are going to use Azure DNS, update the add-on to pass in the `--dns-zone-resource-id`.
152+
153+
Retrieve the resource ID for the DNS zone.
154+
155+
```azurecli-interactive
156+
# Retrieve the resource ID
157+
ZONEID=$(az network dns zone show -g <ResourceGroupName> -n <ZoneName> --query "id" --output tsv)
158+
```
159+
160+
Grant **DNS Zone Contributor** permissions on the DNS zone to the add-on's managed identity.
161+
162+
```azureclie-interactive
163+
az role assignment create --role "DNS Zone Contributor" --assignee $MANAGEDIDENTITY_OBJECTID --scope $ZONEID
164+
```
165+
166+
Update the add-on to enable the integration with Azure DNS. This will create the **external-dns** controller.
167+
168+
```azureclie-interactive
169+
az aks addon update -g <ResourceGroupName> -n <ClusterName> --addon web_application_routing --dns-zone-resource-id=$ZONEID
170+
```
171+
172+
173+
174+
## Grant the add-on permissions to retrieve certficates from Azure Key Vault
175+
The Web Application Routing add-on creates a user created managed identity in the cluster resource group. This managed identity will need to be granted permissions to retrieve SSL certificates from the Azure Key Vault.
176+
159177
Grant `GET` permissions for the Web Application Routing add-on to retrieve certificates from Azure Key Vault:
160178
```azurecli-interactive
161-
az keyvault set-policy --name $KEYVAULTNAME --object-id $MANAGEDIDENTITY_OBJECTID --secret-permissions get --certificate-permissions get
179+
az keyvault set-policy --name <KeyVaultName> --object-id $MANAGEDIDENTITY_OBJECTID --secret-permissions get --certificate-permissions get
162180
```
163181

164182
## Connect to your AKS cluster
@@ -174,9 +192,9 @@ az aks install-cli
174192
To configure `kubectl` to connect to your Kubernetes cluster, use the [az aks get-credentials][az-aks-get-credentials] command. The following example gets credentials for the AKS cluster named *myAKSCluster* in *myResourceGroup*:
175193

176194
```azurecli-interactive
177-
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
195+
az aks get-credentials -g <ResourceGroupName> -n <ClusterName>
178196
```
179-
## Deploying an application that uses Web Application Routing
197+
## Deploy an application
180198

181199
Web Application Routing uses annotations on Kubernetes Ingress objects to create the appropriate resources, create records on Azure DNS (when configured), and retrieve the SSL certificates from Azure Key Vault.
182200

@@ -247,17 +265,20 @@ spec:
247265
The Web Application Routing add-on creates an Ingress class on the cluster called `webapprouting.kubernetes.azure.com `. When you create an ingress object with this class, this will activate the add-on. To obtain the certificate URI to use in the Ingress from Azure Key Vault, run the following command.
248266

249267
```azurecli-interactive
250-
az keyvault certificate show --vault-name <KEYVAULT NAME> --name <KEYVAULT-CERTIFICATE-NAME> -o jsonc | jq .id
268+
az keyvault certificate show --vault-name <KeyVaultName> -n <KeyVaultCertificateName> ---query "id" --output tsv
251269
```
252270

253-
Create a file named **ingress.yaml** and copy in the following YAML. Update `<MY_HOSTNAME>` with your DNS host name and `<MY_KEYVAULT_CERTIFICATE_URI>` with the ID returned from Azure Key Vault.
271+
Create a file named **ingress.yaml** and copy in the following YAML.
272+
273+
> [!NOTE]
274+
> Update *`<Hostname>`* with your DNS host name and *`<KeyVaultCertificateUri>`* with the ID returned from Azure Key Vault. `secretName` is the name of the secret that going to be generated to store the certificate. This is the certificate that's going to be presented in the browser.
254275

255276
```yaml
256277
apiVersion: networking.k8s.io/v1
257278
kind: Ingress
258279
metadata:
259280
annotations:
260-
kubernetes.azure.com/tls-cert-keyvault-uri: <MY_KEYVAULT_CERTIFICATE_URI>
281+
kubernetes.azure.com/tls-cert-keyvault-uri: <KeyVaultCertificateUri>
261282
kubernetes.azure.com/use-osm-mtls: "true"
262283
nginx.ingress.kubernetes.io/backend-protocol: HTTPS
263284
nginx.ingress.kubernetes.io/configuration-snippet: |2-
@@ -270,7 +291,7 @@ metadata:
270291
spec:
271292
ingressClassName: webapprouting.kubernetes.azure.com
272293
rules:
273-
- host: <MY_HOSTNAME>
294+
- host: <Hostname>
274295
http:
275296
paths:
276297
- backend:
@@ -282,7 +303,7 @@ spec:
282303
pathType: Prefix
283304
tls:
284305
- hosts:
285-
- <MY_HOSTNAME>
306+
- <Hostname>
286307
secretName: keyvault-aks-helloworld
287308
```
288309

@@ -395,23 +416,26 @@ spec:
395416
The Web Application Routing add-on creates an Ingress class on the cluster called `webapprouting.kubernetes.azure.com `. When you create an ingress object with this class, this will activate the add-on. To obtain the certificate URI to use in the Ingress from Azure Key Vault, run the following command.
396417

397418
```azurecli-interactive
398-
az keyvault certificate show --vault-name <KEYVAULT NAME> --name <KEYVAULT-CERTIFICATE-NAME> -o jsonc | jq .id
419+
az keyvault certificate show --vault-name <KeyVaultName> -n <KeyVaultCertificateName> ---query "id" --output tsv
399420
```
400421

401-
Create a file named **ingress.yaml** and copy in the following YAML. Update `<MY_HOSTNAME>` with your DNS host name and `<MY_KEYVAULT_CERTIFICATE_URI>` with the ID returned from Azure Key Vault.
422+
Create a file named **ingress.yaml** and copy in the following YAML.
423+
424+
> [!NOTE]
425+
> Update *`<Hostname>`* with your DNS host name and *`<KeyVaultCertificateUri>`* with the ID returned from Azure Key Vault. `secretName` is the name of the secret that going to be generated to store the certificate. This is the certificate that's going to be presented in the browser.
402426

403427
```yaml
404428
apiVersion: networking.k8s.io/v1
405429
kind: Ingress
406430
metadata:
407431
annotations:
408-
kubernetes.azure.com/tls-cert-keyvault-uri: <MY_KEYVAULT_CERTIFICATE_URI>
432+
kubernetes.azure.com/tls-cert-keyvault-uri: <KeyVaultCertificateUri>
409433
name: aks-helloworld
410434
namespace: hello-web-app-routing
411435
spec:
412436
ingressClassName: webapprouting.kubernetes.azure.com
413437
rules:
414-
- host: helloworld.aks.azure.sabbour.me
438+
- host: <Hostname>
415439
http:
416440
paths:
417441
- backend:
@@ -423,7 +447,7 @@ spec:
423447
pathType: Prefix
424448
tls:
425449
- hosts:
426-
- helloworld.aks.azure.sabbour.me
450+
- <Hostname>
427451
secretName: keyvault-aks-helloworld
428452
```
429453

0 commit comments

Comments
 (0)