diff --git a/charts/zerotier-ingress-helm/.helmignore b/charts/zerotier-ingress-helm/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/zerotier-ingress-helm/.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/zerotier-ingress-helm/Chart.yaml b/charts/zerotier-ingress-helm/Chart.yaml new file mode 100644 index 0000000..87fd7d0 --- /dev/null +++ b/charts/zerotier-ingress-helm/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: zerotier-ingress-helm +description: A 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. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/charts/zerotier-ingress-helm/docker/Dockerfile b/charts/zerotier-ingress-helm/docker/Dockerfile new file mode 100644 index 0000000..e323eeb --- /dev/null +++ b/charts/zerotier-ingress-helm/docker/Dockerfile @@ -0,0 +1,6 @@ +FROM nginx:1.25.3-bookworm + +COPY ./entrypoint-ztnginx.sh /entrypoint-ztnginx.sh +COPY ./default.conf.template /default.conf.template + +ENTRYPOINT ["/entrypoint-ztnginx.sh"] diff --git a/charts/zerotier-ingress-helm/docker/default.conf.template b/charts/zerotier-ingress-helm/docker/default.conf.template new file mode 100644 index 0000000..cd140ee --- /dev/null +++ b/charts/zerotier-ingress-helm/docker/default.conf.template @@ -0,0 +1,11 @@ +server { + listen $NGINX_LISTEN_PORT; + + location / { + proxy_pass $NGINX_PROXY_ADDRESS; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} \ No newline at end of file diff --git a/charts/zerotier-ingress-helm/docker/entrypoint-ztnginx.sh b/charts/zerotier-ingress-helm/docker/entrypoint-ztnginx.sh new file mode 100755 index 0000000..3ca0156 --- /dev/null +++ b/charts/zerotier-ingress-helm/docker/entrypoint-ztnginx.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +NGINX_LISTEN_PORT="${NGINX_LISTEN_PORT:-8000}" + +if [ -z "$NGINX_PROXY_ADDRESS" ]; then + echo "Error: NGINX_PROXY_ADDRESS environment variable is not set" + exit 1 +fi + +envsubst '$NGINX_LISTEN_PORT,$NGINX_PROXY_ADDRESS' < /default.conf.template > /etc/nginx/conf.d/default.conf + +cat /etc/nginx/conf.d/default.conf + +exec /docker-entrypoint.sh nginx -g "daemon off;" diff --git a/charts/zerotier-ingress-helm/templates/NOTES.txt b/charts/zerotier-ingress-helm/templates/NOTES.txt new file mode 100644 index 0000000..e69de29 diff --git a/charts/zerotier-ingress-helm/templates/_helpers.tpl b/charts/zerotier-ingress-helm/templates/_helpers.tpl new file mode 100644 index 0000000..96ef906 --- /dev/null +++ b/charts/zerotier-ingress-helm/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "zerotier-ingress-helm.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 "zerotier-ingress-helm.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 "zerotier-ingress-helm.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "zerotier-ingress-helm.labels" -}} +helm.sh/chart: {{ include "zerotier-ingress-helm.chart" . }} +{{ include "zerotier-ingress-helm.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "zerotier-ingress-helm.selectorLabels" -}} +app.kubernetes.io/name: {{ include "zerotier-ingress-helm.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "zerotier-ingress-helm.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "zerotier-ingress-helm.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/zerotier-ingress-helm/templates/deployment.yaml b/charts/zerotier-ingress-helm/templates/deployment.yaml new file mode 100644 index 0000000..7981f24 --- /dev/null +++ b/charts/zerotier-ingress-helm/templates/deployment.yaml @@ -0,0 +1,97 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "zerotier-ingress-helm.fullname" . }} + labels: + {{- include "zerotier-ingress-helm.labels" . | nindent 4 }} +spec: + selector: + matchLabels: + {{- include "zerotier-ingress-helm.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "zerotier-ingress-helm.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "zerotier-ingress-helm.serviceAccountName" . }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.zerotier.image.repository }}:{{ .Values.zerotier.image.tag | default "1.12.2" }}" + imagePullPolicy: {{ .Values.zerotier.image.pullPolicy }} + args: + - "{{ .Values.zerotier.networkID }}" + env: + - name: ZEROTIER_IDENTITY_PUBLIC + valueFrom: + secretKeyRef: + name: {{ include "zerotier-ingress-helm.fullname" . }}-ztidentity + key: identity.public + - name: ZEROTIER_IDENTITY_SECRET + valueFrom: + secretKeyRef: + name: {{ include "zerotier-ingress-helm.fullname" . }}-ztidentity + key: identity.secret + securityContext: + privileged: true + volumeMounts: + - mountPath: /dev/net + name: dev-net + {{- with .Values.zerotier.volumeMounts }} + {{- toYaml . | nindent 12 }} + {{- end }} + - name: {{ .Chart.Name }}-nginx + image: "{{ .Values.nginx.image.repository }}:{{ .Values.nginx.image.tag | default "1.25.3-bookworm-zt" }}" + imagePullPolicy: {{ .Values.nginx.image.pullPolicy }} + env: + - name: NGINX_LISTEN_PORT + value: "{{ .Values.nginx.listenPort | default 8000 }}" + - name: NGINX_PROXY_ADDRESS + value: {{ .Values.nginx.proxyAddress }} + ports: + - name: http + containerPort: {{ .Values.nginx.listenPort }} + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.nginx.resources | nindent 12 }} + {{- with .Values.nginx.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + volumes: + - name: dev-net + hostPath: + path: /dev/net + {{- with .Values.volumes }} + {{- toYaml . | nindent 8 }} + {{- 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/charts/zerotier-ingress-helm/templates/identity-secret.yaml b/charts/zerotier-ingress-helm/templates/identity-secret.yaml new file mode 100644 index 0000000..2ea02c9 --- /dev/null +++ b/charts/zerotier-ingress-helm/templates/identity-secret.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "zerotier-ingress-helm.fullname" . }}-ztidentity + labels: + {{- include "zerotier-ingress-helm.labels" . | nindent 4 }} +type: Opaque +data: + identity.public: {{ .Values.zerotier.identity.public | b64enc }} + identity.secret: {{ .Values.zerotier.identity.secret | b64enc }} diff --git a/charts/zerotier-ingress-helm/templates/serviceaccount.yaml b/charts/zerotier-ingress-helm/templates/serviceaccount.yaml new file mode 100644 index 0000000..4a9ae7a --- /dev/null +++ b/charts/zerotier-ingress-helm/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "zerotier-ingress-helm.serviceAccountName" . }} + labels: + {{- include "zerotier-ingress-helm.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/charts/zerotier-ingress-helm/values.yaml b/charts/zerotier-ingress-helm/values.yaml new file mode 100644 index 0000000..c78c2d1 --- /dev/null +++ b/charts/zerotier-ingress-helm/values.yaml @@ -0,0 +1,99 @@ +# Default values for zerotier-ingress-helm. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +nginx: + image: + repository: zerotier/ztnginx + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + + listenPort: 8080 + # Set the proxy address + # this should be the full host/port combination: http://someservice.mynamespace.svc.cluster.local:1234 + proxyAddress: "" + + 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 + + volumeMounts: + [] + # - name: foo + # mountPath: "/etc/foo" + # readOnly: true + +zerotier: + image: + repository: zerotier/zerotier + pullPolicy: IfNotPresent + tag: "1.12.2" + + # ZeroTier Identity + # Create these values with `zerotier-idtool` + identity: + public: "" + secret: "" + + # NetworkID to join + networkID: "" + + 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 + + volumeMounts: + [] + # - name: foo + # mountPath: "/etc/foo" + # readOnly: true + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Automatically mount a ServiceAccount's API credentials? + automount: 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: {} +podLabels: {} + +# Additional volumes on the output Deployment definition. +volumes: [] +# - name: foo +# secret: +# secretName: mysecret +# optional: false + +nodeSelector: {} + +tolerations: [] + +affinity: {}