Skip to content

Commit ab85e81

Browse files
make tabs for different mechanisms
1 parent 6b63551 commit ab85e81

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

articles/azure-monitor/containers/prometheus-metrics-scrape-configuration.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -505,17 +505,38 @@ Scraping targets using basic auth is currently not supported using pod/service m
505505
If you have a Prometheus instance served with TLS and you want to scrape metrics from it, you need to set scheme to `https` and set the TLS settings in your configmap or respective CRD.
506506
Please follow the below steps.
507507

508-
1. Create a secret object using the TLS certificate in the **kube-system** namespace named **ama-metrics-mtls-secret**.
508+
1. Create a secret object using the TLS certificate in the **kube-system** namespace named **ama-metrics-mtls-secret**. Inside the secret object , you can specify as many number of secret values under data section and name them how ever you want.
509+
Each secret name-value pair specified in the data section of the secret object will be mounted as a seperate file in this /etc/prometheus/certs location with filename(s) same as key(s) specified in the data section.
510+
The secret values should be base64 encoded before putting them under the data section, in case of creating secret with YAML as shown below.
511+
509512
Below is an example command for creating a secret using the TLS self-signed certificate, in case of CRD based scraping. Please make sure that the secret object is created using the file naming format exactly as in the example below, in case of a CRD based scraping.
510513
```console
511514
kubectl create secret generic ama-metrics-mtls-secret --from-file=secret_kube-system_ama-metrics-mtls-secret_<certfile>=secret_kube-system_ama-metrics-mtls-secret_<certfile> --from-file=secret_kube-system_ama-metrics-mtls-secret_<keyfile>=secret_kube-system_ama-metrics-mtls-secret_<keyfile> -n kube-system
512515
```
513-
Below is an example command for creating a secret using the TLS self-signed certificate, in case of config map based scraping.
516+
517+
Below is an example command for creating a secret using the TLS self-signed certificate, in case of config map based scraping.
514518
```console
515519
kubectl create secret generic ama-metrics-mtls-secret --from-file=<certfile>=<certfile> --from-file=<keyfile>=<keyfile> -n kube-system
516520
```
521+
522+
Below is an example of creating secret through YAML, in case of config map based scraping.
517523

518-
2. Below are the details about how to provide the TLS config settings through a configmap or CRD.
524+
```yaml
525+
apiVersion: v1
526+
kind: Secret
527+
metadata:
528+
name: ama-metrics-mtls-secret
529+
namespace: kube-system
530+
type: Opaque
531+
data:
532+
<certfile>: base64_cert_content
533+
<keyfile>: base64_key_content
534+
```
535+
The **ama-metrics-mtls-secret** secret is mounted on to the ama-metrics containers at path - **/etc/prometheus/certs/** and is made available to the process that is scraping prometheus metrics. The key( ex - certfile) in the above example will be the file name and the value is base64 decoded and added to the contents of the file within the container and the prometheus scraper uses the contents of this file to get the value that is used as the password used to scrape the endpoint.
536+
537+
2. Below are the details about how to provide the TLS config settings through a configmap or CRD.
538+
539+
### [Scrape Config using Config File](#tab/ConfigFileScrapeConfigTLSAuth)
519540

520541
- To provide the TLS config setting in a configmap, please follow the below example.
521542

@@ -527,7 +548,10 @@ tls_config:
527548
insecure_skip_verify: false
528549
```
529550

530-
- To provide the TLS config setting in a configmap, please follow the below example.
551+
---
552+
### [Scrape Config using CRD(Pod/Service Monitor)](#tab/CRDScrapeConfigTLSAuth)
553+
554+
- To provide the TLS config setting in a CRD(Pod/Service Monitor), please follow the below example.
531555

532556
```yaml
533557
tlsConfig:
@@ -545,15 +569,27 @@ tlsConfig:
545569
insecureSkipVerify: false
546570
```
547571

572+
---
548573
> [!NOTE]
549-
>
550-
> Pod and Service monitors currently do not support basic authentication. Support for the same is coming up soon.
551574
>
552575
> The **/etc/prometheus/certs/** path is mandatory, but *password1* can be any string and needs to match the key for the data in the secret created above. This is because the secret **ama-metrics-mtls-secret** is mounted in the path **/etc/prometheus/certs/** within the container.
553576
>
554577
> The base64 encoded value is automatically decoded by the agent pods when the secret is mounted as file.
555578
>
556579
> Make sure the secret name is **ama-metrics-mtls-secret** and it is in **kube-system** namespace.
580+
>
581+
> If you want to use both basic and Tls authentication settings in your configmap/CRD, just make sure that the secret **ama-metrics-mtls-secret** includes all the files(keys) under the data section with their corresponding base 64 encoded values, as shown below.
582+
apiVersion: v1
583+
kind: Secret
584+
metadata:
585+
name: ama-metrics-mtls-secret
586+
namespace: kube-system
587+
type: Opaque
588+
data:
589+
<certfile>: base64_cert_content # used for Tls
590+
<keyfile>: base64_key_content # used for Tls
591+
password1: <base64-encoded-string> # used for basic auth
592+
password2: <base64-encoded-string> # used for basic auth
557593
>
558594
> The secret should be created and then the configmap/CRD should be created in kube-system namespace. The order of secret creation matters. When there's no secret but a valid CRD/config map, you will find errors in collector log -> `no file found for cert....`
559595
>

0 commit comments

Comments
 (0)