Skip to content

Commit ec3b2a1

Browse files
Update docs
1 parent b0d87cc commit ec3b2a1

File tree

1 file changed

+45
-51
lines changed

1 file changed

+45
-51
lines changed

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

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,9 @@ metric_relabel_configs:
466466
467467
If you are using `basic_auth` setting in your prometheus configuration, please follow the steps -
468468

469-
Below is an example of creating a secret.
470-
471-
1. Create a secret object 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.
472-
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.
473-
The secret values should be base64 encoded before putting them under the data section.
469+
1. Create a secret in the **kube-system** namespace named **ama-metrics-mtls-secret**
474470

471+
The value for password1 is **base64encoded**
475472
The key *password1* can be anything, but just needs to match your scrapeconfig *password_file* filepath.
476473

477474
```yaml
@@ -500,26 +497,17 @@ Scraping targets using basic auth is currently not supported using pod/service m
500497

501498
---
502499

500+
If you are using both basic auth and tls auth, please refer to the [section](#create-secret-using-yaml-for-both-basic-and-tls-auth) below.
501+
For more details, refer to the [note section](#note-section).
502+
503+
503504
### TLS based scraping
504505

505506
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.
506507
Please follow the below steps.
507508

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-
512-
### [Create secret with command for CRD based scraping](#tab/CommandSecretCRD)
513-
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.
514-
```console
515-
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
516-
```
517-
### [Create secret with command for Configmap based scraping](#tab/CommandSecretConfigmap)
518-
Below is an example command for creating a secret using the TLS self-signed certificate, in case of config map based scraping.
519-
```console
520-
kubectl create secret generic ama-metrics-mtls-secret --from-file=<certfile>=<certfile> --from-file=<keyfile>=<keyfile> -n kube-system
521-
```
522-
### [Create secret using YAML](#tab/YAMLSecret)
509+
1. Create a secret in the kube-system namespace named ama-metrics-mtls-secret. Each key-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. The secret values should be base64 encoded before putting them under the data section, like below.
510+
523511
Below is an example of creating secret through YAML.
524512

525513
```yaml
@@ -534,24 +522,6 @@ Please follow the below steps.
534522
<keyfile>: base64_key_content
535523
```
536524

537-
### [Create secret using YAML for both basic and Tls auth](#tab/YAMLSecretBasicTls)
538-
539-
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.
540-
541-
```yaml
542-
apiVersion: v1
543-
kind: Secret
544-
metadata:
545-
name: ama-metrics-mtls-secret
546-
namespace: kube-system
547-
type: Opaque
548-
data:
549-
certfile: base64_cert_content # used for Tls
550-
keyfile: base64_key_content # used for Tls
551-
password1: base64-encoded-string # used for basic auth
552-
password2: base64-encoded-string # used for basic auth
553-
```yaml
554-
555525
---
556526

557527
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.
@@ -570,27 +540,51 @@ Please follow the below steps.
570540
key_file: /etc/prometheus/certs/<keyfile>
571541
insecure_skip_verify: false
572542
```
543+
573544
### [Scrape Config using CRD(Pod/Service Monitor)](#tab/CRDScrapeConfigTLSAuth)
574545

575546
- To provide the TLS config setting in a CRD(Pod/Service Monitor), please follow the below example.
576547

577548
```yaml
578-
tlsConfig:
579-
ca:
580-
secret:
581-
key: "<certfile>" # since it is self-signed
582-
name: "ama-metrics-mtls-secret"
583-
cert:
584-
secret:
585-
key: "<certfile>"
586-
name: "ama-metrics-mtls-secret"
587-
keySecret:
588-
key: "<keyfile>"
589-
name: "ama-metrics-mtls-secret"
590-
insecureSkipVerify: false
549+
tlsConfig:
550+
ca:
551+
secret:
552+
key: "<certfile>" # since it is self-signed
553+
name: "ama-metrics-mtls-secret"
554+
cert:
555+
secret:
556+
key: "<certfile>"
557+
name: "ama-metrics-mtls-secret"
558+
keySecret:
559+
key: "<keyfile>"
560+
name: "ama-metrics-mtls-secret"
561+
insecureSkipVerify: false
591562
```
592563

593564
---
565+
566+
567+
### Create secret using YAML for both basic and Tls auth
568+
569+
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.
570+
571+
```yaml
572+
573+
apiVersion: v1
574+
kind: Secret
575+
metadata:
576+
name: ama-metrics-mtls-secret
577+
namespace: kube-system
578+
type: Opaque
579+
data:
580+
certfile: base64_cert_content # used for Tls
581+
keyfile: base64_key_content # used for Tls
582+
password1: base64-encoded-string # used for basic auth
583+
password2: base64-encoded-string # used for basic auth
584+
585+
```yaml
586+
587+
<a name="note-section"></a>
594588
> [!NOTE]
595589
>
596590
> 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.

0 commit comments

Comments
 (0)