K3s Traefik Real Ip

Published
Length
3 min read

Luis Felipe Dias

All posts

You get a working k3s traefik real ip setup by turning on local traffic rules. You must also trust upstream headers or turn on the proxy protocol in your load balancer. Many teams change these cluster network settings without checking who can edit the ingress rules. When cluster roles stay too broad, any user can spoof headers or open private apps. How k3s traefik real ip forwarding works K3s runs an embedded load balancer and the Traefik ingress router by default. When outside web traffic hi

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You get a working k3s traefik real ip setup by turning on local traffic rules. You must also trust upstream headers or turn on the proxy protocol in your load balancer. Many teams change these cluster network settings without checking who can edit the ingress rules. When cluster roles stay too broad, any user can spoof headers or open private apps.

How k3s traefik real ip forwarding works

K3s runs an embedded load balancer and the Traefik ingress router by default. When outside web traffic hits a node, the cluster network changes the source address. The app inside the pod only sees the internal IP of the cluster node. This default behavior hides the true caller address from your app logs and security rules.

Teams fix this issue by changing the service traffic policy from cluster to local. A local policy tells the node to send traffic straight to the local ingress pod. This path skips extra network hops between nodes and keeps the original client IP intact. If a node has no ingress pod, it drops the traffic instead of forwarding it.

When an outside load balancer sits in front of the cluster, local rules are not enough. The outside load balancer rewrites the packet source before the packet reaches the node. In this case, teams use either forwarded HTTP headers or the TCP proxy protocol. Traefik reads these headers only when you list the load balancer IP as trusted. If you do not set trusted IPs, Traefik drops or ignores the forwarded address headers.

Why source IP logs leave a gap in cluster access

Preserving the true client IP helps your web apps log public user traffic. It lets your ingress router block bad actors or limit requests by location. It also helps security teams trace public web requests back to a specific outside network.

Still, source IP rules do not secure internal engineers or automated tools that manage the cluster. Engineers who run cluster commands or query backend databases often share a single corporate VPN IP. Even with real IP tracking, the audit log only shows that a network packet arrived. The network layer only decides which IP can reach the port and log in.

Real-Time Session Monitoring + Traefik Middleware Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Network policies cannot see what individual kubectl commands or database queries do in flight. An engineer with broad cluster roles can still read secret keys or delete production workloads. Also, static kubeconfig files and database keys stay valid even when a user switches networks. Relying on source IP checks leaves internal sessions unchecked once the user passes the ingress.

Controlling cluster commands and data queries in flight

Securing a K3s cluster requires checking every command and query, not just the client IP. Instead of handing out static admin keys, teams should tie every request to a user identity. When an engineer runs a command, the system should check their identity against fine-grained rules. High-risk actions should pause for peer review before they run on the cluster.

The same principle applies when engineers or apps query databases running inside K3s pods. Network logs may record the caller IP, but they do not inspect the data returned. Dynamic data masking rewrites matched fields like emails, phone numbers, card numbers, and national IDs in query results. This approach keeps sensitive records safe while engineers fix issues in live cluster apps.

Govern kubectl and API calls in flight

Identity providers and Kubernetes RBAC decide who logs into a cluster. They cannot redact keys inside returned JSON objects or hold a risky delete call for review. By design, hoop.dev runs as an open-source proxy, a sidecar for your Kubernetes API, checking requests and responses without replacing RBAC.

First, hoop.dev guardrails refuse banned methods, paths, or headers before they run. Next, hoop.dev data masking rewrites sensitive keys in returned Secret, ConfigMap, and log responses in memory, and writes each decision to the audit trail. Explore the repo on GitHub.

Frequently asked questions

Why do my K3s pod logs show an internal cluster IP?

K3s uses virtual network routing that replaces the client IP with the node IP. You must set the external traffic policy to local on the Traefik service to stop this.

Is trusting all forwarded headers in Traefik safe?

No, trusting all sources lets any caller send fake IP headers to your apps. You should only trust the specific IP range of your upstream load balancer.

Does real IP forwarding track what engineers do inside the cluster?

No, real IP settings only record the network address of incoming web requests. Tracking internal admin work requires identity-based logging at the Kubernetes API and database level.

The query runs. The emails stay hidden.