diff --git a/charts/prometheus-prefect-exporter/Chart.yaml b/charts/prometheus-prefect-exporter/Chart.yaml new file mode 100644 index 0000000..a7dedf5 --- /dev/null +++ b/charts/prometheus-prefect-exporter/Chart.yaml @@ -0,0 +1,17 @@ +apiVersion: v2 +description: A Helm chart to deploy Prometheus Prefect Exporter +type: application +maintainers: + - name: ialejandro + email: hello@ialejandro.rocks + url: https://ialejandro.rocks +name: prometheus-prefect-exporter +sources: + - https://github.com/devops-ia/prometheus-prefect-exporter +version: 0.1.0 +appVersion: "0.1.0" +home: https://github.com/devops-ia/helm-charts/tree/main/charts/prometheus-prefect-exporter +keywords: +- prometheus-prefect-exporter +- prometheus +- prefect diff --git a/charts/prometheus-prefect-exporter/README.md b/charts/prometheus-prefect-exporter/README.md new file mode 100644 index 0000000..44d61dc --- /dev/null +++ b/charts/prometheus-prefect-exporter/README.md @@ -0,0 +1,77 @@ +# prometheus-prefect-exporter + +A Helm chart to deploy Prometheus Prefect Exporter + +## Maintainers + +| Name | Email | Url | +| ---- | ------ | --- | +| ialejandro | | | + +## Prerequisites + +* Helm 3+ + +## Add repository + +```console +helm repo add devops-ia https://devops-ia.github.io/helm-charts +helm repo update +``` + +## Install Helm chart + +```console +helm install [RELEASE_NAME] devops-ia/prometheus-prefect-exporter +``` + +This install all the Kubernetes components associated with the chart and creates the release. + +_See [helm install](https://helm.sh/docs/helm/helm_install/) for command documentation._ + +## Uninstall Helm chart + +```console +# Helm +helm uninstall [RELEASE_NAME] +``` + +This removes all the Kubernetes components associated with the chart and deletes the release. + +_See [helm uninstall](https://helm.sh/docs/helm/helm_uninstall/) for command documentation._ + +## Configuration + +See [Customizing the chart before installing](https://helm.sh/docs/intro/using_helm/#customizing-the-chart-before-installing). To see all configurable options with comments: + +```console +helm show values devops-ia/prometheus-prefect-exporter +``` + +## Values + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| affinity | object | `{}` | Affinity for pod assignment | +| autoscaling | object | `{"enabled":false,"maxReplicas":100,"minReplicas":1,"targetCPUUtilizationPercentage":80}` | Autoscaling with CPU or memory utilization percentage | +| env | object | `{}` | Environment variables to configure application | +| fullnameOverride | string | `""` | String to fully override prometheus-prefect-exporter.fullname template | +| image | object | `{"pullPolicy":"IfNotPresent","repository":"devopsiaci/prometheus-prefect-exporter","tag":""}` | Image registry | +| imagePullSecrets | list | `[]` | Global Docker registry secret names as an array | +| ingress | object | `{"annotations":{},"className":"","enabled":false,"hosts":[{"host":"chart-example.local","paths":[{"path":"/","pathType":"ImplementationSpecific"}]}],"tls":[]}` | Ingress configuration to expose app | +| nameOverride | string | `""` | String to partially override prometheus-prefect-exporter.fullname template (will maintain the release name) | +| nodeSelector | object | `{}` | Node labels for pod assignment | +| podAnnotations | object | `{}` | Pod annotations | +| podSecurityContext | object | `{}` | To specify security settings for a Pod | +| replicaCount | int | `1` | Number of replicas | +| resources | object | `{}` | The resources limits and requested | +| securityContext | object | `{}` | Defines privilege and access control settings for a Pod or Container | +| service | object | `{"port":80,"targetPort":80,"type":"ClusterIP"}` | Kubernetes servide to expose Pod | +| service.port | int | `80` | Kubernetes Service port | +| service.targetPort | int | `80` | Pod expose port | +| service.type | string | `"ClusterIP"` | Kubernetes Service type. Allowed values: NodePort, LoadBalancer or ClusterIP | +| serviceAccount | object | `{"annotations":{},"create":true,"name":""}` | Enable creation of ServiceAccount | +| serviceMonitor | object | `{"enabled":false,"interval":"30s","metricRelabelings":[],"relabelings":[],"scrapeTimeout":"10s"}` | Enable ServiceMonitor to get metrics ref: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#servicemonitor | +| serviceMonitor.enabled | bool | `false` | Enable or disable | +| testConnection | bool | `false` | Enable livenessProbe and readinessProbe | +| tolerations | list | `[]` | Tolerations for pod assignment | diff --git a/charts/prometheus-prefect-exporter/README.md.gotmpl b/charts/prometheus-prefect-exporter/README.md.gotmpl new file mode 100644 index 0000000..d3318f5 --- /dev/null +++ b/charts/prometheus-prefect-exporter/README.md.gotmpl @@ -0,0 +1,49 @@ +# {{ template "chart.name" . }} + +{{ template "chart.description" . }} + +{{ template "chart.maintainersSection" . }} + +## Prerequisites + +* Helm 3+ + +{{ template "chart.requirementsSection" . }} + +## Add repository + +```console +helm repo add devops-ia https://devops-ia.github.io/helm-charts +helm repo update +``` + +## Install Helm chart + +```console +helm install [RELEASE_NAME] devops-ia/{{ template "chart.name" . }} +``` + +This install all the Kubernetes components associated with the chart and creates the release. + +_See [helm install](https://helm.sh/docs/helm/helm_install/) for command documentation._ + +## Uninstall Helm chart + +```console +# Helm +helm uninstall [RELEASE_NAME] +``` + +This removes all the Kubernetes components associated with the chart and deletes the release. + +_See [helm uninstall](https://helm.sh/docs/helm/helm_uninstall/) for command documentation._ + +## Configuration + +See [Customizing the chart before installing](https://helm.sh/docs/intro/using_helm/#customizing-the-chart-before-installing). To see all configurable options with comments: + +```console +helm show values devops-ia/{{ template "chart.name" . }} +``` + +{{ template "chart.valuesSection" . }} diff --git a/charts/prometheus-prefect-exporter/templates/NOTES.txt b/charts/prometheus-prefect-exporter/templates/NOTES.txt new file mode 100644 index 0000000..a0436f0 --- /dev/null +++ b/charts/prometheus-prefect-exporter/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "prometheus-prefect-exporter.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "prometheus-prefect-exporter.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "prometheus-prefect-exporter.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "prometheus-prefect-exporter.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/charts/prometheus-prefect-exporter/templates/_helpers.tpl b/charts/prometheus-prefect-exporter/templates/_helpers.tpl new file mode 100644 index 0000000..837e8bd --- /dev/null +++ b/charts/prometheus-prefect-exporter/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "prometheus-prefect-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 "prometheus-prefect-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 "prometheus-prefect-exporter.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "prometheus-prefect-exporter.labels" -}} +helm.sh/chart: {{ include "prometheus-prefect-exporter.chart" . }} +{{ include "prometheus-prefect-exporter.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "prometheus-prefect-exporter.selectorLabels" -}} +app.kubernetes.io/name: {{ include "prometheus-prefect-exporter.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "prometheus-prefect-exporter.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "prometheus-prefect-exporter.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/prometheus-prefect-exporter/templates/deployment.yaml b/charts/prometheus-prefect-exporter/templates/deployment.yaml new file mode 100644 index 0000000..e2b39f3 --- /dev/null +++ b/charts/prometheus-prefect-exporter/templates/deployment.yaml @@ -0,0 +1,80 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "prometheus-prefect-exporter.fullname" . }} + labels: + {{- include "prometheus-prefect-exporter.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "prometheus-prefect-exporter.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "prometheus-prefect-exporter.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- if .Values.serviceAccount.useServiceAccount }} + serviceAccountName: {{ .Values.serviceAccount.useServiceAccount }} + {{ else }} + serviceAccountName: {{ include "prometheus-prefect-exporter.serviceAccountName" . }} + {{- end }} + 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: + {{- if .Values.containerArgs }} + {{- range .Values.containerArgs }} + - {{ . | quote }} + {{- end }} + {{- end }} + ports: + - name: http + containerPort: {{ .Values.service.targetPort | default .Values.service.port }} + protocol: TCP + {{- if .Values.testConnection }} + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + {{- end }} + env: + {{- if .Values.env }} + {{- range $key, $value := .Values.env }} + - name: {{ $key | upper }} + value: {{ $value | quote }} + {{- end }} + {{- end }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/prometheus-prefect-exporter/templates/hpa.yaml b/charts/prometheus-prefect-exporter/templates/hpa.yaml new file mode 100644 index 0000000..5b1f48d --- /dev/null +++ b/charts/prometheus-prefect-exporter/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "prometheus-prefect-exporter.fullname" . }} + labels: + {{- include "prometheus-prefect-exporter.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "prometheus-prefect-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/prometheus-prefect-exporter/templates/service.yaml b/charts/prometheus-prefect-exporter/templates/service.yaml new file mode 100644 index 0000000..49f110a --- /dev/null +++ b/charts/prometheus-prefect-exporter/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "prometheus-prefect-exporter.fullname" . }} + labels: + {{- include "prometheus-prefect-exporter.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: {{ .Values.service.targetPort | default .Values.service.port }} + protocol: TCP + name: http + selector: + {{- include "prometheus-prefect-exporter.selectorLabels" . | nindent 4 }} diff --git a/charts/prometheus-prefect-exporter/templates/serviceaccount.yaml b/charts/prometheus-prefect-exporter/templates/serviceaccount.yaml new file mode 100644 index 0000000..24287b2 --- /dev/null +++ b/charts/prometheus-prefect-exporter/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "prometheus-prefect-exporter.serviceAccountName" . }} + labels: + {{- include "prometheus-prefect-exporter.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/prometheus-prefect-exporter/templates/servicemonitor.yaml b/charts/prometheus-prefect-exporter/templates/servicemonitor.yaml new file mode 100644 index 0000000..e490c74 --- /dev/null +++ b/charts/prometheus-prefect-exporter/templates/servicemonitor.yaml @@ -0,0 +1,24 @@ +{{- if .Values.serviceMonitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ include "prometheus-prefect-exporter.fullname" . }} + labels: + {{- include "prometheus-prefect-exporter.labels" . | nindent 4 }} +spec: + selector: + matchLabels: + {{- include "prometheus-prefect-exporter.selectorLabels" . | nindent 8 }} + endpoints: + - port: http + interval: {{ .Values.serviceMonitor.interval | quote }} + scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout | quote }} + {{- if .Values.serviceMonitor.metricRelabelings }} + metricRelabelings: + {{- toYaml .Values.serviceMonitor.metricRelabelings | nindent 4 }} + {{- end }} + {{- if .Values.serviceMonitor.relabelings }} + relabelings: + {{- toYaml .Values.serviceMonitor.relabelings | nindent 4 }} + {{- end }} +{{- end -}} diff --git a/charts/prometheus-prefect-exporter/templates/tests/test-connection.yaml b/charts/prometheus-prefect-exporter/templates/tests/test-connection.yaml new file mode 100644 index 0000000..e3d2a40 --- /dev/null +++ b/charts/prometheus-prefect-exporter/templates/tests/test-connection.yaml @@ -0,0 +1,17 @@ +{{- if .Values.testConnection }} +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "prometheus-prefect-exporter.fullname" . }}-test-connection" + labels: + {{- include "prometheus-prefect-exporter.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "prometheus-prefect-exporter.fullname" . }}:{{ .Values.service.targetPort | default .Values.service.port }}'] + restartPolicy: Never +{{- end }} \ No newline at end of file diff --git a/charts/prometheus-prefect-exporter/values.yaml b/charts/prometheus-prefect-exporter/values.yaml new file mode 100644 index 0000000..965669e --- /dev/null +++ b/charts/prometheus-prefect-exporter/values.yaml @@ -0,0 +1,119 @@ +# -- Number of replicas +replicaCount: 1 + +# -- Image registry +image: + repository: devopsiaci/prometheus-prefect-exporter + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +# -- String to partially override prometheus-prefect-exporter.fullname template (will maintain the release name) +nameOverride: "" + +# -- String to fully override prometheus-prefect-exporter.fullname template +fullnameOverride: "" + +# -- Global Docker registry secret names as an array +imagePullSecrets: [] + +# -- Enable creation of ServiceAccount +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: "" + +# -- Environment variables to configure application +env: {} + # Plain vars + # foo: bar + # my_env: my_value + +# -- Pod annotations +podAnnotations: {} + +# -- To specify security settings for a Pod +podSecurityContext: {} + # fsGroup: 2000 + +# -- Defines privilege and access control settings for a Pod or Container +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +# -- Kubernetes servide to expose Pod +service: + # -- Kubernetes Service type. Allowed values: NodePort, LoadBalancer or ClusterIP + type: ClusterIP + # -- Kubernetes Service port + port: 80 + # -- Pod expose port + targetPort: 8000 + +# -- Enable ServiceMonitor to get metrics +# ref: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#servicemonitor +serviceMonitor: + # -- Enable or disable + enabled: false + interval: 30s + scrapeTimeout: 10s + metricRelabelings: [] + relabelings: [] + +# -- Enable livenessProbe and readinessProbe +testConnection: false + +# -- Ingress configuration to expose app +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +# -- The resources limits and requested +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 + +# -- Autoscaling with CPU or memory utilization percentage +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +# -- Node labels for pod assignment +nodeSelector: {} + +# -- Tolerations for pod assignment +tolerations: [] + +# -- Affinity for pod assignment +affinity: {}