From d6a96b339977b250941b11d811cb83d9d466f5d1 Mon Sep 17 00:00:00 2001 From: mihma Date: Thu, 20 Jul 2023 21:12:43 +0100 Subject: [PATCH] add wireguard chart --- charts/wireguard/.helmignore | 23 +++++++ charts/wireguard/Chart.yaml | 18 ++++++ charts/wireguard/templates/_helpers.tpl | 62 ++++++++++++++++++ charts/wireguard/templates/configmap.yaml | 16 +++++ charts/wireguard/templates/deployment.yaml | 63 +++++++++++++++++++ charts/wireguard/templates/pvc.yaml | 13 ++++ charts/wireguard/templates/service.yaml | 15 +++++ .../wireguard/templates/serviceaccount.yaml | 12 ++++ charts/wireguard/values.yaml | 55 ++++++++++++++++ 9 files changed, 277 insertions(+) create mode 100644 charts/wireguard/.helmignore create mode 100644 charts/wireguard/Chart.yaml create mode 100644 charts/wireguard/templates/_helpers.tpl create mode 100644 charts/wireguard/templates/configmap.yaml create mode 100644 charts/wireguard/templates/deployment.yaml create mode 100644 charts/wireguard/templates/pvc.yaml create mode 100644 charts/wireguard/templates/service.yaml create mode 100644 charts/wireguard/templates/serviceaccount.yaml create mode 100644 charts/wireguard/values.yaml diff --git a/charts/wireguard/.helmignore b/charts/wireguard/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/wireguard/.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/charts/wireguard/Chart.yaml b/charts/wireguard/Chart.yaml new file mode 100644 index 0000000..17f848a --- /dev/null +++ b/charts/wireguard/Chart.yaml @@ -0,0 +1,18 @@ +apiVersion: v2 +name: wireguard +description: Helm chart for wireguard server + +# 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 diff --git a/charts/wireguard/templates/_helpers.tpl b/charts/wireguard/templates/_helpers.tpl new file mode 100644 index 0000000..a1b676d --- /dev/null +++ b/charts/wireguard/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "wireguard.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 "wireguard.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 "wireguard.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "wireguard.labels" -}} +helm.sh/chart: {{ include "wireguard.chart" . }} +{{ include "wireguard.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "wireguard.selectorLabels" -}} +app.kubernetes.io/name: {{ include "wireguard.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "wireguard.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "wireguard.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/wireguard/templates/configmap.yaml b/charts/wireguard/templates/configmap.yaml new file mode 100644 index 0000000..681b1a2 --- /dev/null +++ b/charts/wireguard/templates/configmap.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "wireguard.fullname" . }} + labels: + {{- include "wireguard.labels" . | nindent 4 }} +data: + PUID: "1000" + PGID: "1000" + TZ: {{ .Values.config.timeZone }} + SERVERURL: {{ .Values.config.serverUrl }} + SERVERPORT: "51820" + PEERS: {{ .Values.config.peers | quote }} + ALLOWEDIPS: {{ .Values.config.allowedIPs | quote }} + INTERNAL_SUBNET: {{ .Values.config.internalSubnet | quote }} + LOG_CONFS: {{ .Values.config.logConfs | quote }} diff --git a/charts/wireguard/templates/deployment.yaml b/charts/wireguard/templates/deployment.yaml new file mode 100644 index 0000000..bb84c30 --- /dev/null +++ b/charts/wireguard/templates/deployment.yaml @@ -0,0 +1,63 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "wireguard.fullname" . }} + labels: + {{- include "wireguard.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "wireguard.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "wireguard.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "wireguard.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.registry }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: IfNotPresent + ports: + - name: wg-server + containerPort: 51820 + protocol: UDP + volumeMounts: + - name: wg-config + mountPath: /config + envFrom: + - configMapRef: + name: {{ include "wireguard.fullname" . }} + env: + {{- toYaml .Values.env | nindent 12 }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumes: + - name: wg-config + persistentVolumeClaim: + claimName: {{ include "wireguard.fullname" . }} + {{- 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/charts/wireguard/templates/pvc.yaml b/charts/wireguard/templates/pvc.yaml new file mode 100644 index 0000000..b9762b5 --- /dev/null +++ b/charts/wireguard/templates/pvc.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ include "wireguard.fullname" . }} + labels: + {{- include "wireguard.labels" . | nindent 4 }} +spec: + storageClassName: {{ .Values.persistence.storageClassName }} + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .Values.persistence.storageSize }} diff --git a/charts/wireguard/templates/service.yaml b/charts/wireguard/templates/service.yaml new file mode 100644 index 0000000..36d3100 --- /dev/null +++ b/charts/wireguard/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "wireguard.fullname" . }} + labels: + {{- include "wireguard.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: 51820 + protocol: UDP + name: wg-server + selector: + {{- include "wireguard.selectorLabels" . | nindent 4 }} diff --git a/charts/wireguard/templates/serviceaccount.yaml b/charts/wireguard/templates/serviceaccount.yaml new file mode 100644 index 0000000..eb2d5f0 --- /dev/null +++ b/charts/wireguard/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "wireguard.serviceAccountName" . }} + labels: + {{- include "wireguard.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/wireguard/values.yaml b/charts/wireguard/values.yaml new file mode 100644 index 0000000..3ee7860 --- /dev/null +++ b/charts/wireguard/values.yaml @@ -0,0 +1,55 @@ +replicaCount: 1 + +config: + timeZone: Europe/Helsinki + serverUrl: "vpn.example.com" + peers: "1" + allowedIPs: "10.0.0.0/8" + internalSubnet: "10.13.13.0/24" + logConfs: "false" + +image: + registry: linuxserver/wireguard + pullPolicy: IfNotPresent + tag: "1.0.20210914" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + create: true + annotations: {} + +podAnnotations: {} + +podSecurityContext: {} + +securityContext: + capabilities: + add: + - NET_ADMIN + +persistence: + storageClassName: standard-rwo + storageSize: 10M + +service: + type: LoadBalancer + port: 51820 + +env: [] + +resources: + requests: + memory: 64Mi + cpu: 100m + limits: + memory: 512Mi + cpu: 500m + +nodeSelector: {} + +tolerations: [] + +affinity: {}