Browse Source

add helm

pull/542/head
ZILosoft 3 years ago
parent
commit
600e69a40e
13 changed files with 456 additions and 1 deletions
  1. +3
    -1
      .gitignore
  2. +23
    -0
      docker/helm/healthchecks/.helmignore
  3. +28
    -0
      docker/helm/healthchecks/Chart.yaml
  4. +34
    -0
      docker/helm/healthchecks/README.md
  5. +21
    -0
      docker/helm/healthchecks/templates/NOTES.txt
  6. +62
    -0
      docker/helm/healthchecks/templates/_helpers.tpl
  7. +81
    -0
      docker/helm/healthchecks/templates/deployment.yaml
  8. +31
    -0
      docker/helm/healthchecks/templates/ingress.yaml
  9. +10
    -0
      docker/helm/healthchecks/templates/secret.yml
  10. +14
    -0
      docker/helm/healthchecks/templates/service.yaml
  11. +12
    -0
      docker/helm/healthchecks/templates/serviceaccount.yaml
  12. +15
    -0
      docker/helm/healthchecks/templates/tests/test-connection.yaml
  13. +122
    -0
      docker/helm/healthchecks/values.yaml

+ 3
- 1
.gitignore View File

@ -4,4 +4,6 @@ __pycache__/
.env
hc.sqlite
hc/local_settings.py
static-collected
static-collected
/docker/helm/healthchecks/charts/
/docker/helm/healthchecks/Chart.lock

+ 23
- 0
docker/helm/healthchecks/.helmignore View File

@ -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/

+ 28
- 0
docker/helm/healthchecks/Chart.yaml View File

@ -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"

+ 34
- 0
docker/helm/healthchecks/README.md View File

@ -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.

+ 21
- 0
docker/helm/healthchecks/templates/NOTES.txt View File

@ -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 }}

+ 62
- 0
docker/helm/healthchecks/templates/_helpers.tpl View File

@ -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 }}

+ 81
- 0
docker/helm/healthchecks/templates/deployment.yaml View File

@ -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 !</dev/tcp/{{ template "common.names.fullname" . }}-postgresql/5432; do sleep 1; done; {{.Values.command}}"
env:
- name: "DB"
value: "postgres"
- name: "DB_CONN_MAX_AGE"
value: "0"
- name: "DB_HOST"
value: "{{ template "common.names.fullname" . }}-postgresql"
- name: "DB_NAME"
value: "postgres"
- name: "DB_PASSWORD"
value: {{.Values.postgresql.postgresqlPassword | quote}}
- name: "DB_PORT"
value: {{.Values.postgresql.service.port |quote}}
- name: "DB_SSLMODE"
value: "prefer"
- name: "DB_TARGET_SESSION_ATTRS"
value: "read-write"
- name: "DB_USER"
value: {{.Values.postgresql.postgresqlUsername | quote }}
- name: "PING_ENDPOINT"
value: "{{ if .Values.ingress.tls }}https://{{ else }}http://{{ end }}{{.Values.ingress.host }}/ping/"
- name: "PING_EMAIL_DOMAIN"
value: "{{.Values.ingress.host }}"
- name: "SITE_ROOT"
value: "{{ if .Values.ingress.tls }}https://{{ else }}http://{{ end }}{{.Values.ingress.host }}"
- name: "SECRET_KEY"
valueFrom:
secretKeyRef:
name: secret-key
key: secret-key
{{- range $envName, $envValue := $.Values.env }}
- name: {{ $envName | quote }}
value: {{ $envValue | quote }}
{{- 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 }}

+ 31
- 0
docker/helm/healthchecks/templates/ingress.yaml View File

@ -0,0 +1,31 @@
{{- $fullName := include "healthchecks.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if semverCompare ">=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 }}

+ 10
- 0
docker/helm/healthchecks/templates/secret.yml View File

@ -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 }}

+ 14
- 0
docker/helm/healthchecks/templates/service.yaml View File

@ -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 }}

+ 12
- 0
docker/helm/healthchecks/templates/serviceaccount.yaml View File

@ -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 }}

+ 15
- 0
docker/helm/healthchecks/templates/tests/test-connection.yaml View File

@ -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

+ 122
- 0
docker/helm/healthchecks/values.yaml View File

@ -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: [email protected]
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

Loading…
Cancel
Save