From c5b567e477e57b3be69d06e19a44afbacd002a9a Mon Sep 17 00:00:00 2001 From: Brad Clark Date: Thu, 30 May 2019 16:34:27 -0400 Subject: [PATCH] helm chart for privatebin --- kubernetes/privatebin/.helmignore | 22 +++++++ kubernetes/privatebin/Chart.yaml | 8 +++ kubernetes/privatebin/README.md | 58 +++++++++++++++++++ kubernetes/privatebin/templates/NOTES.txt | 21 +++++++ kubernetes/privatebin/templates/_helpers.tpl | 32 ++++++++++ .../privatebin/templates/config-cm.yaml | 15 +++++ .../privatebin/templates/deployment.yaml | 58 +++++++++++++++++++ kubernetes/privatebin/templates/ingress.yaml | 39 +++++++++++++ kubernetes/privatebin/templates/service.yaml | 23 ++++++++ .../templates/tests/test-connection.yaml | 18 ++++++ kubernetes/privatebin/values.yaml | 56 ++++++++++++++++++ 11 files changed, 350 insertions(+) create mode 100644 kubernetes/privatebin/.helmignore create mode 100644 kubernetes/privatebin/Chart.yaml create mode 100644 kubernetes/privatebin/README.md create mode 100644 kubernetes/privatebin/templates/NOTES.txt create mode 100644 kubernetes/privatebin/templates/_helpers.tpl create mode 100644 kubernetes/privatebin/templates/config-cm.yaml create mode 100644 kubernetes/privatebin/templates/deployment.yaml create mode 100644 kubernetes/privatebin/templates/ingress.yaml create mode 100644 kubernetes/privatebin/templates/service.yaml create mode 100644 kubernetes/privatebin/templates/tests/test-connection.yaml create mode 100644 kubernetes/privatebin/values.yaml diff --git a/kubernetes/privatebin/.helmignore b/kubernetes/privatebin/.helmignore new file mode 100644 index 00000000..50af0317 --- /dev/null +++ b/kubernetes/privatebin/.helmignore @@ -0,0 +1,22 @@ +# 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 +.vscode/ diff --git a/kubernetes/privatebin/Chart.yaml b/kubernetes/privatebin/Chart.yaml new file mode 100644 index 00000000..48bf63fc --- /dev/null +++ b/kubernetes/privatebin/Chart.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +appVersion: "1.2.1" +description: A Helm chart for installing PrivateBin +name: privatebin +home: https://github.com/PrivateBin/PrivateBin +version: 0.2.2 +maintainers: + - name: bdashrad diff --git a/kubernetes/privatebin/README.md b/kubernetes/privatebin/README.md new file mode 100644 index 00000000..0eca4544 --- /dev/null +++ b/kubernetes/privatebin/README.md @@ -0,0 +1,58 @@ +# privatebin + +This is a kubernetes chart to deploy [PrivateBin](https://github.com/PrivateBin/PrivateBin). + +## Quick Start + +To install the privatebin chart with default options: + +```bash +cd kubernetes/ +helm install ./privatebin/ +``` + +## Installation + +1. checkout the repo and change to the kubernetes directory. + +```bash +cd kubernetes/ +``` + +1. Customize your values.yaml for your needs. Add a [custom config.php](https://github.com/PrivateBin/PrivateBin/blob/master/cfg/conf.sample.php) to change any default settings. + +1. Deploy with helm + + ```bash + helm install \ + --name your-release \ + --values your-values.yaml \ + privatebin/ + ``` + +## Configuration + +See values.yaml for full documentation + +| Parameter | Description | Default | +| --------------------------- | -------------------------------------------------- | ------------------------------------------------ | +| `replicaCount` | Number of replicas | `1` | +| `image.repository` | Container image name | `privatebin/nginx-fpm-alpine` | +| `image.tag` | Container image tag | `1.2.1` | +| `image.pullPolicy` | Container image pull policy | `IfNotPresent` | +| `nameOverride` | Name Override | `""` | +| `fullnameOverride` | FullName Override | `""` | +| `service.type` | Service type (ClusterIP, NodePort or LoadBalancer) | `ClusterIP` | +| `service.port` | Ports exposed by service | `80` | +| `service.portName` | Name of exposed port, becomes LB protocol on ELB | `http` | +| `service.annotations` | Service annotations | `{}` | +| `ingress.enabled` | Enables Ingress | `false` | +| `ingress.annotations` | Ingress annotations | `{}` | +| `ingress.hosts.host` | Ingress accepted hostnames | `privatebin.local` | +| `ingress.hosts.path` | Ingress path | `\` | +| `ingress.tls` | Ingress TLS configuration | `[]` | +| `resources` | Pod resource requests & limits | `{}` | +| `nodeSelector` | Node selector | `{}` | +| `tolerations` | Tolerations | `[]` | +| `affinity` | Affinity or Anti-Affinity | `{}` | +| `configs` | List of files to put in cfg path | `{}` | diff --git a/kubernetes/privatebin/templates/NOTES.txt b/kubernetes/privatebin/templates/NOTES.txt new file mode 100644 index 00000000..270c60f8 --- /dev/null +++ b/kubernetes/privatebin/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 "privatebin.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 "privatebin.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "privatebin.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.kubernetes.io/name={{ include "privatebin.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 port-forward $POD_NAME 8080:80 +{{- end }} diff --git a/kubernetes/privatebin/templates/_helpers.tpl b/kubernetes/privatebin/templates/_helpers.tpl new file mode 100644 index 00000000..06ba88b7 --- /dev/null +++ b/kubernetes/privatebin/templates/_helpers.tpl @@ -0,0 +1,32 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "privatebin.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 "privatebin.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 "privatebin.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/kubernetes/privatebin/templates/config-cm.yaml b/kubernetes/privatebin/templates/config-cm.yaml new file mode 100644 index 00000000..f2a25e2e --- /dev/null +++ b/kubernetes/privatebin/templates/config-cm.yaml @@ -0,0 +1,15 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "privatebin.fullname" . }}-configs + labels: + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/name: {{ include "privatebin.name" . }} + helm.sh/chart: {{ include "privatebin.chart" . }} +data: +{{- range $key, $value := .Values.configs }} + {{ $key }}: |- +{{ $value | indent 4 }} +{{- end }} diff --git a/kubernetes/privatebin/templates/deployment.yaml b/kubernetes/privatebin/templates/deployment.yaml new file mode 100644 index 00000000..200ec975 --- /dev/null +++ b/kubernetes/privatebin/templates/deployment.yaml @@ -0,0 +1,58 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "privatebin.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "privatebin.name" . }} + helm.sh/chart: {{ include "privatebin.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "privatebin.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "privatebin.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 80 + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: configs + mountPath: /srv/cfg + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + volumes: + - name: configs + configMap: + name: {{ include "privatebin.fullname" . }}-configs diff --git a/kubernetes/privatebin/templates/ingress.yaml b/kubernetes/privatebin/templates/ingress.yaml new file mode 100644 index 00000000..7e473ea4 --- /dev/null +++ b/kubernetes/privatebin/templates/ingress.yaml @@ -0,0 +1,39 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "privatebin.fullname" . -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + app.kubernetes.io/name: {{ include "privatebin.name" . }} + helm.sh/chart: {{ include "privatebin.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: +{{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} +{{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ . }} + backend: + serviceName: {{ $fullName }} + servicePort: http + {{- end }} + {{- end }} +{{- end }} diff --git a/kubernetes/privatebin/templates/service.yaml b/kubernetes/privatebin/templates/service.yaml new file mode 100644 index 00000000..6ee4753f --- /dev/null +++ b/kubernetes/privatebin/templates/service.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "privatebin.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "privatebin.name" . }} + helm.sh/chart: {{ include "privatebin.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + {{- with .Values.service.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: {{ .Values.service.portName }} + selector: + app.kubernetes.io/name: {{ include "privatebin.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/kubernetes/privatebin/templates/tests/test-connection.yaml b/kubernetes/privatebin/templates/tests/test-connection.yaml new file mode 100644 index 00000000..91ca7973 --- /dev/null +++ b/kubernetes/privatebin/templates/tests/test-connection.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "privatebin.fullname" . }}-test-connection" + labels: + app.kubernetes.io/name: {{ include "privatebin.name" . }} + helm.sh/chart: {{ include "privatebin.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + annotations: + "helm.sh/hook": test-success +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "privatebin.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/kubernetes/privatebin/values.yaml b/kubernetes/privatebin/values.yaml new file mode 100644 index 00000000..522dcaed --- /dev/null +++ b/kubernetes/privatebin/values.yaml @@ -0,0 +1,56 @@ +# Default values for privatebin. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + # https://github.com/PrivateBin/docker-nginx-fpm-alpine + repository: privatebin/nginx-fpm-alpine + tag: 1.2.1 + pullPolicy: IfNotPresent + +nameOverride: "" +fullnameOverride: "" + +service: + type: ClusterIP + port: 80 + portName: http + annotations: {} + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: privatebin.local + paths: [] + + 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: {} + +configs: {} + # config.php: |- + # ; see https://github.com/PrivateBin/PrivateBin/blob/master/cfg/conf.sample.php for config