diff --git a/deploy/helm/time-exporter/.helmignore b/deploy/helm/time-exporter/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/deploy/helm/time-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/deploy/helm/time-exporter/Chart.yaml b/deploy/helm/time-exporter/Chart.yaml new file mode 100644 index 0000000..d317454 --- /dev/null +++ b/deploy/helm/time-exporter/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: time-exporter +description: Time Exporter +type: application +version: 0.1.2 +appVersion: "0.0.3" diff --git a/deploy/helm/time-exporter/README.md b/deploy/helm/time-exporter/README.md new file mode 100644 index 0000000..34c3810 --- /dev/null +++ b/deploy/helm/time-exporter/README.md @@ -0,0 +1,48 @@ +# Helm Chart for the Time Exporter + +This [Helm](https://helm.sh/) chart deploys the Time Exporter to a +Kubernetes cluster as a +[DaemonSet](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/). + +## Chrony Monitoring Considerations + +Chrony by defaults provides its command channel through a Unix socket. +There is also an additional UDP socket that listens to the loopback +interface only by default (127.0.0.1:323). + +Before actually deploying the Time Exporter to monitor Chrony, check +your access options: + +- When passing the Unix socket (`/var/run/chrony/chronyd.sock`), + ensure that the `time_exporter` process has write access to it. + +- The container cannot access the host’s loopback interface unless the + Pods runs with host network access (`hostNetwork=true`). Consider + securing the endpoint via + [`--web.config`](https://github.com/prometheus/node_exporter#tls-endpoint). + +- Another option is to bind `chronyd` to an accessible IP address and + configure authentication. However, the latter seems to be + unsupported by `time_exporter` currently. + +## Scraping + +Typically, annotating the Kubernetes Service should be sufficient to +make the [Prometheus Service +Discovery](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kubernetes_sd_config) +aware of the Time Exporter and scrape the metrics. + +Example: + +```yaml +service: + annotations: + prometheus.io/scrape: "true" +``` + +## Deployment Configuration (Helm Values) + +See the file `values.yaml` for all available configuration options. + +Do not forget to enable the desired collector. The Helm chart disables +all collectors by default except for the exporter metrics. diff --git a/deploy/helm/time-exporter/index.yaml b/deploy/helm/time-exporter/index.yaml new file mode 100644 index 0000000..55e0e85 --- /dev/null +++ b/deploy/helm/time-exporter/index.yaml @@ -0,0 +1,24 @@ +apiVersion: v1 +entries: + time-exporter: + - apiVersion: v2 + appVersion: 0.0.3 + created: "2021-11-22T11:35:17.606647408+01:00" + description: Time Exporter + digest: 2da94972515e527852708f3ebaa5615af083d48d1cff9b24628b492fdf611edb + name: time-exporter + type: application + urls: + - time-exporter-0.1.2.tgz + version: 0.1.2 + - apiVersion: v2 + appVersion: 0.0.3 + created: "2021-11-22T11:35:17.604661748+01:00" + description: Time Exporter + digest: 6df64198080229a804046b4a320e11af57d52208359fd39727b734bea58b1e93 + name: time-exporter + type: application + urls: + - time-exporter-0.1.1.tgz + version: 0.1.1 +generated: "2021-11-22T11:35:17.598863969+01:00" diff --git a/deploy/helm/time-exporter/templates/_helpers.tpl b/deploy/helm/time-exporter/templates/_helpers.tpl new file mode 100644 index 0000000..c80bf2f --- /dev/null +++ b/deploy/helm/time-exporter/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "time-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 "time-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 "time-exporter.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "time-exporter.labels" -}} +helm.sh/chart: {{ include "time-exporter.chart" . }} +{{ include "time-exporter.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "time-exporter.selectorLabels" -}} +app.kubernetes.io/name: {{ include "time-exporter.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "time-exporter.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "time-exporter.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/deploy/helm/time-exporter/templates/daemonset.yaml b/deploy/helm/time-exporter/templates/daemonset.yaml new file mode 100644 index 0000000..ac84197 --- /dev/null +++ b/deploy/helm/time-exporter/templates/daemonset.yaml @@ -0,0 +1,117 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: {{ include "time-exporter.fullname" . }} + labels: + {{- include "time-exporter.labels" . | nindent 4 }} +spec: + selector: + matchLabels: + {{- include "time-exporter.selectorLabels" . | nindent 6 }} +{{- with .Values.updateStrategy }} + updateStrategy: + {{ . | toYaml | nindent 4 }} +{{- end }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "time-exporter.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "time-exporter.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} +{{- if .Values.priorityClassName }} + priorityClassName: {{ .Values.priorityClassName }} +{{- end }} + hostNetwork: {{ .Values.hostNetwork }} + 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: + - --log.level={{ .Values.logging.level }} + - --log.format={{ .Values.logging.format }} + - --collector.disable-defaults +{{- if not .Values.collectors.exporterMetrics }} + - --web.disable-exporter-metrics +{{- end }} +{{- if .Values.collectors.chrony.enabled }} + - --collector.chrony + - --collector.chrony.address={{ .Values.collectors.chrony.address }} +{{- if .Values.collectors.chrony.logResponse }} + - --collector.chrony.log-response-json +{{- end }} +{{- end }} +{{- if .Values.collectors.ntp.enabled }} + - --collector.ntp +{{- end }} +{{- if .Values.collectors.time.enabled }} + - --collector.time +{{- end }} +{{- if .Values.collectors.timex.enabled }} + - --collector.timex +{{- end }} +{{- range $key, $value := .Values.extraArgs }} + - --{{ $key }}={{ $value }} +{{- end }} + ports: + - name: http + containerPort: 9818 + protocol: TCP +{{- if .Values.livenessProbe.enabled }} + livenessProbe: + httpGet: + path: / + port: http + failureThreshold: {{ .Values.livenessProbe.failureThreshold }} + periodSeconds: {{ .Values.livenessProbe.periodSeconds }} + successThreshold: {{ .Values.livenessProbe.successThreshold }} + timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} +{{- end }} +{{- if .Values.readinessProbe.enabled }} + readinessProbe: + httpGet: + path: / + port: http + failureThreshold: {{ .Values.readinessProbe.failureThreshold }} + periodSeconds: {{ .Values.readinessProbe.periodSeconds }} + successThreshold: {{ .Values.readinessProbe.successThreshold }} + timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} +{{- end }} + resources: + {{- toYaml .Values.resources | nindent 12 }} +{{- if and .Values.collectors.chrony.enabled (eq "/" (substr 0 1 .Values.collectors.chrony.address)) }} + volumeMounts: + - name: chrony-socket + mountPath: {{ .Values.collectors.chrony.address }} + readOnly: true +{{- 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 }} +{{- if and .Values.collectors.chrony.enabled (eq "/" (substr 0 1 .Values.collectors.chrony.address)) }} + volumes: + - name: chrony-socket + hostPath: + path: {{ .Values.collectors.chrony.hostPath }} + type: Socket +{{- end }} diff --git a/deploy/helm/time-exporter/templates/service.yaml b/deploy/helm/time-exporter/templates/service.yaml new file mode 100644 index 0000000..07ab1ee --- /dev/null +++ b/deploy/helm/time-exporter/templates/service.yaml @@ -0,0 +1,20 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "time-exporter.fullname" . }} + labels: + {{- include "time-exporter.labels" . | nindent 4 }} +{{- with .Values.service.annotations }} + annotations: + {{ . |toYaml |indent 4 }} +{{- end }} +spec: + type: {{ .Values.service.type }} + clusterIP: None + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "time-exporter.selectorLabels" . | nindent 4 }} diff --git a/deploy/helm/time-exporter/templates/serviceaccount.yaml b/deploy/helm/time-exporter/templates/serviceaccount.yaml new file mode 100644 index 0000000..ea9e6db --- /dev/null +++ b/deploy/helm/time-exporter/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "time-exporter.serviceAccountName" . }} + labels: + {{- include "time-exporter.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/deploy/helm/time-exporter/templates/tests/test-connection.yaml b/deploy/helm/time-exporter/templates/tests/test-connection.yaml new file mode 100644 index 0000000..0434e0e --- /dev/null +++ b/deploy/helm/time-exporter/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "time-exporter.fullname" . }}-test-connection" + labels: + {{- include "time-exporter.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "time-exporter.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/deploy/helm/time-exporter/time-exporter-0.1.2.tgz b/deploy/helm/time-exporter/time-exporter-0.1.2.tgz new file mode 100644 index 0000000..09d7bd2 Binary files /dev/null and b/deploy/helm/time-exporter/time-exporter-0.1.2.tgz differ diff --git a/deploy/helm/time-exporter/values.yaml b/deploy/helm/time-exporter/values.yaml new file mode 100644 index 0000000..285ad81 --- /dev/null +++ b/deploy/helm/time-exporter/values.yaml @@ -0,0 +1,151 @@ +# Default values for time-exporter. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +image: + repository: dmi7ry/time-exporter + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +# See https://kubernetes.io/docs/tasks/manage-daemon/update-daemon-set/ +updateStrategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 100% + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # 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: 2000 + +securityContext: + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + # allowPrivilegeEscalation: true + +service: + type: ClusterIP + port: 9818 + annotations: {} + # prometheus.io/scrape: "true" + +# Accessing the host's network may be required to access the chronyd +# command channel +hostNetwork: true + +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: 64Mi + # requests: + # cpu: 50m + # memory: 32Mi + +nodeSelector: {} + +tolerations: [] + # - key: node-role.kubernetes.io/master + # operator: Exists + # effect: NoSchedule + +affinity: {} + +# Pod Priority +# See https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/ +# priorityClassName: system-node-critical +priorityClassName: "" + +livenessProbe: + enabled: true + failureThreshold: 3 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 + +readinessProbe: + enabled: true + failureThreshold: 3 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 + +logging: + # Log level (debug, info, warn, error) + level: info + + # Logging format (logfmt, json) + format: json + +collectors: + + # Enable the exporter metrics + exporterMetrics: + enabled: true + + # Chrony + chrony: + + # Enable the Chrony collector + enabled: false + + # chronyd socket or address in container + # + # When using a socket, ensure that the container has write access + # to it. By default, chronyd exposes its UDP command socket to the + # host's loopback address only which is inaccessible for the container. + # + # address: /var/run/chrony/chronyd.sock + address: 127.0.0.1:323 + + # chronyd socket host path + # Passed through only if .address is a path + hostPath: /var/run/chrony/chronyd.sock + + # Log Chrony JSON reponse (requires log level debug) + logResponse: false + + # ntpd + ntp: + # Enable the ntpd collector + enabled: false + server: 127.0.0.1 + protocol: 4 + isLocal: true + maxDistance: 3.46608s + localOffsetTolerance: 1ms + + # time + time: + # Enable time collector + enabled: false + + # timex + timex: + # Enable timex metrics + enabled: false + +# Additional arguments to pass to the Time Exporter +extraArgs: {} + # web.telemetry-path: /metrics