Skip to content

Commit b813c22

Browse files
committed
tls
1 parent 2293b6f commit b813c22

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

templates/prometheus-collector/deployment.yaml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{{- if .Values.prometheusCollector.enabled }}
2+
{{- $tlsEnabled := .Values.prometheusCollector.tls.enabled }}
3+
{{- $basicAuthEnabled := .Values.prometheusCollector.basicAuth.enabled }}
4+
{{- $webConfigEnabled := or $tlsEnabled $basicAuthEnabled }}
25
apiVersion: apps/v1
36
kind: Deployment
47
metadata:
@@ -33,7 +36,7 @@ spec:
3336
- "--web.enable-lifecycle"
3437
- "--storage.tsdb.retention.time={{ .Values.prometheusCollector.retention.time }}"
3538
- "--storage.tsdb.retention.size={{ .Values.prometheusCollector.retention.size }}"
36-
{{- if .Values.prometheusCollector.basicAuth.enabled }}
39+
{{- if $webConfigEnabled }}
3740
- "--web.config.file=/etc/prometheus-web/web.yml"
3841
{{- end }}
3942
ports:
@@ -49,21 +52,47 @@ spec:
4952
mountPath: /etc/prometheus
5053
- name: storage
5154
mountPath: /prometheus
52-
{{- if .Values.prometheusCollector.basicAuth.enabled }}
55+
{{- if $webConfigEnabled }}
5356
- name: web-config
5457
mountPath: /etc/prometheus-web
5558
readOnly: true
5659
{{- end }}
5760
livenessProbe:
61+
{{- if or $tlsEnabled $basicAuthEnabled }}
62+
exec:
63+
command:
64+
- /bin/sh
65+
- -c
66+
- |
67+
{{- if $basicAuthEnabled }}
68+
wget -q --spider {{ if $tlsEnabled }}--no-check-certificate https{{ else }}http{{ end }}://{{ .Values.prometheusCollector.basicAuth.username }}:$(cat /etc/prometheus-web/password)@localhost:{{ .Values.prometheusCollector.port }}/-/healthy
69+
{{- else }}
70+
wget -q --spider --no-check-certificate https://localhost:{{ .Values.prometheusCollector.port }}/-/healthy
71+
{{- end }}
72+
{{- else }}
5873
httpGet:
5974
path: /-/healthy
6075
port: prometheus
76+
{{- end }}
6177
initialDelaySeconds: 30
6278
periodSeconds: 15
6379
readinessProbe:
80+
{{- if or $tlsEnabled $basicAuthEnabled }}
81+
exec:
82+
command:
83+
- /bin/sh
84+
- -c
85+
- |
86+
{{- if $basicAuthEnabled }}
87+
wget -q --spider {{ if $tlsEnabled }}--no-check-certificate https{{ else }}http{{ end }}://{{ .Values.prometheusCollector.basicAuth.username }}:$(cat /etc/prometheus-web/password)@localhost:{{ .Values.prometheusCollector.port }}/-/ready
88+
{{- else }}
89+
wget -q --spider --no-check-certificate https://localhost:{{ .Values.prometheusCollector.port }}/-/ready
90+
{{- end }}
91+
{{- else }}
6492
httpGet:
6593
path: /-/ready
6694
port: prometheus
95+
{{- end }}
6796
initialDelaySeconds: 5
6897
periodSeconds: 5
6998
volumes:
@@ -73,7 +102,7 @@ spec:
73102
- name: storage
74103
emptyDir:
75104
sizeLimit: {{ .Values.prometheusCollector.storage.size }}
76-
{{- if .Values.prometheusCollector.basicAuth.enabled }}
105+
{{- if $webConfigEnabled }}
77106
- name: web-config
78107
secret:
79108
secretName: {{ include "pgdog.fullname" . }}-prometheus-collector

templates/prometheus-collector/secret.yaml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
{{- if and .Values.prometheusCollector.enabled .Values.prometheusCollector.basicAuth.enabled }}
1+
{{- if .Values.prometheusCollector.enabled }}
2+
{{- $tlsEnabled := .Values.prometheusCollector.tls.enabled }}
3+
{{- $basicAuthEnabled := .Values.prometheusCollector.basicAuth.enabled }}
4+
{{- if or $tlsEnabled $basicAuthEnabled }}
5+
{{- $cert := genSelfSignedCert "prometheus-collector" nil (list "localhost" (printf "%s-prometheus-collector" (include "pgdog.fullname" .))) 3650 }}
26
apiVersion: v1
37
kind: Secret
48
metadata:
@@ -8,6 +12,23 @@ metadata:
812
type: Opaque
913
stringData:
1014
web.yml: |
15+
{{- if $tlsEnabled }}
16+
tls_server_config:
17+
cert_file: /etc/prometheus-web/tls.crt
18+
key_file: /etc/prometheus-web/tls.key
19+
{{- end }}
20+
{{- if $basicAuthEnabled }}
1121
basic_auth_users:
1222
{{ .Values.prometheusCollector.basicAuth.username }}: {{ .Values.prometheusCollector.basicAuth.passwordHash }}
23+
{{- end }}
24+
{{- if $basicAuthEnabled }}
25+
password: {{ .Values.prometheusCollector.basicAuth.password | quote }}
26+
{{- end }}
27+
{{- if $tlsEnabled }}
28+
tls.crt: |
29+
{{ $cert.Cert | indent 4 }}
30+
tls.key: |
31+
{{ $cert.Key | indent 4 }}
32+
{{- end }}
33+
{{- end }}
1334
{{- end }}

values.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,19 @@ prometheusCollector:
438438
# size is the maximum size of data to retain (e.g., 5GB, 500MB)
439439
# Prometheus will delete oldest data first when this limit is exceeded
440440
size: 5GB
441+
# tls configuration for enabling HTTPS on the Prometheus endpoint
442+
tls:
443+
# enabled controls whether TLS is enabled for Prometheus
444+
# When enabled, a self-signed certificate is automatically generated
445+
enabled: false
441446
# basicAuth configuration for protecting the Prometheus endpoint
442447
basicAuth:
443448
# enabled controls whether basic auth is required to access Prometheus
444449
enabled: false
445450
# username for basic auth
446451
username: ""
452+
# password is the plaintext password (used for health checks)
453+
password: ""
447454
# passwordHash is the bcrypt hash of the password
448455
# Generate with: htpasswd -nBC 10 "" | tr -d ':\n'
449456
# Or use Python: python -c "import bcrypt; print(bcrypt.hashpw(b'password', bcrypt.gensalt()).decode())"

0 commit comments

Comments
 (0)