diff --git a/README.md b/README.md index 3fe3f797..0a3bf689 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,14 @@ We currently provide a few Docker images: [target/flottbot:python](https://hub.docker.com/r/target/flottbot) - Alpine image, flottbot binary, and python v3.7 installed +## Helm Chart + +To install using the [Helm](https://helm.sh/) chart located in this repo, clone this repo, create a [Kubernetes secret](https://kubernetes.io/docs/concepts/configuration/secret/) for your Slack Token in your namespace & install the chart: + +```bash + helm install helm/flottbot/ +``` + ## Available remotes | Remote | Status | Documentation | diff --git a/helm/flottbot/.helmignore b/helm/flottbot/.helmignore new file mode 100644 index 00000000..f0c13194 --- /dev/null +++ b/helm/flottbot/.helmignore @@ -0,0 +1,21 @@ +# 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 +*~ +# Various IDEs +.project +.idea/ +*.tmproj diff --git a/helm/flottbot/Chart.yaml b/helm/flottbot/Chart.yaml new file mode 100644 index 00000000..167dc899 --- /dev/null +++ b/helm/flottbot/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: A Helm chart for Kubernetes +name: flottbot +version: 0.1.0 diff --git a/helm/flottbot/templates/NOTES.txt b/helm/flottbot/templates/NOTES.txt new file mode 100644 index 00000000..9d08ce34 --- /dev/null +++ b/helm/flottbot/templates/NOTES.txt @@ -0,0 +1,19 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range .Values.ingress.hosts }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }}{{ $.Values.ingress.path }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "flottbot.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 svc -w {{ template "flottbot.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "flottbot.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + 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={{ template "flottbot.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl port-forward $POD_NAME 8080:80 +{{- end }} diff --git a/helm/flottbot/templates/_helpers.tpl b/helm/flottbot/templates/_helpers.tpl new file mode 100644 index 00000000..0128971f --- /dev/null +++ b/helm/flottbot/templates/_helpers.tpl @@ -0,0 +1,32 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "flottbot.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 "flottbot.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 "flottbot.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/helm/flottbot/templates/bot-configmap.yaml b/helm/flottbot/templates/bot-configmap.yaml new file mode 100644 index 00000000..0f544689 --- /dev/null +++ b/helm/flottbot/templates/bot-configmap.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: bot +data: + bot.yml: {{ (.Files.Get "config/bot.yml") .| quote }} \ No newline at end of file diff --git a/helm/flottbot/templates/deployment.yaml b/helm/flottbot/templates/deployment.yaml new file mode 100644 index 00000000..5c25691a --- /dev/null +++ b/helm/flottbot/templates/deployment.yaml @@ -0,0 +1,77 @@ +apiVersion: apps/v1beta2 +kind: Deployment +metadata: + name: {{ template "flottbot.fullname" . }} + labels: + app: {{ template "flottbot.name" . }} + chart: {{ template "flottbot.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app: {{ template "flottbot.name" . }} + release: {{ .Release.Name }} + template: + metadata: + labels: + app: {{ template "flottbot.name" . }} + release: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + command: ["/bin/sh", "-c", "./flottbot"] + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: SLACK_TOKEN + valueFrom: + secretKeyRef: + name: slack + key: SLACK_TOKEN + volumeMounts: + - name: bot + mountPath: /config/bot.yml + subPath: bot.yml + - name: hello-rule + mountPath: /config/rules/hello.yml + subPath: hello.yml + ports: + - containerPort: {{ .Values.service.internalPort }} + livenessProbe: + tcpSocket: + port: {{ .Values.service.internalPort }} + initialDelaySeconds: 30 + readinessProbe: + tcpSocket: + port: {{ .Values.service.internalPort }} + timeoutSeconds: 3 + initialDelaySeconds: 30 + resources: +{{ toYaml .Values.resources | indent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: +{{ toYaml . | indent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: +{{ toYaml . | indent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: +{{ toYaml . | indent 8 }} + {{- end }} + volumes: + - name: hello-rule + configMap: + name: rules + items: + - key: hello.yml + path: hello.yml + - name: bot + configMap: + name: bot + items: + - key: bot.yml + path: bot.yml \ No newline at end of file diff --git a/helm/flottbot/templates/ingress.yaml b/helm/flottbot/templates/ingress.yaml new file mode 100644 index 00000000..bf8e8d28 --- /dev/null +++ b/helm/flottbot/templates/ingress.yaml @@ -0,0 +1,38 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "flottbot.fullname" . -}} +{{- $ingressPath := .Values.ingress.path -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + app: {{ template "flottbot.name" . }} + chart: {{ template "flottbot.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +{{- with .Values.ingress.annotations }} + annotations: +{{ toYaml . | indent 4 }} +{{- end }} +spec: +{{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} +{{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ . }} + http: + paths: + - path: {{ $ingressPath }} + backend: + serviceName: {{ $fullName }} + servicePort: http + {{- end }} +{{- end }} diff --git a/helm/flottbot/templates/rules-configmap.yaml b/helm/flottbot/templates/rules-configmap.yaml new file mode 100644 index 00000000..482356bd --- /dev/null +++ b/helm/flottbot/templates/rules-configmap.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: rules +data: + hello.yml: {{ (.Files.Get "config/rules/hello.yml") .| quote }} \ No newline at end of file diff --git a/helm/flottbot/templates/service.yaml b/helm/flottbot/templates/service.yaml new file mode 100644 index 00000000..57e2b9ce --- /dev/null +++ b/helm/flottbot/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "flottbot.fullname" . }} + labels: + app: {{ template "flottbot.name" . }} + chart: {{ template "flottbot.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.externalPort }} + targetPort: {{ .Values.service.internalPort }} + protocol: TCP + name: {{ .Values.service.name }} + selector: + app: {{ template "flottbot.name" . }} + release: {{ .Release.Name }} diff --git a/helm/flottbot/values.yaml b/helm/flottbot/values.yaml new file mode 100644 index 00000000..1531baf9 --- /dev/null +++ b/helm/flottbot/values.yaml @@ -0,0 +1,47 @@ +# Default values for flottbot. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: target/flottbot + tag: latest + pullPolicy: IfNotPresent + +service: + name: flottbot + externalPort: 8080 + internalPort: 8080 + type: ClusterIP + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + path: / + hosts: + - chart-example.local + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +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 + +nodeSelector: {} + +tolerations: [] + +affinity: {}