Clean stale VPN state synchronously before gluetun starts

Replace the upstream-recommended postStart hook, which runs
concurrently with the entrypoint and loses the race (observed: it
deleted the ip rule the restarted gluetun had just created, leaving the
container in a permanent CrashLoop behind the kill switch). A command
wrapper now removes stale table-51820 rules and the leftover tun
device deterministically before exec'ing /gluetun-entrypoint, covering
container restarts after unclean exits.
This commit is contained in:
jklein committed 2026-08-24 13:41:47 +02:00
1 parent 818a71f7b6
commit 0a5035ae83
1 file changed
+12 -11
+12 -11
View File
@@ -27,17 +27,18 @@ spec:
- name: gluetun
image: "qmcgaw/gluetun:{{ .Chart.AppVersion }}"
imagePullPolicy: IfNotPresent
# An uncleanly exited gluetun (crash, OOM, node issue) leaves its ip
# rule behind in the shared pod network namespace, and the restarted
# container then fails forever with "ip rule 101 ... file exists".
# Upstream-recommended fix for Kubernetes: drop stale rules on start.
lifecycle:
postStart:
exec:
command:
- /bin/sh
- -c
- (ip rule del table 51820; ip -6 rule del table 51820) || true
# An uncleanly exited gluetun (crash, OOM killer, node issue) leaves
# its ip rule, routing table and tun device behind in the shared pod
# network namespace, and the restarted container then fails forever
# ("adding ip rule 101 ... file exists" / silent tunnel breakage)
# while the kill switch blocks all egress. The upstream-recommended
# postStart hook is racy (it runs concurrently with the entrypoint
# and can delete the rule the new instance just created), so the
# stale state is cleaned synchronously before gluetun starts.
command:
- /bin/sh
- -c
- 'while ip rule del table 51820 2>/dev/null; do :; done; while ip -6 rule del table 51820 2>/dev/null; do :; done; ip link del tun0 2>/dev/null; exec /gluetun-entrypoint'
env:
- name: TZ
value: {{ .Values.timezone | quote }}