diff --git a/.gitignore b/.gitignore index 708a0fd..8ecc6ac 100644 --- a/.gitignore +++ b/.gitignore @@ -238,8 +238,6 @@ $RECYCLE.BIN/ # End of https://www.toptal.com/developers/gitignore/api/go,jetbrains+all,visualstudiocode,sublimetext,macos,osx,windows,linux # Custom -health_exporter -health-exporter app config.yaml diff --git a/charts/health-exporter/.helmignore b/charts/health-exporter/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/health-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/health-exporter/Chart.yaml b/charts/health-exporter/Chart.yaml new file mode 100644 index 0000000..fc3ef6b --- /dev/null +++ b/charts/health-exporter/Chart.yaml @@ -0,0 +1,8 @@ +apiVersion: v2 +name: health-exporter +home: https://github.com/snapp-cab/health-exporter +sources: + - https://github.com/snapp-cab/health-exporter.git +type: application +version: 0.3.0 +appVersion: 1.0.0 diff --git a/charts/health-exporter/README.md b/charts/health-exporter/README.md new file mode 100644 index 0000000..1ba8bda --- /dev/null +++ b/charts/health-exporter/README.md @@ -0,0 +1 @@ +# Helm chart for health-exporter diff --git a/charts/health-exporter/templates/_helpers.tpl b/charts/health-exporter/templates/_helpers.tpl new file mode 100644 index 0000000..1fa20b6 --- /dev/null +++ b/charts/health-exporter/templates/_helpers.tpl @@ -0,0 +1,32 @@ + +{{/* +Expand the name of the chart. +*/}} +{{- define "health_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 "health_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 "health_exporter.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/charts/health-exporter/templates/cm.yaml b/charts/health-exporter/templates/cm.yaml new file mode 100644 index 0000000..8b7be8b --- /dev/null +++ b/charts/health-exporter/templates/cm.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: '{{ template "health_exporter.fullname" . }}' + namespace: '{{ .Release.Namespace }}' +data: + config.yaml: | + {{- toYaml .Values.config | default "{}" | nindent 4 }} diff --git a/charts/health-exporter/templates/deploy.yaml b/charts/health-exporter/templates/deploy.yaml new file mode 100644 index 0000000..cb92be0 --- /dev/null +++ b/charts/health-exporter/templates/deploy.yaml @@ -0,0 +1,70 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: '{{ template "health_exporter.fullname" . }}' + namespace: '{{ .Release.Namespace }}' + labels: + app: '{{ template "health_exporter.fullname" . }}' +spec: + replicas: {{ .Values.replicas }} + selector: + matchLabels: + app: '{{ template "health_exporter.fullname" . }}' + strategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 1 + maxSurge: 0 + template: + metadata: + labels: + app: '{{ template "health_exporter.fullname" . }}' + spec: + affinity: + podAntiAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: + - key: app + operator: In + values: + - '{{ template "health_exporter.fullname" . }}' + topologyKey: "kubernetes.io/hostname" + containers: + - name: health-exporter + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + volumeMounts: + - mountPath: /app/config.yaml + name: config + subPath: config.yaml + imagePullPolicy: Always + resources: + {{- toYaml .Values.resources | nindent 10 }} + ports: + - containerPort: '{{ .Values.config.listen }}' + livenessProbe: + failureThreshold: 3 + httpGet: + path: /healthz + port: '{{ .Values.config.listen }}' + scheme: HTTP + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 + readinessProbe: + failureThreshold: 3 + httpGet: + path: /healthz + port: '{{ .Values.config.listen }}' + scheme: HTTP + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 + volumes: + - name: config + configMap: + defaultMode: 420 + name: '{{ template "health_exporter.fullname" . }}' + items: + - key: config.yaml + path: config.yaml diff --git a/charts/health-exporter/templates/hpa.yaml b/charts/health-exporter/templates/hpa.yaml new file mode 100644 index 0000000..6ef9539 --- /dev/null +++ b/charts/health-exporter/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "health_exporter.fullname" . }} + labels: + {{- include "health_exporter.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "health_exporter.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/health-exporter/templates/svc.yaml b/charts/health-exporter/templates/svc.yaml new file mode 100644 index 0000000..feea788 --- /dev/null +++ b/charts/health-exporter/templates/svc.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: '{{ template "health_exporter.fullname" . }}' + namespace: '{{ .Release.Namespace }}' +spec: + ports: + - name: web + port: 8080 + protocol: TCP + targetPort: '{{ .Values.config.listen }}' + selector: + app: '{{ template "health_exporter.fullname" . }}' diff --git a/charts/health-exporter/values.yaml b/charts/health-exporter/values.yaml new file mode 100644 index 0000000..82665b8 --- /dev/null +++ b/charts/health-exporter/values.yaml @@ -0,0 +1,39 @@ +# Default values for health-exporter. +image: + repository: "spc35771/health-exporter" + tag: "latest" +replicas: 1 +resources: + limits: + memory: "100Mi" + cpu: "1" + requests: + memory: "100Mi" + cpu: "1" + +autoscaling: + enabled: false + minReplicas: 2 + maxReplicas: 4 + targetCPUUtilizationPercentage: 80 + targetMemoryUtilizationPercentage: 80 + +config: + listen: ':9876' + targets: + http: + - name: 'sample' + url: 'http://google.com' + rps: 0.5 + timeout: '5s' + - name: 'google-tls' + url: 'https://google.com' + rps: 0.5 + timeout: '5s' + tls_skip_verify: true + dns: + - name: 'google' + domain: 'google.com' + record_type: 'A' + rps: 0.5 + timeout: '2s'