Skip to content

Commit b0d87cc

Browse files
Add tls and basic auth config in tab instead of note
1 parent 3870a02 commit b0d87cc

File tree

1 file changed

+65
-59
lines changed

1 file changed

+65
-59
lines changed

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

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -508,64 +508,87 @@ Please follow the below steps.
508508
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.
509509
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.
510510
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-
511+
512+
### [Create secret with command for CRD based scraping](#tab/CommandSecretCRD)
512513
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.
513514
```console
514515
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
515516
```
516-
517+
### [Create secret with command for Configmap based scraping](#tab/CommandSecretConfigmap)
517518
Below is an example command for creating a secret using the TLS self-signed certificate, in case of config map based scraping.
518519
```console
519520
kubectl create secret generic ama-metrics-mtls-secret --from-file=<certfile>=<certfile> --from-file=<keyfile>=<keyfile> -n kube-system
520521
```
521-
522-
Below is an example of creating secret through YAML, in case of config map based scraping.
522+
### [Create secret using YAML](#tab/YAMLSecret)
523+
Below is an example of creating secret through YAML.
524+
525+
```yaml
526+
apiVersion: v1
527+
kind: Secret
528+
metadata:
529+
name: ama-metrics-mtls-secret
530+
namespace: kube-system
531+
type: Opaque
532+
data:
533+
<certfile>: base64_cert_content
534+
<keyfile>: base64_key_content
535+
```
536+
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+
555+
---
556+
557+
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.
523558

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

537560
2. Below are the details about how to provide the TLS config settings through a configmap or CRD.
538561

539562
### [Scrape Config using Config File](#tab/ConfigFileScrapeConfigTLSAuth)
540563

541-
- To provide the TLS config setting in a configmap, please follow the below example.
542-
543-
```yaml
544-
tls_config:
545-
ca_file: /etc/prometheus/certs/<certfile> # since it is self-signed
546-
cert_file: /etc/prometheus/certs/<certfile>
547-
key_file: /etc/prometheus/certs/<keyfile>
548-
insecure_skip_verify: false
549-
```
564+
- To provide the TLS config setting in a configmap, please follow the below example.
565+
566+
```yaml
567+
tls_config:
568+
ca_file: /etc/prometheus/certs/<certfile> # since it is self-signed
569+
cert_file: /etc/prometheus/certs/<certfile>
570+
key_file: /etc/prometheus/certs/<keyfile>
571+
insecure_skip_verify: false
572+
```
550573
### [Scrape Config using CRD(Pod/Service Monitor)](#tab/CRDScrapeConfigTLSAuth)
551574

552-
- To provide the TLS config setting in a CRD(Pod/Service Monitor), please follow the below example.
553-
554-
```yaml
555-
tlsConfig:
556-
ca:
557-
secret:
558-
key: "<certfile>" # since it is self-signed
559-
name: "ama-metrics-mtls-secret"
560-
cert:
561-
secret:
562-
key: "<certfile>"
563-
name: "ama-metrics-mtls-secret"
564-
keySecret:
565-
key: "<keyfile>"
566-
name: "ama-metrics-mtls-secret"
567-
insecureSkipVerify: false
568-
```
575+
- To provide the TLS config setting in a CRD(Pod/Service Monitor), please follow the below example.
576+
577+
```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
591+
```
569592

570593
---
571594
> [!NOTE]
@@ -575,23 +598,6 @@ tlsConfig:
575598
> The base64 encoded value is automatically decoded by the agent pods when the secret is mounted as file.
576599
>
577600
> Make sure the secret name is **ama-metrics-mtls-secret** and it is in **kube-system** namespace.
578-
>
579-
> 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.
580-
581-
```yaml
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
593-
```yaml
594-
595601
>
596602
> 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....`
597603
>

0 commit comments

Comments
 (0)