Skip to content

Commit 20232e9

Browse files
Merge pull request #28 from grafana/use_secrets
Add secrets for credentials and endpoints
2 parents f61913d + 043a503 commit 20232e9

File tree

4 files changed

+54
-28
lines changed

4 files changed

+54
-28
lines changed

charts/meta-monitoring/templates/agent/config.yaml

+24-11
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ data:
4040
// Logs
4141
4242
{{- if or .Values.local.logs.enabled .Values.cloud.logs.enabled }}
43+
remote.kubernetes.secret "logs_credentials" {
44+
namespace = "{{- .Values.metaMonitoringNamespace -}}"
45+
name = "logs"
46+
}
47+
4348
loki.source.kubernetes "pods" {
4449
clustering {
4550
enabled = true
@@ -75,6 +80,11 @@ data:
7580
// Metrics
7681
7782
{{- if or .Values.local.metrics.enabled .Values.cloud.metrics.enabled }}
83+
remote.kubernetes.secret "metrics_credentials" {
84+
namespace = "{{- .Values.metaMonitoringNamespace -}}"
85+
name = "metrics"
86+
}
87+
7888
prometheus.scrape "pods" {
7989
clustering {
8090
enabled = true
@@ -210,6 +220,11 @@ data:
210220
// Traces
211221
212222
{{- if or .Values.local.traces.enabled .Values.cloud.traces.enabled }}
223+
remote.kubernetes.secret "traces_credentials" {
224+
namespace = "{{- .Values.metaMonitoringNamespace -}}"
225+
name = "traces"
226+
}
227+
213228
// Shamelessly copied from https://github.com/grafana/intro-to-mlt/blob/main/agent/config.river
214229
otelcol.receiver.otlp "otlp_receiver" {
215230
// We don't technically need this, but it shows how to change listen address and incoming port.
@@ -278,11 +293,10 @@ data:
278293
{{- if .Values.cloud.logs.enabled }}
279294
loki.write "cloud" {
280295
endpoint {
281-
url = "{{- .Values.cloud.logs.endpoint -}}/loki/api/v1/push"
282-
296+
url = nonsensitive(remote.kubernetes.secret.logs_credentials.data["endpoint"])
283297
basic_auth {
284-
username = "{{- .Values.cloud.logs.username -}}"
285-
password = "{{- .Values.cloud.logs.password -}}"
298+
username = nonsensitive(remote.kubernetes.secret.logs_credentials.data["username"])
299+
password = remote.kubernetes.secret.logs_credentials.data["password"]
286300
}
287301
}
288302
}
@@ -291,11 +305,10 @@ data:
291305
{{- if .Values.cloud.metrics.enabled }}
292306
prometheus.remote_write "cloud" {
293307
endpoint {
294-
url = "{{- .Values.cloud.metrics.endpoint -}}/api/prom/push"
295-
308+
url = nonsensitive(remote.kubernetes.secret.metrics_credentials.data["endpoint"])
296309
basic_auth {
297-
username = "{{- .Values.cloud.metrics.username -}}"
298-
password = "{{- .Values.cloud.metrics.password -}}"
310+
username = nonsensitive(remote.kubernetes.secret.metrics_credentials.data["username"])
311+
password = remote.kubernetes.secret.metrics_credentials.data["password"]
299312
}
300313
}
301314
}
@@ -304,13 +317,13 @@ data:
304317
{{- if .Values.cloud.traces.enabled }}
305318
otelcol.exporter.otlp "cloud" {
306319
client {
307-
endpoint = "{{- .Values.cloud.traces.endpoint -}}"
320+
endpoint = nonsensitive(remote.kubernetes.secret.traces_credentials.data["endpoint"])
308321
auth = otelcol.auth.basic.creds.handler
309322
}
310323
}
311324
312325
otelcol.auth.basic "creds" {
313-
username = "{{- .Values.cloud.traces.username -}}"
314-
password = "{{- .Values.cloud.traces.password -}}"
326+
username = nonsensitive(remote.kubernetes.secret.traces_credentials.data["username"])
327+
password = remote.kubernetes.secret.traces_credentials.data["password"]
315328
}
316329
{{- end }}

charts/meta-monitoring/templates/validate.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
{{- end -}}
44

55
{{- if eq .Values.cloud.logs.enabled true -}}
6-
{{- if or (empty .Values.cloud.logs.endpoint) (or (empty .Values.cloud.logs.username) (empty .Values.cloud.logs.password)) -}}
7-
{{- fail "if cloud.logs is enabled then the endpoint, username and password have to be filled in" -}}
6+
{{- if empty .Values.cloud.logs.secret -}}
7+
{{- fail "if cloud.logs is enabled then the secret has to be filled in" -}}
88
{{- end -}}
99
{{- end -}}
1010

1111
{{- if eq .Values.cloud.metrics.enabled true -}}
12-
{{- if or (empty .Values.cloud.metrics.endpoint) (or (empty .Values.cloud.metrics.username) (empty .Values.cloud.metrics.password)) -}}
13-
{{- fail "if cloud.metrics is enabled then the endpoint, username and password have to be filled in" -}}
12+
{{- if empty .Values.cloud.metrics.secret -}}
13+
{{- fail "if cloud.metrics is enabled then the secret has to be filled in" -}}
1414
{{- end -}}
1515
{{- end -}}
1616

1717
{{- if eq .Values.cloud.traces.enabled true -}}
18-
{{- if or (empty .Values.cloud.traces.endpoint) (or (empty .Values.cloud.traces.username) (empty .Values.cloud.traces.password)) -}}
19-
{{- fail "if cloud.traces is enabled then the endpoint, username and password have to be filled in" -}}
18+
{{- if empty .Values.cloud.traces.secret -}}
19+
{{- fail "if cloud.traces is enabled then the secret has to be filled in" -}}
2020
{{- end -}}
2121
{{- end -}}
2222

charts/meta-monitoring/values.yaml

+4-10
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,20 @@ namespacesToMonitor:
55
- tempo
66
# The name of the cluster where this will be installed
77
clusterName: "meta-monitoring"
8-
metaMonitoringNamespace: "mmc"
8+
metaMonitoringNamespace: "meta"
99
lokiNamespace: "loki"
1010

1111
# Set to true to write logs, metrics or traces to Grafana Cloud
1212
cloud:
1313
logs:
1414
enabled: true
15-
endpoint: to_be_changed
16-
username: to_be_changed
17-
password: to_be_changed
15+
secret: ""
1816
metrics:
1917
enabled: true
20-
endpoint: to_be_changed
21-
username: to_be_changed
22-
password: to_be_changed
18+
secret: ""
2319
traces:
2420
enabled: true
25-
endpoint: to_be_changed
26-
username: to_be_changed
27-
password: to_be_changed
21+
secret: ""
2822

2923
# Set to true for a local version of logs, metrics or traces
3024
local:

docs/installation.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,26 @@
66
kubectl create namespace meta
77
```
88

9-
1. Create a values.yaml file based on the [default one](../charts/meta-monitoring/values.yaml).
9+
1. Create secrets with credentials and the endpoint when sending logs, metrics or traces to Grafana Cloud.
10+
11+
```
12+
kubectl create secret generic logs -n meta \
13+
--from-literal=username=<logs username> \
14+
--from-literal=password=<logs password>
15+
--from-literal=endpoint='https://logs-prod-us-central1.grafana.net/loki/api/v1/push'
16+
17+
kubectl create secret generic metrics -n meta \
18+
--from-literal=username=<metrics username> \
19+
--from-literal=password=<metrics password>
20+
--from-literal=endpoint='https://prometheus-us-central1.grafana.net/api/prom/push'
21+
22+
kubectl create secret generic traces -n meta \
23+
--from-literal=username=<traces username> \
24+
--from-literal=password=<traces password>
25+
--from-literal=endpoint='https://tempo-us-central1.grafana.net/tempo'
26+
```
27+
28+
1. Create a values.yaml file based on the [default one](../charts/meta-monitoring/values.yaml). Fill in the names of the secrets created above as needed.
1029

1130
1. Install this helm chart
1231

0 commit comments

Comments
 (0)