From 446fb7c2f927e3de6af840fe7cf65bae61a2624e Mon Sep 17 00:00:00 2001 From: Varac <varac@varac.net> Date: Fri, 22 Jan 2021 20:16:42 +0100 Subject: [PATCH] Add restic-rest-server from https://github.com/edjmao/charts/tree/master/rest-server --- restic-rest-server/.helmignore | 23 ++++++ restic-rest-server/Chart.yaml | 21 +++++ restic-rest-server/README.md | 60 +++++++++++++++ restic-rest-server/templates/NOTES.txt | 21 +++++ restic-rest-server/templates/_helpers.tpl | 63 +++++++++++++++ restic-rest-server/templates/deployment.yaml | 76 ++++++++++++++++++ restic-rest-server/templates/ingress.yaml | 41 ++++++++++ restic-rest-server/templates/service.yaml | 15 ++++ .../templates/serviceaccount.yaml | 12 +++ .../templates/tests/test-connection.yaml | 15 ++++ restic-rest-server/values.yaml | 77 +++++++++++++++++++ 11 files changed, 424 insertions(+) create mode 100644 restic-rest-server/.helmignore create mode 100644 restic-rest-server/Chart.yaml create mode 100644 restic-rest-server/README.md create mode 100644 restic-rest-server/templates/NOTES.txt create mode 100644 restic-rest-server/templates/_helpers.tpl create mode 100644 restic-rest-server/templates/deployment.yaml create mode 100644 restic-rest-server/templates/ingress.yaml create mode 100644 restic-rest-server/templates/service.yaml create mode 100644 restic-rest-server/templates/serviceaccount.yaml create mode 100644 restic-rest-server/templates/tests/test-connection.yaml create mode 100644 restic-rest-server/values.yaml diff --git a/restic-rest-server/.helmignore b/restic-rest-server/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/restic-rest-server/.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/restic-rest-server/Chart.yaml b/restic-rest-server/Chart.yaml new file mode 100644 index 0000000..2feb1e2 --- /dev/null +++ b/restic-rest-server/Chart.yaml @@ -0,0 +1,21 @@ +apiVersion: v2 +name: rest-server +description: Restic Rest Server for remote backups via HTTP + +# 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. +version: 0.1.1 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. +appVersion: 0.9.7 diff --git a/restic-rest-server/README.md b/restic-rest-server/README.md new file mode 100644 index 0000000..7a655f2 --- /dev/null +++ b/restic-rest-server/README.md @@ -0,0 +1,60 @@ +# Restic Rest Server + +[Restic](https://restic.net) is a backup program that fast, secure, and efficient. [Restic Rest Server](https://github.com/restic/rest-server) is a high performance HTTP server that implements restic's REST backend API. + +## Introduction + +## Prerequisites + +## Installing the Chart + +Make sure you have the repository enabled, then install the `rest-server` chart. + +```shell script +helm repo add edjmao https://edjmao.github.io/charts/pkg +helm repo update +helm install edjmao/rest-server +``` + +## Configuration + +By default, this chart does not provide persistent storage, so any backups made to the system will be saved to an `emptyDir` volume. It is recommended that you enable persistent storage to ensure that your data is backed up safely. + +The following table lists common configurable parameters of the chart and their default values. See values.yaml for all available options. + +| Parameter | Description | Default | +| --------------------------------------- | --------------------------------------------------------------------------- | ------------------------------------ | +| `image.pullPolicy` | Container pull policy | `IfNotPresent` | +| `image.repository` | Container image to use | `restic/rest-server` | +| `image.tag` | Container image tag to deploy | `0.9.7` | +| `persistence.enabled` | Whether to use a PVC for persistent storage | `false` | +| `persistence.existingClaim` | The name of a PVC to use | `""` | +| `persistence.subPath` | If set, mount the subdirectory as the root for backups. Useful for PVCs handling multiple instances.| `""` | +| `service.type` | Kubernetes Service type | `ClusterIP` | +| `service.clusterIP` | Static clusterIP or None for headless services | `nil` | +| `options.disableAuthentication` | Disable HTTP basic authentication | `false` | +| `ingress.enabled` | Enable ingress controller resource | `false` | +| `ingress.annotations` | Ingress annotations | `[]` | +| `ingress.labels` | Ingress labels | `[]` | +| `ingress.hosts[0].host` | Hostname for the ingress | `` | +| `ingress.hosts[0].path` | Path within the url structure | `` | +| `ingress.tls[0].secretName` | Name of the secret for the TLS cert | `` | +| `ingress.tls[0].hosts` | List of hostnames for the TLS cert | `[]` | + +## Authentication and User Accounts + +HTTP Basic Auth is enabled by default. This requires a user to be created to be able to access the server. Create the user by executing the following: + +```shell script +$ kubectl exec -it restic-rest-server-xxxxxxxxxx-xxxxx create_user <username> +``` + +This will prompt you for a new password. To run restic with basic auth, include it between the protocol and URL. + +```shell script +$ restic init -r rest:https://username:password@my-restic-host/my-repo +``` + +The user shall be saved in the `.htpasswd` file in the PVC and will persist across deployments (if persistence is enabled). + +To disable basic auth, set `options.disableAuthentication` to `true`. diff --git a/restic-rest-server/templates/NOTES.txt b/restic-rest-server/templates/NOTES.txt new file mode 100644 index 0000000..b4e1cc6 --- /dev/null +++ b/restic-rest-server/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 "rest-server.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 "rest-server.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "rest-server.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 "rest-server.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/restic-rest-server/templates/_helpers.tpl b/restic-rest-server/templates/_helpers.tpl new file mode 100644 index 0000000..794ad89 --- /dev/null +++ b/restic-rest-server/templates/_helpers.tpl @@ -0,0 +1,63 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "rest-server.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 "rest-server.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 "rest-server.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "rest-server.labels" -}} +helm.sh/chart: {{ include "rest-server.chart" . }} +{{ include "rest-server.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} + +{{/* +Selector labels +*/}} +{{- define "rest-server.selectorLabels" -}} +app.kubernetes.io/name: {{ include "rest-server.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end -}} + +{{/* +Create the name of the service account to use +*/}} +{{- define "rest-server.serviceAccountName" -}} +{{- if .Values.serviceAccount.create -}} + {{ default (include "rest-server.fullname" .) .Values.serviceAccount.name }} +{{- else -}} + {{ default "default" .Values.serviceAccount.name }} +{{- end -}} +{{- end -}} diff --git a/restic-rest-server/templates/deployment.yaml b/restic-rest-server/templates/deployment.yaml new file mode 100644 index 0000000..8dbaa56 --- /dev/null +++ b/restic-rest-server/templates/deployment.yaml @@ -0,0 +1,76 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "rest-server.fullname" . }} + labels: + {{- include "rest-server.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "rest-server.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "rest-server.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "rest-server.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 8000 + protocol: TCP + livenessProbe: + tcpSocket: + port: http + initialDelaySeconds: 5 + periodSeconds: 10 + readinessProbe: + tcpSocket: + port: http + initialDelaySeconds: 5 + periodSeconds: 20 + resources: + {{- toYaml .Values.resources | nindent 12 }} + env: + {{- if .Values.options.disableAuthentication }} + - name: DISABLE_AUTHENTICATION + value: "true" + {{- end }} + volumeMounts: + - name: data + mountPath: /data + {{- if .Values.persistence.subPath }} + subPath: {{ .Values.persistence.subPath }} + {{- end }} + volumes: + - name: data + {{- if .Values.persistence.existingClaim }} + persistentVolumeClaim: + claimName: {{ .Values.persistence.existingClaim }} + {{- else }} + emptyDir: {} + {{- end }} + {{- 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/restic-rest-server/templates/ingress.yaml b/restic-rest-server/templates/ingress.yaml new file mode 100644 index 0000000..0bf1b50 --- /dev/null +++ b/restic-rest-server/templates/ingress.yaml @@ -0,0 +1,41 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "rest-server.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 "rest-server.labels" . | nindent 4 }} + {{- 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: {{ $svcPort }} + {{- end }} + {{- end }} +{{- end }} diff --git a/restic-rest-server/templates/service.yaml b/restic-rest-server/templates/service.yaml new file mode 100644 index 0000000..43bfb83 --- /dev/null +++ b/restic-rest-server/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "rest-server.fullname" . }} + labels: + {{- include "rest-server.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: 8000 + protocol: TCP + name: http + selector: + {{- include "rest-server.selectorLabels" . | nindent 4 }} diff --git a/restic-rest-server/templates/serviceaccount.yaml b/restic-rest-server/templates/serviceaccount.yaml new file mode 100644 index 0000000..924268f --- /dev/null +++ b/restic-rest-server/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "rest-server.serviceAccountName" . }} + labels: + {{- include "rest-server.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end -}} diff --git a/restic-rest-server/templates/tests/test-connection.yaml b/restic-rest-server/templates/tests/test-connection.yaml new file mode 100644 index 0000000..f493d8e --- /dev/null +++ b/restic-rest-server/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "rest-server.fullname" . }}-test-connection" + labels: + {{- include "rest-server.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test-success +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "rest-server.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/restic-rest-server/values.yaml b/restic-rest-server/values.yaml new file mode 100644 index 0000000..d0b2def --- /dev/null +++ b/restic-rest-server/values.yaml @@ -0,0 +1,77 @@ +# Default values for rest-server. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: restic/rest-server + tag: "0.9.7" + pullPolicy: IfNotPresent + +imagePullSecrets: [] +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: + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: [] + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +persistence: + enabled: false + existingClaim: "" + subPath: "" + +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: {} + +options: + disableAuthentication: false \ No newline at end of file -- GitLab