Argo CD via Cloudflare Tunnel: fixing the 502 Bad Gateway
Current router config: the live
k8s-argocd-proxy.servicelistens on30004/tcpand forwards to10.10.50.10:30004(seeansible2/router-proxy.md). The port80 → 30080example below is the older troubleshooting variant.
Symptom
http://argocd.gridzig.com (Cloudflare Tunnel → 192.168.0.250 / k8s-router,
Host header argocd.kubernetes.local) returns 502 Bad Gateway.
These DNAT rules were added on the router but did not help:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 10.10.50.10:80
iptables -t nat -A POSTROUTING -p tcp -d 10.10.50.10 --dport 80 -j MASQUERADE
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j DNAT --to-destination 10.10.50.10:443
iptables -t nat -A POSTROUTING -p tcp -d 10.10.50.10 --dport 443 -j MASQUERADE
Root causes
Wrong destination ports. Nothing listens on
10.10.50.10:80or:443. The Talos nodes expose Traefik only as a NodePort:- HTTP
30080 - HTTPS
30443
DNAT to port
80/443therefore ends at a closed port;cloudflaredsees a failed connection and Cloudflare renders a 502. Seeansible2/traefik.mdandeuro-office-nodeport.md.- HTTP
PREROUTINGdoes not see traffic generated on the router itself.cloudflaredruns on the tunnel/router appliance (as with the other*.gridzig.comtunnels). Locally-originated packets traverse theOUTPUTchain, notPREROUTING, so-i eth0never matches them. A local listener (proxy) is the reliable pattern here; the router already uses it for the other tunnels.No HTTP Ingress for Argo CD / HTTPS backend.
argocd-serveris installed by the default chart values and serves HTTPS. An HTTP Traefik Ingress with a TLS backend produces 502 unlessconfigs.params.server.insecure=trueis set, and without an Ingress containing the requested Host header Traefik returns 404.argocd.kubernetes.localis not currently in any Ingress in this repository.
Fix (recommended) — local L4 proxy on k8s-router
This matches the existing systemd-socket-proxyd / socat pattern and works
regardless of whether cloudflared connects to 127.0.0.1 or
192.168.0.250.
1. Remove the incorrect rules
sudo iptables -t nat -D PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 10.10.50.10:80
sudo iptables -t nat -D PREROUTING -i eth0 -p tcp --dport 443 -j DNAT --to-destination 10.10.50.10:443
sudo iptables -t nat -D POSTROUTING -p tcp -d 10.10.50.10 --dport 80 -j MASQUERADE
sudo iptables -t nat -D POSTROUTING -p tcp -d 10.10.50.10 --dport 443 -j MASQUERADE
sudo iptables-save | sudo tee /etc/iptables/rules.v4 # if iptables-persistent is in use
2. Forward the tunnel target port to the Traefik NodePort
Pick a node where the Traefik NodePort is reachable (curl check below); the
existing docs use 10.10.50.10 and 10.10.50.22.
sudo apt-get install -y socat
sudo tee /etc/systemd/system/k8s-argocd-proxy.service >/dev/null <<'EOF'
[Unit]
Description=Argo CD Cloudflare tunnel proxy to Traefik NodePort
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/usr/bin/socat TCP-LISTEN:80,fork,reuseaddr TCP:10.10.50.10:30080
Restart=always
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now k8s-argocd-proxy.service
sudo systemctl status k8s-argocd-proxy.service
Only forward 443 → 30443 as well if the tunnel service really uses HTTPS on
the router side. For a Cloudflare Tunnel configured as http://192.168.0.250:80
the HTTP listener above is sufficient — Cloudflare terminates TLS at the edge.
Keep eth0 NAT/DHCP from router.tf untouched; it already allows
FORWARD between eth0 and eth1 and MASQUERADEs cluster egress on eth0.
3. Make sure Traefik has an Ingress for Argo CD
kubectl -n argocd apply -f - <<'EOF'
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: argocd
namespace: argocd
spec:
ingressClassName: traefik
rules:
- host: argocd.kubernetes.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: argocd-server
port:
number: 80
- host: argocd.gridzig.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: argocd-server
port:
number: 80
EOF
Argo CD must serve plain HTTP behind Traefik (TLS is terminated at Cloudflare):
helm upgrade --install argocd oci://ghcr.io/argoproj/argo-helm/argo-cd \
--namespace argocd --reuse-values \
--set configs.params.server.insecure=true --wait
kubectl -n argocd rollout restart deploy/argocd-server
4. Tunnel settings
- Public hostname:
argocd.gridzig.com - Service:
HTTP→192.168.0.250, port80 - Host header: use
argocd.gridzig.com(recommended) or keepargocd.kubernetes.local— both hosts are now on the Ingress. Using the public name avoids Argo CD generating OAuth/callback redirects to the internal*.kubernetes.localname.
Alternative — iptables only
Use this only if cloudflared runs on a different machine (so traffic really
enters eth0), and skip step 2 above:
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 10.10.50.10:30080
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j DNAT --to-destination 10.10.50.10:30443
sudo iptables -t nat -A POSTROUTING -o eth1 -d 10.10.50.10 -p tcp --dport 30080 -j MASQUERADE
sudo iptables -t nat -A POSTROUTING -o eth1 -d 10.10.50.10 -p tcp --dport 30443 -j MASQUERADE
# If cloudflared runs on the router and targets 192.168.0.250:80:
sudo iptables -t nat -A OUTPUT -d 192.168.0.250 -p tcp --dport 80 -j DNAT --to-destination 10.10.50.10:30080
Scope MASQUERADE to -o eth1 (cluster side) instead of matching only the
destination port; that keeps reply traffic returning through the router without
rewriting unrelated flows.
Verification
Check the origin before involving Cloudflare:
# On k8s-router: the NodePort must answer with a redirect/login page
curl -sS -o /dev/null -w '%{http_code}\n' \
-H 'Host: argocd.gridzig.com' http://10.10.50.10:30080/
# expected: 200 or 302 (not 000, 404 or 502)
# Via the new local listener
curl -sS -o /dev/null -w '%{http_code}\n' \
-H 'Host: argocd.gridzig.com' http://192.168.0.250:80/
# Public URL — cache-bust, Cloudflare can serve a stale cached 502
curl -sS -o /dev/null -w '%{http_code}\n' \
"https://argocd.gridzig.com/?nocache=$(date +%s)"
Also confirm the ingress rule and Argo CD pod are healthy:
kubectl -n argocd get ingress argocd
kubectl -n argocd get pods -l app.kubernetes.io/name=argocd-server
kubectl -n traefik logs deploy/traefik --tail=50