Skip to content

Commit 36d2dd2

Browse files
Merge pull request #227706 from Sohamdg081992/AddAzurePolicyDocumentation
Add doc for enabling prometheus addon through policy
2 parents 89a3a40 + 528823d commit 36d2dd2

File tree

1 file changed

+48
-13
lines changed

1 file changed

+48
-13
lines changed

articles/azure-monitor/essentials/prometheus-metrics-enable.md

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ Use `az aks update` with the `-enable-azuremonitormetrics` option to install the
5151

5252
**Create a new default Azure Monitor workspace.**<br>
5353
If no Azure Monitor Workspace is specified, then a default Azure Monitor Workspace will be created in the `DefaultRG-<cluster_region>` following the format `DefaultAzureMonitorWorkspace-<mapped_region>`.
54-
This Azure Monitor Workspace will be in the region specific in [Region mappings](#region-mappings).
54+
This Azure Monitor Workspace is in the region specific in [Region mappings](#region-mappings).
5555

5656
```azurecli
5757
az aks update --enable-azuremonitormetrics -n <cluster-name> -g <cluster-resource-group>
5858
```
5959

6060
**Use an existing Azure Monitor workspace.**<br>
61-
If the Azure Monitor workspace is linked to one or more Grafana workspaces, then the data will be available in Grafana.
61+
If the Azure Monitor workspace is linked to one or more Grafana workspaces, then the data is available in Grafana.
6262

6363
```azurecli
6464
az aks update --enable-azuremonitormetrics -n <cluster-name> -g <cluster-resource-group> --azure-monitor-workspace-resource-id <workspace-name-resource-id>
@@ -71,7 +71,7 @@ This creates a link between the Azure Monitor workspace and the Grafana workspac
7171
az aks update --enable-azuremonitormetrics -n <cluster-name> -g <cluster-resource-group> --azure-monitor-workspace-resource-id <azure-monitor-workspace-name-resource-id> --grafana-resource-id <grafana-workspace-name-resource-id>
7272
```
7373

74-
The output for each command will look similar to the following:
74+
The output for each command looks similar to the following:
7575

7676
```json
7777
"azureMonitorProfile": {
@@ -88,16 +88,16 @@ The output for each command will look similar to the following:
8888
#### Optional parameters
8989
Following are optional parameters that you can use with the previous commands.
9090

91-
- `--ksm-metric-annotations-allow-list` is a comma-separated list of Kubernetes annotations keys that will be used in the resource's labels metric. By default the metric contains only name and namespace labels. To include additional annotations provide a list of resource names in their plural form and Kubernetes annotation keys, you would like to allow for them. A single `*` can be provided per resource instead to allow any annotations, but that has severe performance implications.
92-
- `--ksm-metric-labels-allow-list` is a comma-separated list of additional Kubernetes label keys that will be used in the resource's labels metric. By default the metric contains only name and namespace labels. To include additional labels provide a list of resource names in their plural form and Kubernetes label keys you would like to allow for them. A single `*` can be provided per resource instead to allow any labels, but that has severe performance implications.
91+
- `--ksm-metric-annotations-allow-list` is a comma-separated list of Kubernetes annotations keys that will be used in the resource's labels metric. By default the metric contains only name and namespace labels. To include more annotations provide a list of resource names in their plural form and Kubernetes annotation keys, you would like to allow for them. A single `*` can be provided per resource instead to allow any annotations, but that has severe performance implications.
92+
- `--ksm-metric-labels-allow-list` is a comma-separated list of more Kubernetes label keys that will be used in the resource's labels metric. By default the metric contains only name and namespace labels. To include more labels provide a list of resource names in their plural form and Kubernetes label keys, you would like to allow for them. A single `*` can be provided per resource instead to allow any labels, but that has severe performance implications.
9393

9494
**Use annotations and labels.**
9595

9696
```azurecli
9797
az aks update --enable-azuremonitormetrics -n <cluster-name> -g <cluster-resource-group> --ksm-metric-labels-allow-list "namespaces=[k8s-label-1,k8s-label-n]" --ksm-metric-annotations-allow-list "pods=[k8s-annotation-1,k8s-annotation-n]"
9898
```
9999

100-
The output will be similar to the following:
100+
The output is similar to the following:
101101

102102
```json
103103
"azureMonitorProfile": {
@@ -125,7 +125,7 @@ The output will be similar to the following:
125125
### Retrieve required values for Grafana resource
126126
From the **Overview** page for the Azure Managed Grafana instance in the Azure portal, select **JSON view**.
127127

128-
If you're using an existing Azure Managed Grafana instance that already has been linked to an Azure Monitor workspace then you need the list of Grafana integrations. Copy the value of the `azureMonitorWorkspaceIntegrations` field. If it doesn't exist, then the instance hasn't been linked with any Azure Monitor workspace.
128+
If you're using an existing Azure Managed Grafana instance that already has been linked to an Azure Monitor workspace, then you need the list of Grafana integrations. Copy the value of the `azureMonitorWorkspaceIntegrations` field. If it doesn't exist, then the instance hasn't been linked with any Azure Monitor workspace.
129129

130130
```json
131131
"properties": {
@@ -155,13 +155,13 @@ If you're using an existing Azure Managed Grafana instance that already has been
155155
| `clusterResourceId` | Resource ID for the AKS cluster. Retrieve from the **JSON view** on the **Overview** page for the cluster. |
156156
| `clusterLocation` | Location of the AKS cluster. Retrieve from the **JSON view** on the **Overview** page for the cluster. |
157157
| `metricLabelsAllowlist` | Comma-separated list of Kubernetes labels keys that will be used in the resource's labels metric. |
158-
| `metricAnnotationsAllowList` | Comma-separated list of additional Kubernetes label keys that will be used in the resource's labels metric. |
158+
| `metricAnnotationsAllowList` | Comma-separated list of more Kubernetes label keys that will be used in the resource's labels metric. |
159159
| `grafanaResourceId` | Resource ID for the managed Grafana instance. Retrieve from the **JSON view** on the **Overview** page for the Grafana instance. |
160160
| `grafanaLocation` | Location for the managed Grafana instance. Retrieve from the **JSON view** on the **Overview** page for the Grafana instance. |
161161
| `grafanaSku` | SKU for the managed Grafana instance. Retrieve from the **JSON view** on the **Overview** page for the Grafana instance. Use the **sku.name**. |
162162

163163

164-
4. Open the template file and update the `grafanaIntegrations` property at the end of the file with the values that you retrieved from the Grafana instance. This will be similar to the following:
164+
4. Open the template file and update the `grafanaIntegrations` property at the end of the file with the values that you retrieved from the Grafana instance. This is similar to the following:
165165

166166
```json
167167
{
@@ -210,7 +210,7 @@ Currently in bicep, there is no way to explicitly "scope" the Monitoring Data Re
210210

211211
From the **Overview** page for the Azure Managed Grafana instance in the Azure portal, select **JSON view**.
212212

213-
If you're using an existing Azure Managed Grafana instance that already has been linked to an Azure Monitor workspace then you need the list of Grafana integrations. Copy the value of the `azureMonitorWorkspaceIntegrations` field. If it doesn't exist, then the instance hasn't been linked with any Azure Monitor workspace.
213+
If you're using an existing Azure Managed Grafana instance that already has been linked to an Azure Monitor workspace, then you need the list of Grafana integrations. Copy the value of the `azureMonitorWorkspaceIntegrations` field. If it doesn't exist, then the instance hasn't been linked with any Azure Monitor workspace.
214214

215215
```json
216216
"properties": {
@@ -233,7 +233,7 @@ If you're using an existing Azure Managed Grafana instance that already has been
233233
2. Download the parameter file from [here](https://aka.ms/azureprometheus-enable-bicep-template-parameters) and save it as **FullAzureMonitorMetricsProfileParameters.json** in the same directory as the main bicep template.
234234
3. Download the [nested_azuremonitormetrics_dcra_clusterResourceId.bicep](https://aka.ms/nested_azuremonitormetrics_dcra_clusterResourceId) and [nested_azuremonitormetrics_profile_clusterResourceId.bicep](https://aka.ms/nested_azuremonitormetrics_profile_clusterResourceId) files in the same directory as the main bicep template.
235235
4. Edit the values in the parameter file.
236-
5. The main bicep template creates all the required resources and uses 2 modules for creating the dcra and monitormetrics profile resources from the other two bicep files.
236+
5. The main bicep template creates all the required resources and uses two modules for creating the dcra and monitormetrics profile resources from the other two bicep files.
237237

238238
| Parameter | Value |
239239
|:---|:---|
@@ -242,13 +242,13 @@ If you're using an existing Azure Managed Grafana instance that already has been
242242
| `clusterResourceId` | Resource ID for the AKS cluster. Retrieve from the **JSON view** on the **Overview** page for the cluster. |
243243
| `clusterLocation` | Location of the AKS cluster. Retrieve from the **JSON view** on the **Overview** page for the cluster. |
244244
| `metricLabelsAllowlist` | Comma-separated list of Kubernetes labels keys that will be used in the resource's labels metric. |
245-
| `metricAnnotationsAllowList` | Comma-separated list of additional Kubernetes label keys that will be used in the resource's labels metric. |
245+
| `metricAnnotationsAllowList` | Comma-separated list of more Kubernetes label keys that will be used in the resource's labels metric. |
246246
| `grafanaResourceId` | Resource ID for the managed Grafana instance. Retrieve from the **JSON view** on the **Overview** page for the Grafana instance. |
247247
| `grafanaLocation` | Location for the managed Grafana instance. Retrieve from the **JSON view** on the **Overview** page for the Grafana instance. |
248248
| `grafanaSku` | SKU for the managed Grafana instance. Retrieve from the **JSON view** on the **Overview** page for the Grafana instance. Use the **sku.name**. |
249249

250250

251-
6. Open the template file and update the `grafanaIntegrations` property at the end of the file with the values that you retrieved from the Grafana instance. This will be similar to the following:
251+
6. Open the template file and update the `grafanaIntegrations` property at the end of the file with the values that you retrieved from the Grafana instance. This is similar to the following:
252252

253253
```json
254254
{
@@ -280,6 +280,41 @@ In this json, `full_resource_id_1` and `full_resource_id_2` were already in the
280280

281281
The final `azureMonitorWorkspaceResourceId` entry is already in the template and is used to link to the Azure Monitor Workspace resource ID provided in the parameters file.
282282

283+
## [Azure Policy](#tab/azurepolicy)
284+
285+
### Prerequisites
286+
287+
- Register the `AKS-PrometheusAddonPreview` feature flag in the Azure Kubernetes clusters subscription with the following command in Azure CLI: `az feature register --namespace Microsoft.ContainerService --name AKS-PrometheusAddonPreview`.
288+
- The Azure Monitor workspace and Azure Managed Grafana workspace must already be created.
289+
290+
### Download Azure policy rules and parameters and deploy
291+
292+
1. Download the main Azure policy rules template from [here](https://aka.ms/AddonPolicyMetricsProfile) and save it as **AddonPolicyMetricsProfile.rules.json**.
293+
2. Download the parameter file from [here](https://aka.ms/AddonPolicyMetricsProfile.parameters) and save it as **AddonPolicyMetricsProfile.parameters.json** in the same directory as the rules template.
294+
3. Create the policy definition using a command like : `az policy definition create --name "(Preview) Prometheus Metrics addon" --display-name "(Preview) Prometheus Metrics addon" --mode Indexed --metadata version=1.0.0 category=Kubernetes --rules .\AddonPolicyMetricsProfile.rules.json --params .\AddonPolicyMetricsProfile.parameters.json`
295+
4. After creating the policy definition, go to Azure portal -> Policy -> Definitions and select the Policy definition you created.
296+
5. Click on 'Assign' and then go to the 'Parameters' tab and fill in the details. Then click 'Review + Create'.
297+
6. Now that the policy is assigned to the subscription, whenever you create a new cluster, which does not have Prometheus enabled, the policy will run and deploy the resources. If you want to apply the policy to existing AKS cluster, create a 'Remediation task' for that AKS cluster resource after going to the 'Policy Assignment'.
298+
7. Now you should see metrics flowing in the existing linked Grafana resource, which is linked with the corresponding Azure Monitor Workspace.
299+
300+
In case you create a new Managed Grafana resource from Azure portal, please link it with the corresponding Azure Monitor Workspace from the 'Linked Grafana Workspaces' tab of the relevant Azure Monitor Workspace page. Please assign the role 'Monitoring Data Reader' to the Grafana MSI on the Azure Monitor Workspace resource so that it can read data for displaying the charts, using the instructions below.
301+
302+
1. From the **Overview** page for the Azure Managed Grafana instance in the Azure portal, select **JSON view**.
303+
304+
2. Copy the value of the `principalId` field for the `SystemAssigned` identity.
305+
306+
```json
307+
"identity": {
308+
"principalId": "00000000-0000-0000-0000-000000000000",
309+
"tenantId": "00000000-0000-0000-0000-000000000000",
310+
"type": "SystemAssigned"
311+
},
312+
```
313+
3. From the **Access control (IAM)** page for the Azure Managed Grafana instance in the Azure portal, select **Add** and then **Add role assignment**.
314+
4. Select `Monitoring Data Reader`.
315+
5. Select **Managed identity** and then **Select members**.
316+
6. Select the **system-assigned managed identity** with the `principalId` from the Grafana resource.
317+
7. Click **Select** and then **Review+assign**.
283318

284319
### Deploy template
285320

0 commit comments

Comments
 (0)