Kubernetes Load Balancing

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up kubernetes load balancing by creating service rules that spread traffic across pods. These service objects direct requests from outside or inside the cluster to healthy containers. Teams often grant broad cluster roles so engineers can check and fix routing rules. Still, wide permissions let users change live traffic paths or read sensitive pod logs. How kubernetes load balancing works with cluster roles Traffic routing in a cluster relies on service definitions and endpoint contro

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 set up kubernetes load balancing by creating service rules that spread traffic across pods. These service objects direct requests from outside or inside the cluster to healthy containers. Teams often grant broad cluster roles so engineers can check and fix routing rules. Still, wide permissions let users change live traffic paths or read sensitive pod logs.

How kubernetes load balancing works with cluster roles

Traffic routing in a cluster relies on service definitions and endpoint controllers. When a request arrives, the cluster checks service rules to find healthy pods. It then spreads the network load across those running containers.

To manage these traffic rules, engineers need specific permissions in the cluster. Kubernetes role-based access control uses roles and cluster roles to hold permission sets. All rules in this system are additive, which means there are no deny rules. A standard role sets permissions inside one single namespace. A cluster role is not limited to a single namespace. It can cover cluster-wide resources like nodes, or resources across every namespace.

Teams connect users to these rules using a role binding or a cluster role binding. A role binding grants permissions inside one namespace, even if it points to a cluster role. A cluster role binding grants access across the entire cluster at once. When engineers fix traffic issues, they also ask for access to pod subresources. The API names these subresources with a slash, such as pod logs or pod exec.

How to scope permissions for traffic management

Start by separating the permissions that view traffic from the permissions that change routing. Create a namespace role that only allows reading service objects and endpoints. Bind that role to the team that monitors app health in that specific namespace.

Avoid using cluster role bindings for daily network checks. When a user gets a cluster role binding, they can touch services in every namespace. Keep write rules for load balancers inside tight role bindings per namespace. Also, split permissions for subresources like pod logs away from service edit roles. This step stops an engineer who only checks network routes from running commands inside pods.

Kubernetes RBAC: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Where native cluster access control falls short

Native roles and bindings do a good job of deciding who can reach the API. They control which user can create a service or open a shell on a pod. Still, native permissions only check access at the start of an API request.

Once a user has permission to update services or run pod commands, the check ends. The native system cannot inspect the exact command an engineer runs inside a container. It also cannot require a second person to approve a risky routing change in flight. If a pod log prints customer emails, phone numbers, or card numbers, native roles show everything. The cluster has no built-in way to rewrite matched fields in results before they appear. Teams are left with a choice between blocking engineers or giving out broad keys.

Check Kubernetes API requests and responses on the wire

Kubernetes RBAC decides who may call the API server. RBAC does not check response payloads or split listing Secret names from reading Secret values when a role grants get access. With hoop.dev, you run an open-source HTTP proxy, a sidecar for your Kubernetes API. The kubectl client changes only the server address it talks to while RBAC stays in place.

On each call, hoop.dev guardrails read the method, normalized path, and headers to refuse bad deletes or full Secret reads with a 403 error. On the way back, hoop.dev data masking walks JSON responses by key and masks matched values in Secrets, ConfigMaps, and pod logs. Every request and verdict is logged without storing bearer tokens. View the project on GitHub.

Frequently asked questions

What is the difference between a role and a cluster role for traffic rules?

A role sets permissions for services and pods inside one single namespace. A cluster role can grant permissions for resources across all namespaces or cluster-wide nodes.

Can I write a deny rule to block changes to a production load balancer?

No, permissions in native Kubernetes access control are strictly additive. You cannot write a deny rule, so you must grant only the exact permissions needed.

How do I let engineers read pod logs without giving full pod access?

Grant access to the specific log subresource in your role definition. This allows the user to read container output without permission to change or delete pods.

The query runs. The emails stay hidden.