10BC0 Expose Prometheus metrics through a headless Service. (#4331) · nginx/kubernetes-ingress@a843e0c · GitHub
[go: up one dir, main page]

Skip to content

Commit a843e0c

Browse files
authored
Expose Prometheus metrics through a headless Service. (#4331)
1 parent 5b1d085 commit a843e0c

File tree

4 files changed

+70
-14
lines changed

4 files changed

+70
-14
lines changed

deployments/helm-chart/templates/_helpers.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,7 @@ Expand image name.
129129
{{- printf "%s:%s" .Values.controller.image.repository (include "nginx-ingress.tag" .) -}}
130130
{{- end -}}
131131
{{- end -}}
132+
133+
{{- define "nginx-ingress.prometheus.serviceName" -}}
134+
{{- printf "%s-%s" (include "nginx-ingress.fullname" .) "prometheus-service" -}}
135+
{{- end -}}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{{- if and .Values.prometheus.create .Values.prometheus.service.create}}
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: {{ include "nginx-ingress.prometheus.serviceName" . }}
6+
namespace: {{ .Release.Namespace }}
7+
labels:
8+
{{- include "nginx-ingress.labels" . | nindent 4 }}
9+
{{- if .Values.prometheus.service.labels -}}
10+
{{- toYaml .Values.prometheus.service.labels | nindent 4 }}
11+
{{- end }}
12+
spec:
13+
clusterIP: None
14+
ports:
15+
- name: prometheus
16+
protocol: TCP
17+
port: {{ .Values.prometheus.port }}
18+
targetPort: {{ .Values.prometheus.port }}
19+
selector:
20+
{{- include "nginx-ingress.selectorLabels" . | nindent 4 }}
21+
{{- end }}

deployments/helm-chart/values.schema.json

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,26 @@
15041504
"examples": [
15051505
"http"
15061506
]
1507+
},
1508+
"service": {
1509+
"type": "object",
1510+
"default": {},
1511+
"properties": {
1512+
"create": {
1513+
"type": "boolean",
1514+
"default": false,
1515+
"title": "The create",
1516+
"examples": [
1517+
true
1518+
]
1519+
},
1520+
"labels": {
1521+
"type": "object",
1522+
"default": {},
1523+
"title": "The labels Schema",
1524+
"$ref": "https://raw.githubusercontent.com/nginxinc/kubernetes-json-schema/master/v1.27.4/_definitions.json#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta/properties/labels"
1525+
}
1526+
}
15071527
}
15081528
},
15091529
"examples": [
@@ -1755,7 +1775,11 @@
17551775
"create": true,
17561776
"port": 9113,
17571777
"secret": "",
1758-
"scheme": "http"
1778+
"scheme": "http",
1779+
"service": {
1780+
"create": false,
1781+
"labels": {}
1782+
}
17591783
},
17601784
"serviceInsight": {
17611785
"create": true,

deployments/helm-chart/values.yaml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -382,19 +382,6 @@ controller:
382382
## Secret must exist in the same namespace as the helm release.
383383
imagePullSecretName: ""
384384

385-
serviceMonitor:
386-
## Creates a serviceMonitor to expose statistics on the kubernetes pods.
387-
create: false
388-
389-
## Kubernetes object labels to attach to the serviceMonitor object.
390-
labels: {}
391-
392-
## A set of labels to allow the selection of endpoints for the ServiceMonitor.
393-
selectorMatchLabels: {}
394-
395-
## A list of endpoints allowed as part of this ServiceMonitor.
396-
endpoints: []
397-
398385
reportIngressStatus:
399386
## Updates the address field in the status of Ingress resources with an external address of the Ingress Controller.
400387
## You must also specify the source of the external address either through an external service via controller.reportIngressStatus.externalService,
@@ -452,6 +439,19 @@ controller:
452439
## Configure root filesystem as read-only and add volumes for temporary data.
453440
readOnlyRootFilesystem: false
454441

442+
serviceMonitor:
443+
## Creates a serviceMonitor to expose statistics on the kubernetes pods.
444+
create: false
445+
446+
## Kubernetes object labels to attach to the serviceMonitor object.
447+
labels: {}
448+
449+
## A set of labels to allow the selection of endpoints for the ServiceMonitor.
450+
selectorMatchLabels: {}
451+
452+
## A list of endpoints allowed as part of this ServiceMonitor.
453+
endpoints: []
454+
455455
rbac:
456456
## Configures RBAC.
457457
create: true
@@ -469,6 +469,13 @@ prometheus:
469469
## Configures the HTTP scheme used.
470470
scheme: http
471471

472+
service:
473+
## Creates a ClusterIP Service to expose Prometheus metrics internally
474+
## Requires prometheus.create=true
475+
create: false
476+
477+
labels: {}
478+
472479
serviceInsight:
473480
## Expose NGINX Plus Service Insight endpoint.
474481
create: false

0 commit comments

Comments
 (0)
0