From 3444facc00c5bd73e02d6ff793a88742dbcdfe89 Mon Sep 17 00:00:00 2001 From: Reinier Schoof Date: Wed, 19 Oct 2022 21:41:20 +0200 Subject: [PATCH] added helm chart --- README.md | 6 + charts/ssl-exporter/.helmignore | 23 ++++ charts/ssl-exporter/Chart.yaml | 10 ++ charts/ssl-exporter/templates/NOTES.txt | 6 + charts/ssl-exporter/templates/_helpers.tpl | 62 ++++++++++ charts/ssl-exporter/templates/configmap.yaml | 11 ++ charts/ssl-exporter/templates/deployment.yaml | 86 ++++++++++++++ .../templates/serviceaccount.yaml | 12 ++ charts/ssl-exporter/values.yaml | 112 ++++++++++++++++++ 9 files changed, 328 insertions(+) create mode 100644 charts/ssl-exporter/.helmignore create mode 100644 charts/ssl-exporter/Chart.yaml create mode 100644 charts/ssl-exporter/templates/NOTES.txt create mode 100644 charts/ssl-exporter/templates/_helpers.tpl create mode 100644 charts/ssl-exporter/templates/configmap.yaml create mode 100644 charts/ssl-exporter/templates/deployment.yaml create mode 100644 charts/ssl-exporter/templates/serviceaccount.yaml create mode 100644 charts/ssl-exporter/values.yaml diff --git a/README.md b/README.md index d2148dd9..60287f62 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ metric indicates if the probe has been successful. ### Release process +- Update the Helm chart version in [`charts/ssl-exporter/Chart.yaml`](charts/ssl-exporter/Chart.yaml) - Create a release in Github with a semver tag and GH actions will: - Add a changelog - Upload binaries @@ -78,6 +79,11 @@ Flags: | ssl_verified_cert_not_after | The date after which a certificate in the verified chain expires. Expressed as a Unix Epoch Time. | chain_no, serial_no, issuer_cn, cn, dnsnames, ips, emails, ou | tcp, https | | ssl_verified_cert_not_before | The date before which a certificate in the verified chain is not valid. Expressed as a Unix Epoch Time. | chain_no, serial_no, issuer_cn, cn, dnsnames, ips, emails, ou | tcp, https | +## Helm install + + git clone https://github.com/ribbybibby/ssl_exporter + helm install ssl-exporter ssl_exporter/charts/ssl-exporter + ## Configuration ### TCP diff --git a/charts/ssl-exporter/.helmignore b/charts/ssl-exporter/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/charts/ssl-exporter/.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/charts/ssl-exporter/Chart.yaml b/charts/ssl-exporter/Chart.yaml new file mode 100644 index 00000000..9a9f43c9 --- /dev/null +++ b/charts/ssl-exporter/Chart.yaml @@ -0,0 +1,10 @@ +apiVersion: v2 +name: ssl-exporter +description: SSL Certificate Exporter for Prometheus +type: application +version: 0.1.0 +appVersion: "2.4.2" +home: https://github.com/ribbybibby/ssl_exporter +maintainers: + - name: "@skoef" + url: https://github.com/skoef diff --git a/charts/ssl-exporter/templates/NOTES.txt b/charts/ssl-exporter/templates/NOTES.txt new file mode 100644 index 00000000..eccf75f6 --- /dev/null +++ b/charts/ssl-exporter/templates/NOTES.txt @@ -0,0 +1,6 @@ +SSL Certificate Exporter for Prometheus is installed! + +You should be able to see metrics like ssl_prober and ssl_*_cert_not_after appear +in your prometheus very soon. If not, check the logs by running + + kubectl -n {{ .Release.Namespace }} logs -f $(kubectl -n {{ .Release.Namespace }} get pods -l app.kubernetes.io/instance={{ .Release.Name }},app.kubernetes.io/name={{ include "ssl-exporter.name" . }} -o name) diff --git a/charts/ssl-exporter/templates/_helpers.tpl b/charts/ssl-exporter/templates/_helpers.tpl new file mode 100644 index 00000000..19aa3c60 --- /dev/null +++ b/charts/ssl-exporter/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "ssl-exporter.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 "ssl-exporter.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 "ssl-exporter.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "ssl-exporter.labels" -}} +helm.sh/chart: {{ include "ssl-exporter.chart" . }} +{{ include "ssl-exporter.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "ssl-exporter.selectorLabels" -}} +app.kubernetes.io/name: {{ include "ssl-exporter.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "ssl-exporter.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "ssl-exporter.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/ssl-exporter/templates/configmap.yaml b/charts/ssl-exporter/templates/configmap.yaml new file mode 100644 index 00000000..15c8373e --- /dev/null +++ b/charts/ssl-exporter/templates/configmap.yaml @@ -0,0 +1,11 @@ +{{- if .Values.config.enabled }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "ssl-exporter.fullname" . }} + labels: + {{- include "ssl-exporter.labels" . | nindent 4 }} +data: + config.yaml: | + {{- .Values.config.data | nindent 4 }} +{{- end }} diff --git a/charts/ssl-exporter/templates/deployment.yaml b/charts/ssl-exporter/templates/deployment.yaml new file mode 100644 index 00000000..20cd1941 --- /dev/null +++ b/charts/ssl-exporter/templates/deployment.yaml @@ -0,0 +1,86 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "ssl-exporter.fullname" . }} + labels: + {{- include "ssl-exporter.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "ssl-exporter.selectorLabels" . | nindent 6 }} + template: + metadata: + annotations: + prometheus.io/scrape: "true" + prometheus.io/port: "9219" + prometheus.io/path: /probe{{ with .Values.probeQuery }}?{{ . }}{{ end }} + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml" ) . | sha256sum }} + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "ssl-exporter.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "ssl-exporter.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + args: + - --web.probe-path=/probe + - --web.listen-address=:9219 + {{- if .Values.config.enabled }} + - --config.file=/config/config.yaml + {{- end}} + ports: + - name: http + containerPort: 9219 + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + {{- if .Values.config.enabled }} + - name: config + mountPath: /config + {{- end }} + {{- with .Values.extraVolumeMounts }} + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + volumes: + {{- if .Values.config.enabled }} + - name: config + configMap: + name: {{ include "ssl-exporter.fullname" . }} + {{- end }} + {{- with .Values.extraVolumes }} + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/ssl-exporter/templates/serviceaccount.yaml b/charts/ssl-exporter/templates/serviceaccount.yaml new file mode 100644 index 00000000..bb2f6c31 --- /dev/null +++ b/charts/ssl-exporter/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "ssl-exporter.serviceAccountName" . }} + labels: + {{- include "ssl-exporter.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/ssl-exporter/values.yaml b/charts/ssl-exporter/values.yaml new file mode 100644 index 00000000..f6de6e42 --- /dev/null +++ b/charts/ssl-exporter/values.yaml @@ -0,0 +1,112 @@ +# Default values for ssl_exporter. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: ribbybibby/ssl-exporter + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: false + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +podSecurityContext: + fsGroup: 100 + +securityContext: + capabilities: + drop: + - ALL + readOnlyRootFilesystem: true + runAsNonRoot: true + runAsUser: 100 + runAsGroup: 100 + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +extraVolumeMounts: [] +# - name: mysecret +# mountPath: /mysecret + +extraVolumes: [] +# - name: mysecret +# secret: +# secretName: mysecret-tls + +# query for calling the probe path, without the leading ? +# probeQuery: probe=file&target=/etc/ssl/ca.crt + +config: + enabled: true + data: | + modules: + https: + prober: https + https_insecure: + prober: https + tls_config: + insecure_skip_verify: true + https_proxy: + prober: https + https: + proxy_url: "socks5://localhost:8123" + https_timeout: + prober: https + timeout: 3s + tcp: + prober: tcp + tcp_servername: + prober: tcp + tls_config: + server_name: example.com + tcp_client_auth: + prober: tcp + tls_config: + ca_file: /etc/tls/ca.crt + cert_file: /etc/tls/tls.crt + key_file: /etc/tls/tls.key + tcp_smtp_starttls: + prober: tcp + tcp: + starttls: smtp + file: + prober: file + kubernetes: + prober: kubernetes + kubernetes_kubeconfig: + prober: kubernetes + kubernetes: + kubeconfig: /root/.kube/config + kubeconfig: + prober: kubeconfig