Add cloudflared remote

This commit is contained in:
2024-01-22 23:25:25 +08:00
parent 8153a1984a
commit 62ecb1cf7c
12 changed files with 153 additions and 212 deletions
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "cloudflare-tunnel-remote.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 "cloudflare-tunnel-remote.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 "cloudflare-tunnel-remote.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "cloudflare-tunnel-remote.labels" -}}
helm.sh/chart: {{ include "cloudflare-tunnel-remote.chart" . }}
{{ include "cloudflare-tunnel-remote.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "cloudflare-tunnel-remote.selectorLabels" -}}
app.kubernetes.io/name: {{ include "cloudflare-tunnel-remote.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "cloudflare-tunnel-remote.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "cloudflare-tunnel-remote.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
@@ -0,0 +1,53 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "cloudflare-tunnel-remote.fullname" . }}
labels:
{{- include "cloudflare-tunnel-remote.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
pod: cloudflared
template:
metadata:
creationTimestamp: null
annotations:
# These are here so the deployment rolls when the config or secret change.
checksum/secret: {{ .Values.cloudflare.tunnel_token | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
pod: cloudflared
spec:
serviceAccountName: {{ include "cloudflare-tunnel-remote.fullname" . }}
containers:
- name: cloudflared
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default "latest" }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- cloudflared
- tunnel
# We can regulate the cloudflared version via an image tag.
- --no-autoupdate
# In a k8s environment, the metrics server needs to listen outside the pod it runs on.
# The address 0.0.0.0:2000 allows any pod in the namespace.
- --metrics
- 0.0.0.0:2000
- run
env:
- name: TUNNEL_TOKEN
valueFrom:
secretKeyRef:
name: {{ include "cloudflare-tunnel-remote.fullname" . }}
key: tunnelToken
livenessProbe:
httpGet:
# Cloudflared has a /ready endpoint which returns 200 if and only if
# it has an active connection to the edge.
path: /ready
port: 2000
failureThreshold: 1
initialDelaySeconds: 10
periodSeconds: 10
@@ -0,0 +1,10 @@
# This credentials secret allows cloudflared to authenticate itself
# to the Cloudflare infrastructure.
apiVersion: v1
kind: Secret
metadata:
name: {{ include "cloudflare-tunnel-remote.fullname" . }}
labels:
{{- include "cloudflare-tunnel-remote.labels" . | nindent 4 }}
stringData:
tunnelToken: {{ .Values.cloudflare.tunnel_token }}
@@ -0,0 +1,12 @@
# Here we create a service account with no privileges to run the
# deployment - just in case the default service account is different.
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "cloudflare-tunnel-remote.fullname" . }}
labels:
{{- include "cloudflare-tunnel-remote.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}