From 1a1b0b9047e82580d58939074305fa8ada604b79 Mon Sep 17 00:00:00 2001 From: Raffael H Date: Tue, 8 Aug 2023 17:25:02 +0200 Subject: [PATCH] Initial commit --- readme.md | 13 ++++ user-monitoring-demo/.helmignore | 23 +++++++ user-monitoring-demo/Chart.yaml | 24 +++++++ user-monitoring-demo/demo-role.yaml | 20 ++++++ user-monitoring-demo/templates/_helpers.tpl | 62 +++++++++++++++++++ .../templates/demo-deploy.yaml | 21 +++++++ user-monitoring-demo/templates/demo-role.yaml | 21 +++++++ .../templates/demo-rolebinding.yaml | 12 ++++ .../templates/demo-servicemonitor.yaml | 16 +++++ user-monitoring-demo/templates/demo-svc.yaml | 15 +++++ user-monitoring-demo/values.yaml | 1 + user-monitoring/.helmignore | 23 +++++++ user-monitoring/Chart.yaml | 24 +++++++ user-monitoring/templates/_helpers.tpl | 62 +++++++++++++++++++ .../templates/user-basic-auth-secret.yaml | 7 +++ .../templates/user-prom-ingress.yaml | 25 ++++++++ user-monitoring/templates/user-prom-role.yaml | 20 ++++++ .../templates/user-prom-rolebinding.yaml | 11 ++++ user-monitoring/templates/user-prom-sa.yaml | 5 ++ .../templates/user-prometheus.yaml | 22 +++++++ user-monitoring/values.yaml | 1 + 21 files changed, 428 insertions(+) create mode 100644 readme.md create mode 100644 user-monitoring-demo/.helmignore create mode 100644 user-monitoring-demo/Chart.yaml create mode 100644 user-monitoring-demo/demo-role.yaml create mode 100644 user-monitoring-demo/templates/_helpers.tpl create mode 100644 user-monitoring-demo/templates/demo-deploy.yaml create mode 100644 user-monitoring-demo/templates/demo-role.yaml create mode 100644 user-monitoring-demo/templates/demo-rolebinding.yaml create mode 100644 user-monitoring-demo/templates/demo-servicemonitor.yaml create mode 100644 user-monitoring-demo/templates/demo-svc.yaml create mode 100644 user-monitoring-demo/values.yaml create mode 100644 user-monitoring/.helmignore create mode 100644 user-monitoring/Chart.yaml create mode 100644 user-monitoring/templates/_helpers.tpl create mode 100644 user-monitoring/templates/user-basic-auth-secret.yaml create mode 100644 user-monitoring/templates/user-prom-ingress.yaml create mode 100644 user-monitoring/templates/user-prom-role.yaml create mode 100644 user-monitoring/templates/user-prom-rolebinding.yaml create mode 100644 user-monitoring/templates/user-prom-sa.yaml create mode 100644 user-monitoring/templates/user-prometheus.yaml create mode 100644 user-monitoring/values.yaml diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..d58625e --- /dev/null +++ b/readme.md @@ -0,0 +1,13 @@ +# Prometheus lab setup + +WIP repository for prometheus lab user setup: + +Setup the namespaces with: + +kubectl create namespace user1-monitoring +kubectl create namespace user1-monitoring-demo + +helm -n user1-monitoring install user1-monitoring ./user-monitoring --set user=user1 +helm -n user1-monitoring-demo install user1-monitoring-demo ./user-monitoring-demo --set user=user1 + + diff --git a/user-monitoring-demo/.helmignore b/user-monitoring-demo/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/user-monitoring-demo/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/user-monitoring-demo/Chart.yaml b/user-monitoring-demo/Chart.yaml new file mode 100644 index 0000000..6365e94 --- /dev/null +++ b/user-monitoring-demo/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: user-monitoring-demo +description: Demo chart for user spaced monitoring stack in prometheus basics training. + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/user-monitoring-demo/demo-role.yaml b/user-monitoring-demo/demo-role.yaml new file mode 100644 index 0000000..a14f2eb --- /dev/null +++ b/user-monitoring-demo/demo-role.yaml @@ -0,0 +1,20 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: prometheus-{{ .Values.user }} +rules: +- apiGroups: [""] + resources: + - services + - endpoints + - pods + verbs: ["get", "list", "watch"] +- apiGroups: [""] + resources: + - configmaps + verbs: ["get"] +- apiGroups: + - networking.k8s.io + resources: + - ingresses + verbs: ["get", "list", "watch"] diff --git a/user-monitoring-demo/templates/_helpers.tpl b/user-monitoring-demo/templates/_helpers.tpl new file mode 100644 index 0000000..5b13f04 --- /dev/null +++ b/user-monitoring-demo/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "user-monitoring-demo.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "user-monitoring-demo.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "user-monitoring-demo.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "user-monitoring-demo.labels" -}} +helm.sh/chart: {{ include "user-monitoring-demo.chart" . }} +{{ include "user-monitoring-demo.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "user-monitoring-demo.selectorLabels" -}} +app.kubernetes.io/name: {{ include "user-monitoring-demo.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "user-monitoring-demo.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "user-monitoring-demo.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/user-monitoring-demo/templates/demo-deploy.yaml b/user-monitoring-demo/templates/demo-deploy.yaml new file mode 100644 index 0000000..7690c30 --- /dev/null +++ b/user-monitoring-demo/templates/demo-deploy.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: example-web-python + name: example-web-python +spec: + replicas: 1 + selector: + matchLabels: + app: example-web-python + template: + metadata: + labels: + app: example-web-python + spec: + containers: + - image: quay.io/acend/example-web-python + imagePullPolicy: Always + name: example-web-python + restartPolicy: Always diff --git a/user-monitoring-demo/templates/demo-role.yaml b/user-monitoring-demo/templates/demo-role.yaml new file mode 100644 index 0000000..4099a01 --- /dev/null +++ b/user-monitoring-demo/templates/demo-role.yaml @@ -0,0 +1,21 @@ +# Source: user-monitoring/templates/user-prom-role.yaml +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: prometheus-{{ .Values.user }} +rules: +- apiGroups: [""] + resources: + - services + - endpoints + - pods + verbs: ["get", "list", "watch"] +- apiGroups: [""] + resources: + - configmaps + verbs: ["get"] +- apiGroups: + - networking.k8s.io + resources: + - ingresses + verbs: ["get", "list", "watch"] \ No newline at end of file diff --git a/user-monitoring-demo/templates/demo-rolebinding.yaml b/user-monitoring-demo/templates/demo-rolebinding.yaml new file mode 100644 index 0000000..9470ff6 --- /dev/null +++ b/user-monitoring-demo/templates/demo-rolebinding.yaml @@ -0,0 +1,12 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: prometheus +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: prometheus-{{ .Values.user }} +subjects: +- kind: ServiceAccount + name: prometheus-{{ .Values.user }} + namespace: {{ .Values.user }}-monitoring \ No newline at end of file diff --git a/user-monitoring-demo/templates/demo-servicemonitor.yaml b/user-monitoring-demo/templates/demo-servicemonitor.yaml new file mode 100644 index 0000000..98aab47 --- /dev/null +++ b/user-monitoring-demo/templates/demo-servicemonitor.yaml @@ -0,0 +1,16 @@ +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + labels: + app.kubernetes.io/name: example-web-python + user: {{ .Values.user }} + name: example-web-python-monitor +spec: + endpoints: + - interval: 30s + port: http + scheme: http + path: /metrics + selector: + matchLabels: + app: example-web-python diff --git a/user-monitoring-demo/templates/demo-svc.yaml b/user-monitoring-demo/templates/demo-svc.yaml new file mode 100644 index 0000000..6b2986c --- /dev/null +++ b/user-monitoring-demo/templates/demo-svc.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: example-web-python + labels: + app: example-web-python +spec: + ports: + - name: http + port: 5000 + protocol: TCP + targetPort: 5000 + selector: + app: example-web-python + type: ClusterIP \ No newline at end of file diff --git a/user-monitoring-demo/values.yaml b/user-monitoring-demo/values.yaml new file mode 100644 index 0000000..b60785c --- /dev/null +++ b/user-monitoring-demo/values.yaml @@ -0,0 +1 @@ +user: user1 \ No newline at end of file diff --git a/user-monitoring/.helmignore b/user-monitoring/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/user-monitoring/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/user-monitoring/Chart.yaml b/user-monitoring/Chart.yaml new file mode 100644 index 0000000..56c21a2 --- /dev/null +++ b/user-monitoring/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: user-monitoring +description: Acend helm chart for user-monitoring namespace in prometheus-basics training + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/user-monitoring/templates/_helpers.tpl b/user-monitoring/templates/_helpers.tpl new file mode 100644 index 0000000..a23e681 --- /dev/null +++ b/user-monitoring/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "user-monitoring.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "user-monitoring.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "user-monitoring.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "user-monitoring.labels" -}} +helm.sh/chart: {{ include "user-monitoring.chart" . }} +{{ include "user-monitoring.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "user-monitoring.selectorLabels" -}} +app.kubernetes.io/name: {{ include "user-monitoring.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "user-monitoring.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "user-monitoring.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/user-monitoring/templates/user-basic-auth-secret.yaml b/user-monitoring/templates/user-basic-auth-secret.yaml new file mode 100644 index 0000000..bd33500 --- /dev/null +++ b/user-monitoring/templates/user-basic-auth-secret.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +data: + admin: JDEkSzNRZUlsOHAkZVZZb1h2RERNWk40b3RJT2tBc3AwLw== # $(openssl passwd -1 admin) + {{ .Values.user }}: JDEkSzNRZUlsOHAkZVZZb1h2RERNWk40b3RJT2tBc3AwLw== # $(openssl passwd -1 admin) +kind: Secret +metadata: + name: basic-auth \ No newline at end of file diff --git a/user-monitoring/templates/user-prom-ingress.yaml b/user-monitoring/templates/user-prom-ingress.yaml new file mode 100644 index 0000000..eca6f1b --- /dev/null +++ b/user-monitoring/templates/user-prom-ingress.yaml @@ -0,0 +1,25 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + haproxy.org/auth-secret: basic-auth + haproxy.org/auth-type: basic-auth + haproxy.org/auth-realm: Authentication Required + name: {{ .Values.user }}-prometheus +spec: + ingressClassName: haproxy + rules: + - host: {{ .Values.user }}-prometheus.training.cluster.acend.ch + http: + paths: + - backend: + service: + name: prometheus-operated + port: + number: 9090 + path: / + pathType: ImplementationSpecific + tls: + - hosts: + - {{ .Values.user }}-prometheus.training.cluster.acend.ch + secretName: acend-wildcard diff --git a/user-monitoring/templates/user-prom-role.yaml b/user-monitoring/templates/user-prom-role.yaml new file mode 100644 index 0000000..a14f2eb --- /dev/null +++ b/user-monitoring/templates/user-prom-role.yaml @@ -0,0 +1,20 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: prometheus-{{ .Values.user }} +rules: +- apiGroups: [""] + resources: + - services + - endpoints + - pods + verbs: ["get", "list", "watch"] +- apiGroups: [""] + resources: + - configmaps + verbs: ["get"] +- apiGroups: + - networking.k8s.io + resources: + - ingresses + verbs: ["get", "list", "watch"] diff --git a/user-monitoring/templates/user-prom-rolebinding.yaml b/user-monitoring/templates/user-prom-rolebinding.yaml new file mode 100644 index 0000000..58f5705 --- /dev/null +++ b/user-monitoring/templates/user-prom-rolebinding.yaml @@ -0,0 +1,11 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: prometheus +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: prometheus-{{ .Values.user }} +subjects: +- kind: ServiceAccount + name: prometheus-{{ .Values.user }} diff --git a/user-monitoring/templates/user-prom-sa.yaml b/user-monitoring/templates/user-prom-sa.yaml new file mode 100644 index 0000000..a6d6505 --- /dev/null +++ b/user-monitoring/templates/user-prom-sa.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: prometheus-{{ .Values.user }} + diff --git a/user-monitoring/templates/user-prometheus.yaml b/user-monitoring/templates/user-prometheus.yaml new file mode 100644 index 0000000..44a258c --- /dev/null +++ b/user-monitoring/templates/user-prometheus.yaml @@ -0,0 +1,22 @@ +apiVersion: monitoring.coreos.com/v1 +kind: Prometheus +metadata: + name: prometheus +spec: + serviceAccountName: prometheus-{{ .Values.user }} + serviceMonitorNamespaceSelector: + matchLabels: + user: {{ .Values.user }} + serviceMonitorSelector: + matchLabels: + user: {{ .Values.user }} + resources: + requests: + memory: 400Mi + enableAdminAPI: false + storage: + volumeClaimTemplate: + spec: + resources: + requests: + storage: 2Gi \ No newline at end of file diff --git a/user-monitoring/values.yaml b/user-monitoring/values.yaml new file mode 100644 index 0000000..b60785c --- /dev/null +++ b/user-monitoring/values.yaml @@ -0,0 +1 @@ +user: user1 \ No newline at end of file