diff --git a/.gitignore b/.gitignore index 04f63edc..0e9d884f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ __pycache__/ .env hc.sqlite hc/local_settings.py -static-collected \ No newline at end of file +static-collected +/docker/helm/healthchecks/charts/ +/docker/helm/healthchecks/Chart.lock diff --git a/docker/helm/healthchecks/.helmignore b/docker/helm/healthchecks/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/docker/helm/healthchecks/.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/docker/helm/healthchecks/Chart.yaml b/docker/helm/healthchecks/Chart.yaml new file mode 100644 index 00000000..8ac228d3 --- /dev/null +++ b/docker/helm/healthchecks/Chart.yaml @@ -0,0 +1,28 @@ +apiVersion: v2 +name: healthchecks +description: A healthchecks Helm chart for Kubernetes + +# 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. +appVersion: 1.21.0 + +dependencies: +- name: postgresql + version: ~10.3.13 + repository: "@bitnami" \ No newline at end of file diff --git a/docker/helm/healthchecks/README.md b/docker/helm/healthchecks/README.md new file mode 100644 index 00000000..0739e08c --- /dev/null +++ b/docker/helm/healthchecks/README.md @@ -0,0 +1,34 @@ + + +# Running with Helm + +This is a sample configuration for running Healthchecks with kubernetes and helm + +**Note: The Helm configuration is a recent addition, and, for the time being, +should be considered as highly experimental**. + +Note: For the sake of simplicity, the sample configuration starts a single database +pod and a single web server pod, both on the same namespace. + +## Getting Started + +* Add your configuration in the `/docker/helm/healthchecks/values.yaml` file. + As a minimum, set the following fields: + * `env.DEFAULT_FROM_EMAIL` – the "From:" address for outbound emails + * `env.EMAIL_HOST` – the SMTP server + * `env.EMAIL_HOST_PASSWORD` – the SMTP password + * `env.EMAIL_HOST_USER` – the SMTP username + * `postgresql.postgresqlPassword` – set to a random value + * 'ingress.host: healthchecks.example.com' +* Deploy to k8s with helm: + + ``` + helm repo add bitnami https://charts.bitnami.com/bitnami + helm repo update + helm dependency update docker/helm/healthchecks + helm install healthchecks docker/helm/healthchecks --create-namespace -n healthchecks + ``` + +* Open https://healthchecks.example.com in your browser and log in with + the credentials from the previous step. + diff --git a/docker/helm/healthchecks/templates/NOTES.txt b/docker/helm/healthchecks/templates/NOTES.txt new file mode 100644 index 00000000..49021c8b --- /dev/null +++ b/docker/helm/healthchecks/templates/NOTES.txt @@ -0,0 +1,21 @@ +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 }}{{ . }} + {{- 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 "healthchecks.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 "healthchecks.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "healthchecks.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 "healthchecks.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:80 +{{- end }} diff --git a/docker/helm/healthchecks/templates/_helpers.tpl b/docker/helm/healthchecks/templates/_helpers.tpl new file mode 100644 index 00000000..2f26d3a8 --- /dev/null +++ b/docker/helm/healthchecks/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "healthchecks.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 "healthchecks.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 "healthchecks.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "healthchecks.labels" -}} +helm.sh/chart: {{ include "healthchecks.chart" . }} +{{ include "healthchecks.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "healthchecks.selectorLabels" -}} +app.kubernetes.io/name: {{ include "healthchecks.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "healthchecks.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "healthchecks.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/docker/helm/healthchecks/templates/deployment.yaml b/docker/helm/healthchecks/templates/deployment.yaml new file mode 100644 index 00000000..c21e8742 --- /dev/null +++ b/docker/helm/healthchecks/templates/deployment.yaml @@ -0,0 +1,81 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "healthchecks.fullname" . }} + labels: + {{- include "healthchecks.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "healthchecks.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "healthchecks.selectorLabels" . | nindent 8 }} + spec: + serviceAccountName: {{ include "healthchecks.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:v{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: + - "bash" + - "-c" + - "while !=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "healthchecks.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if .Values.ingress.tls }} + tls: + - hosts: + - {{.Values.ingress.host | quote}} + secretName: tls + {{- end }} + rules: + - host: {{ .Values.ingress.host | quote }} + http: + paths: + - path: / + backend: + serviceName: {{ include "healthchecks.fullname" . }} + servicePort: {{ .Values.service.port }} \ No newline at end of file diff --git a/docker/helm/healthchecks/templates/secret.yml b/docker/helm/healthchecks/templates/secret.yml new file mode 100644 index 00000000..5ca3b387 --- /dev/null +++ b/docker/helm/healthchecks/templates/secret.yml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Secret +metadata: + name: secret-key +data: + {{- if .Release.IsInstall }} + secret-key: {{ randAlphaNum 20 | b64enc }} + {{ else }} + secret-key: {{ index (lookup "v1" "Secret" .Release.Namespace "secret-key").data "secret-key" }} + {{ end }} \ No newline at end of file diff --git a/docker/helm/healthchecks/templates/service.yaml b/docker/helm/healthchecks/templates/service.yaml new file mode 100644 index 00000000..04c03e90 --- /dev/null +++ b/docker/helm/healthchecks/templates/service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "healthchecks.fullname" . }} + labels: + {{- include "healthchecks.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + protocol: TCP + name: http + selector: + {{- include "healthchecks.selectorLabels" . | nindent 4 }} diff --git a/docker/helm/healthchecks/templates/serviceaccount.yaml b/docker/helm/healthchecks/templates/serviceaccount.yaml new file mode 100644 index 00000000..f1c1b381 --- /dev/null +++ b/docker/helm/healthchecks/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "healthchecks.serviceAccountName" . }} + labels: + {{- include "healthchecks.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/docker/helm/healthchecks/templates/tests/test-connection.yaml b/docker/helm/healthchecks/templates/tests/test-connection.yaml new file mode 100644 index 00000000..349583e6 --- /dev/null +++ b/docker/helm/healthchecks/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "healthchecks.fullname" . }}-test-connection" + labels: + {{- include "healthchecks.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test-success +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "healthchecks.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/docker/helm/healthchecks/values.yaml b/docker/helm/healthchecks/values.yaml new file mode 100644 index 00000000..acbbb957 --- /dev/null +++ b/docker/helm/healthchecks/values.yaml @@ -0,0 +1,122 @@ +# Default values for healthchecks. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: healthchecks/healthchecks + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +command: uwsgi /opt/healthchecks/docker/uwsgi.ini +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 + +service: + type: ClusterIP + port: 8000 + +ingress: + annotations: + kubernetes.io/ingress.class: nginx + kubernetes.io/tls-acme: "true" + cert-manager.io/cluster-issuer: letsencrypt-prod + host: healthchecks.example.com + tls: true + +resources: + limits: + cpu: 500m + memory: 512Mi + requests: + cpu: 150m + memory: 512Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +env: + ALLOWED_HOSTS: "*" + APPRISE_ENABLED: "False" + DEBUG: "False" + DEFAULT_FROM_EMAIL: healthcheck@healthchecks.example.com + DISCORD_CLIENT_ID: + DISCORD_CLIENT_SECRET: + EMAIL_HOST: + EMAIL_HOST_PASSWORD: + EMAIL_HOST_USER: + EMAIL_PORT: 587 + EMAIL_USE_TLS: "True" + EMAIL_USE_VERIFICATION: "True" + LINENOTIFY_CLIENT_ID: + LINENOTIFY_CLIENT_SECRET: + MASTER_BADGE_LABEL: Mychecks + MATRIX_ACCESS_TOKEN: + MATRIX_HOMESERVER: + MATRIX_USER_ID: + MATTERMOST_ENABLED: "True" + MSTEAMS_ENABLED: "True" + OPSGENIE_ENABLED: "True" + PAGERTREE_ENABLED: "True" + PD_APP_ID: + PD_ENABLED: "True" + PD_VENDOR_KEY: + PING_BODY_LIMIT: 10000 + PROMETHEUS_ENABLED: "True" + PUSHBULLET_CLIENT_ID: + PUSHBULLET_CLIENT_SECRET: + PUSHOVER_API_TOKEN: + PUSHOVER_EMERGENCY_EXPIRATION: 86400 + PUSHOVER_EMERGENCY_RETRY_DELAY: 300 + PUSHOVER_SUBSCRIPTION_URL: + REGISTRATION_OPEN: "False" + REMOTE_USER_HEADER: + RP_ID: + SHELL_ENABLED: "False" + SIGNAL_CLI_ENABLED: "False" + SITE_NAME: Mychecks + SLACK_CLIENT_ID: + SLACK_CLIENT_SECRET: + SLACK_ENABLED: "False" + SPIKE_ENABLED: "False" + TELEGRAM_BOT_NAME: ExampleBot + TELEGRAM_TOKEN: + TRELLO_APP_KEY: + TWILIO_ACCOUNT: + TWILIO_AUTH: + TWILIO_FROM: + TWILIO_USE_WHATSAPP: "False" + USE_PAYMENTS: "False" + VICTOROPS_ENABLED: "False" + WEBHOOKS_ENABLED: "True" + ZULIP_ENABLED: "False" + +postgresql: + postgresqlPassword: replacemerandompassword \ No newline at end of file