Skip to content

Commit 991a840

Browse files
authored
feat: add manifest helm chart (#145)
* feat: add manifest helm chart * fix: typo * feat: helm chart * feat: add github action to release helm chart --------- Co-authored-by: wencaiwulue <895703375@qq.com>
1 parent 3ad6127 commit 991a840

19 files changed

+677
-10
lines changed

.github/workflows/release.yml

+46-8
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,51 @@ jobs:
9595
labels: |
9696
report
9797
automated pr
98-
# team-reviewers: |
99-
# owners
100-
# maintainers
10198
draft: false
10299

103-
# - name: Update new version in krew-index
104-
# uses: rajatjindal/krew-release-bot@v0.0.43
105-
# with:
106-
# krew_template_file: .github/krew.yaml
107-
# debug: true
100+
release-helm-chart:
101+
name: Release KubeVPN Helm Chart
102+
needs: [ build ]
103+
runs-on: ubuntu-latest
104+
steps:
105+
- name: Helm tool installer
106+
uses: Azure/setup-helm@v1
107+
with:
108+
version: "v3.6.3"
109+
- name: Change chart version
110+
run: |
111+
VERSION=${GITHUB_REF#refs/*/}
112+
CHART_VERSION=${VERSION/#v/}
113+
sed -i "s/^appVersion:.*$/appVersion: \"${VERSION}\"/;s/^version:.*$/version: ${CHART_VERSION}/" charts/kubevpn/Chart.yaml
114+
sed -i "s/tag:.*$/tag: \"${VERSION}\"/" charts/kubevpn/values.yaml
115+
- name: Tar chart
116+
run: |
117+
tar --transform 's/^charts\/kubevpn/kubevpn/' -zcf kubevpn-chart.tar.gz charts/kubevpn
118+
shasum -a 256 kubevpn-chart.tar.gz | awk '{print $1}' > kubevpn-chart.tar.gz-SHA256
119+
- name: Download UPLOAD_URL
120+
uses: actions/download-artifact@v2
121+
with:
122+
name: UPLOAD_URL
123+
- name: Get Release UPLOAD_URL
124+
id: get_release_info
125+
run: |
126+
UploadUrl=$(cat ./UPLOAD_URL)
127+
echo "::set-output name=upload_url::$UploadUrl"
128+
- name: Upload Release Asset KubeVPN Server Chart
129+
uses: actions/upload-release-asset@v1
130+
env:
131+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
132+
with:
133+
upload_url: ${{ steps.get_release_info.outputs.upload_url }}
134+
asset_path: kubevpn-chart.tar.gz
135+
asset_name: kubevpn-chart.tar.gz
136+
asset_content_type: application/octet-stream
137+
- name: Upload Release Asset KubeVPN Chart SHA256
138+
uses: actions/upload-release-asset@v1
139+
env:
140+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
141+
with:
142+
upload_url: ${{ steps.get_release_info.outputs.upload_url }}
143+
asset_path: kubevpn-chart.tar.gz-SHA256
144+
asset_name: kubevpn-chart.tar.gz-SHA256
145+
asset_content_type: application/octet-stream

build/Dockerfile

+12-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@ ARG BASE=github.com/wencaiwulue/kubevpn
1616
RUN sed -i s@/security.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list \
1717
&& sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
1818
RUN apt-get clean && apt-get update && apt-get install -y wget dnsutils vim curl \
19-
net-tools iptables iputils-ping lsof iproute2 tcpdump binutils traceroute conntrack socat iperf3
19+
net-tools iptables iputils-ping lsof iproute2 tcpdump binutils traceroute conntrack socat iperf3 \
20+
apt-transport-https ca-certificates curl
21+
22+
RUN if [ $(uname -m) = "x86_64" ]; then \
23+
echo "The architecture is AMD64"; \
24+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && chmod +x kubectl && mv kubectl /usr/local/bin; \
25+
elif [ $(uname -m) = "aarch64" ]; then \
26+
echo "The architecture is ARM64"; \
27+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl" && chmod +x kubectl && mv kubectl /usr/local/bin; \
28+
else \
29+
echo "Unsupported architecture."; \
30+
fi
2031

2132
ENV TZ=Asia/Shanghai \
2233
DEBIAN_FRONTEND=noninteractive

build/local.Dockerfile

+12-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@ FROM ubuntu:latest
88
RUN sed -i s@/security.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list \
99
&& sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
1010
RUN apt-get clean && apt-get update && apt-get install -y wget dnsutils vim curl \
11-
net-tools iptables iputils-ping lsof iproute2 tcpdump binutils traceroute conntrack socat iperf3
11+
net-tools iptables iputils-ping lsof iproute2 tcpdump binutils traceroute conntrack socat iperf3 \
12+
apt-transport-https ca-certificates curl
13+
14+
RUN if [ $(uname -m) = "x86_64" ]; then \
15+
echo "The architecture is AMD64"; \
16+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && chmod +x kubectl && mv kubectl /usr/local/bin; \
17+
elif [ $(uname -m) = "aarch64" ]; then \
18+
echo "The architecture is ARM64"; \
19+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl" && chmod +x kubectl && mv kubectl /usr/local/bin; \
20+
else \
21+
echo "Unsupported architecture."; \
22+
fi
1223

1324
ENV TZ=Asia/Shanghai \
1425
DEBIAN_FRONTEND=noninteractive

build/test.Dockerfile

+10
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,14 @@ FROM naison/kubevpn:latest
22

33
WORKDIR /app
44

5+
RUN if [ $(uname -m) = "x86_64" ]; then \
6+
echo "The architecture is AMD64"; \
7+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && chmod +x kubectl && mv kubectl /usr/local/bin; \
8+
elif [ $(uname -m) = "aarch64" ]; then \
9+
echo "The architecture is ARM64"; \
10+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl" && chmod +x kubectl && mv kubectl /usr/local/bin; \
11+
else \
12+
echo "Unsupported architecture."; \
13+
fi
14+
515
COPY bin/kubevpn /usr/local/bin/kubevpn

charts/kubevpn/.helmignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

charts/kubevpn/Chart.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v2
2+
name: kubevpn
3+
description: A Helm chart for KubeVPN
4+
type: application
5+
version: 0.1.0
6+
appVersion: "1.16.0"

charts/kubevpn/templates/NOTES.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1. Connect to cluster network by running these commands:
2+
kubevpn connect --namespace {{ .Release.Namespace }}
3+
export POD_IP=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "kubevpn.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].status.podIP}")
4+
ping $POD_IP

charts/kubevpn/templates/_helpers.tpl

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "kubevpn.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "kubevpn.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "kubevpn.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "kubevpn.labels" -}}
37+
helm.sh/chart: {{ include "kubevpn.chart" . }}
38+
app: kubevpn-traffic-manager
39+
{{ include "kubevpn.selectorLabels" . }}
40+
{{- if .Chart.AppVersion }}
41+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
42+
{{- end }}
43+
app.kubernetes.io/managed-by: {{ .Release.Service }}
44+
{{- end }}
45+
46+
{{/*
47+
Selector labels
48+
*/}}
49+
{{- define "kubevpn.selectorLabels" -}}
50+
app.kubernetes.io/name: {{ include "kubevpn.name" . }}
51+
app.kubernetes.io/instance: {{ .Release.Name }}
52+
{{- end }}
53+
54+
{{/*
55+
Create the name of the service account to use
56+
*/}}
57+
{{- define "kubevpn.serviceAccountName" -}}
58+
{{- if .Values.serviceAccount.create }}
59+
{{- default (include "kubevpn.fullname" .) .Values.serviceAccount.name }}
60+
{{- else }}
61+
{{- default "default" .Values.serviceAccount.name }}
62+
{{- end }}
63+
{{- end }}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ include "kubevpn.fullname" . }}
5+
data:
6+
DHCP: ""
7+
DHCP6: ""
8+
ENVOY_CONFIG: ""
9+
IPv4_POOLS: "{{ .Values.cidr.pod }} {{ .Values.cidr.service }}"
10+
REF_COUNT: "0"
+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "kubevpn.fullname" . }}
5+
labels:
6+
{{- include "kubevpn.labels" . | nindent 4 }}
7+
spec:
8+
{{- if not .Values.autoscaling.enabled }}
9+
replicas: {{ .Values.replicaCount }}
10+
{{- end }}
11+
selector:
12+
matchLabels:
13+
{{- include "kubevpn.selectorLabels" . | nindent 6 }}
14+
template:
15+
metadata:
16+
{{- with .Values.podAnnotations }}
17+
annotations:
18+
{{- toYaml . | nindent 8 }}
19+
{{- end }}
20+
labels:
21+
{{- include "kubevpn.labels" . | nindent 8 }}
22+
{{- with .Values.podLabels }}
23+
{{- toYaml . | nindent 8 }}
24+
{{- end }}
25+
spec:
26+
{{- with .Values.imagePullSecrets }}
27+
imagePullSecrets:
28+
{{- toYaml . | nindent 8 }}
29+
{{- end }}
30+
serviceAccountName: {{ include "kubevpn.serviceAccountName" . }}
31+
securityContext:
32+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
33+
containers:
34+
- args:
35+
- |2-
36+
37+
sysctl -w net.ipv4.ip_forward=1
38+
sysctl -w net.ipv6.conf.all.disable_ipv6=0
39+
sysctl -w net.ipv6.conf.all.forwarding=1
40+
update-alternatives --set iptables /usr/sbin/iptables-legacy
41+
iptables -F
42+
ip6tables -F
43+
iptables -P INPUT ACCEPT
44+
ip6tables -P INPUT ACCEPT
45+
iptables -P FORWARD ACCEPT
46+
ip6tables -P FORWARD ACCEPT
47+
iptables -t nat -A POSTROUTING -s ${CIDR4} -o eth0 -j MASQUERADE
48+
ip6tables -t nat -A POSTROUTING -s ${CIDR6} -o eth0 -j MASQUERADE
49+
kubevpn serve -L "tcp://:10800" -L "tun://:8422?net=${TunIPv4}" -L "gtcp://:10801" -L "gudp://:10802" --debug=true
50+
command:
51+
- /bin/sh
52+
- -c
53+
env:
54+
- name: CIDR4
55+
value: 223.254.0.0/16
56+
- name: CIDR6
57+
value: efff:ffff:ffff:ffff::/64
58+
- name: TunIPv4
59+
value: 223.254.0.100/16
60+
- name: TunIPv6
61+
value: efff:ffff:ffff:ffff:ffff:ffff:ffff:9999/64
62+
envFrom:
63+
- secretRef:
64+
name: {{ include "kubevpn.fullname" . }}
65+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
66+
imagePullPolicy: {{ .Values.image.pullPolicy }}
67+
name: vpn
68+
ports:
69+
- containerPort: {{ .Values.service.port8422 }}
70+
name: 8422-for-udp
71+
protocol: UDP
72+
- containerPort: {{ .Values.service.port10800 }}
73+
name: 10800-for-tcp
74+
protocol: TCP
75+
resources:
76+
{{- toYaml .Values.resources | nindent 12 }}
77+
securityContext:
78+
capabilities:
79+
add:
80+
- NET_ADMIN
81+
privileged: true
82+
runAsUser: 0
83+
- args:
84+
- control-plane
85+
- --watchDirectoryFilename
86+
- /etc/envoy/envoy-config.yaml
87+
command:
88+
- kubevpn
89+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
90+
imagePullPolicy: {{ .Values.image.pullPolicy }}
91+
name: control-plane
92+
ports:
93+
- containerPort: {{ .Values.service.port9002 }}
94+
name: 9002-for-envoy
95+
protocol: TCP
96+
resources:
97+
{{- toYaml .Values.resourcesSmall | nindent 12 }}
98+
volumeMounts:
99+
- mountPath: /etc/envoy
100+
name: envoy-config
101+
readOnly: true
102+
- args:
103+
- webhook
104+
command:
105+
- kubevpn
106+
envFrom:
107+
- secretRef:
108+
name: {{ include "kubevpn.fullname" . }}
109+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
110+
imagePullPolicy: {{ .Values.image.pullPolicy }}
111+
name: webhook
112+
ports:
113+
- containerPort: 80
114+
name: 80-for-webhook
115+
protocol: TCP
116+
resources:
117+
{{- toYaml .Values.resourcesSmall | nindent 12 }}
118+
{{- with .Values.volumes }}
119+
volumes:
120+
{{- toYaml . | nindent 8 }}
121+
{{- end }}
122+
{{- with .Values.nodeSelector }}
123+
nodeSelector:
124+
{{- toYaml . | nindent 8 }}
125+
{{- end }}
126+
{{- with .Values.affinity }}
127+
affinity:
128+
{{- toYaml . | nindent 8 }}
129+
{{- end }}
130+
{{- with .Values.tolerations }}
131+
tolerations:
132+
{{- toYaml . | nindent 8 }}
133+
{{- end }}

charts/kubevpn/templates/hpa.yaml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{- if .Values.autoscaling.enabled }}
2+
apiVersion: autoscaling/v2
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ include "kubevpn.fullname" . }}
6+
labels:
7+
{{- include "kubevpn.labels" . | nindent 4 }}
8+
spec:
9+
scaleTargetRef:
10+
apiVersion: apps/v1
11+
kind: Deployment
12+
name: {{ include "kubevpn.fullname" . }}
13+
minReplicas: {{ .Values.autoscaling.minReplicas }}
14+
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
15+
metrics:
16+
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
17+
- type: Resource
18+
resource:
19+
name: cpu
20+
target:
21+
type: Utilization
22+
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
23+
{{- end }}
24+
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
25+
- type: Resource
26+
resource:
27+
name: memory
28+
target:
29+
type: Utilization
30+
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
31+
{{- end }}
32+
{{- end }}

0 commit comments

Comments
 (0)