--- title: Transparent Proxy / Sidecar Mode shortTitle: Transparent Proxy description: Run MockServer as a Kubernetes sidecar with transparent proxy interception for service mesh integration. layout: page pageOrder: 3 section: 'Chaos Testing' subsection: true sitemap: priority: 0.7 changefreq: 'monthly' lastmod: 2026-06-01T08:00:00+00:00 keywords: sidecar proxy, transparent proxy, kubernetes sidecar, iptables redirect, mockserver sidecar, conntrack ---
MockServer can run as a Kubernetes sidecar with transparent HTTP proxy interception. This enables service mesh integration patterns where MockServer intercepts traffic destined for external services without any application code changes.
When transparentProxyEnabled is set to true, MockServer treats all incoming HTTP connections as proxy requests. Instead of requiring clients to send explicit HTTP CONNECT requests or configure proxy settings, it uses the Host header from each request to determine the forwarding target.
This works with Linux iptables REDIRECT rules that redirect outbound traffic to MockServer's port, making the interception completely transparent to the application.
/proc/net/nf_conntrack), which records the pre-REDIRECT destination. This works even when the Host header is missing or incorrect.Host header.| Property | Default | Description |
|---|---|---|
transparentProxyEnabled | false | Enable transparent proxy mode |
Environment variable: MOCKSERVER_TRANSPARENT_PROXY_ENABLED
Add an init container to your Pod spec to redirect outbound traffic to MockServer:
initContainers:
- name: iptables-init
image: alpine:3.19
securityContext:
capabilities:
add: ["NET_ADMIN"]
command:
- sh
- -c
- |
# RETURN first -- exclude MockServer's own egress (UID 65534) to prevent redirect loop.
# The UID must match app.runAsUser (default 65534 in the Helm chart).
iptables -t nat -I OUTPUT -m owner --uid-owner 65534 -j RETURN
# Then REDIRECT HTTP and HTTPS to MockServer
iptables -t nat -A OUTPUT -p tcp --dport 80 -j REDIRECT --to-port 1080
iptables -t nat -A OUTPUT -p tcp --dport 443 -j REDIRECT --to-port 1080
The MockServer Helm chart includes sidecar configuration values:
sidecar:
enabled: false
transparentProxy: false
iptables:
enabled: false
excludeUid: 65534 # must match app.runAsUser to prevent redirect loop
When sidecar.transparentProxy is true, the chart sets MOCKSERVER_TRANSPARENT_PROXY_ENABLED=true in the deployment.
When sidecar.iptables.enabled is true, the chart renders an init container that adds a UID-based RETURN rule (to exclude MockServer's own egress) before any REDIRECT rules, preventing an infinite redirect loop. The excludeUid must match app.runAsUser (both default to 65534).
On Linux with the nf_conntrack kernel module loaded, MockServer reads the original destination of intercepted connections from /proc/net/nf_conntrack. This provides accurate target resolution even when the Host header is absent or incorrect.
Requirements:
/proc/net/nf_conntrack must be readable-j REDIRECTIf conntrack is unavailable, MockServer automatically falls back to Host-header-based resolution with no configuration change needed.
/proc/net/nf_conntrack file is parsed per connection, capped at 200,000 lines. If the conntrack table exceeds this limit, MockServer falls back to Host-header resolution. For high-throughput production use, consider a dedicated transparent proxy.