From 05c2c1915c97376ea0772cfd1ebd959040f704bd Mon Sep 17 00:00:00 2001 From: Mattis Bratland Date: Sun, 20 Oct 2024 03:35:28 +0200 Subject: [PATCH] feat: Add pod monitor for pulling metrics - Add network policy for allowing traffic from prometheus - Add Pod monitor to pull metrics --- charts/flaiserator/templates/deployment.yaml | 9 +++++---- .../flaiserator/templates/networkpolicy.yaml | 20 +++++++++++++++++++ charts/flaiserator/templates/podmonitor.yaml | 13 ++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 charts/flaiserator/templates/networkpolicy.yaml create mode 100644 charts/flaiserator/templates/podmonitor.yaml diff --git a/charts/flaiserator/templates/deployment.yaml b/charts/flaiserator/templates/deployment.yaml index 6432085..4ba744d 100644 --- a/charts/flaiserator/templates/deployment.yaml +++ b/charts/flaiserator/templates/deployment.yaml @@ -12,10 +12,7 @@ spec: template: metadata: annotations: - prometheus.io/scrape: "false" - prometheus.io/port: "8080" - prometheus.io/path: "/metrics" - {{- with .Values.podLabels }} + {{- with .Values.podAnnotations }} {{- toYaml . | nindent 8 }} {{- end }} labels: @@ -37,6 +34,10 @@ spec: imagePullPolicy: {{ .Values.image.pullPolicy }} resources: {{- toYaml .Values.resources | nindent 12 }} + ports: + - name: metrics + containerPort: 8080 + protocol: TCP securityContext: {{- toYaml .Values.securityContext | nindent 12 }} {{- with .Values.volumeMounts }} diff --git a/charts/flaiserator/templates/networkpolicy.yaml b/charts/flaiserator/templates/networkpolicy.yaml new file mode 100644 index 0000000..7027ffd --- /dev/null +++ b/charts/flaiserator/templates/networkpolicy.yaml @@ -0,0 +1,20 @@ +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: {{ include "flaiserator.fullname" . }}-prometheus + labels: + {{- include "flaiserator.labels" . | nindent 4 }} +spec: + podSelector: + matchLabels: + {{- include "flaiserator.selectorLabels" . | nindent 6 }} + ingress: + - from: + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: {{ .Release.Namespace }} + - podSelector: + matchLabels: + app.kubernetes.io/name: prometheus + policyTypes: + - Ingress \ No newline at end of file diff --git a/charts/flaiserator/templates/podmonitor.yaml b/charts/flaiserator/templates/podmonitor.yaml new file mode 100644 index 0000000..71f8692 --- /dev/null +++ b/charts/flaiserator/templates/podmonitor.yaml @@ -0,0 +1,13 @@ +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + labels: + {{- include "flaiserator.labels" . | nindent 4 }} + name: {{ include "flaiserator.fullname" . }} +spec: + selector: + matchLabels: + {{- include "flaiserator.selectorLabels" . | nindent 6 }} + podMetricsEndpoints: + - port: metrics + path: /metrics \ No newline at end of file