How to Configure K3s Network Policy
You set up a k3s network policy by writing label rules that restrict pod traffic. K3s ships with a built-in network controller that enforces these rules across your cluster. Many teams start by letting all pods talk to each other without limits. When permissions stay that broad, one bad workload can reach every service in your cluster. How a k3s network policy works inside the cluster In a standard cluster, every pod can send packets to any other pod by default. A k3s network policy changes t
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 a k3s network policy by writing label rules that restrict pod traffic. K3s ships with a built-in network controller that enforces these rules across your cluster. Many teams start by letting all pods talk to each other without limits. When permissions stay that broad, one bad workload can reach every service in your cluster.
How a k3s network policy works inside the cluster
In a standard cluster, every pod can send packets to any other pod by default. A k3s network policy changes this open setup into a closed list of allowed paths. You start by adding plain key-value labels to your pods and namespaces. The network controller reads those labels and builds firewall rules on each cluster node. When you apply a policy to a pod group, the controller drops unlisted traffic. Only traffic that matches your ingress or egress rules can pass through the node.
Teams usually start with a default deny rule for each namespace in the cluster. This first step blocks all incoming and outgoing packets for pods in that space. Next, engineers add small rules that open specific ports between matching pod labels. For example, your web app pods can talk to database pods on one port. Background worker pods in another namespace cannot reach those database pods at all. The built-in K3s router watches the cluster API for any new pods or rule changes. As pods start or stop, the node updates its packet filter list right away.
Choosing labels and rules for pod isolation
Good pod isolation depends on clear, stable labels across every team and namespace. You should label each workload by its role, its owner, and its stage of work. Avoid sharing the same label across test apps and live apps in your cluster. If two workloads share a label, they also share the same network permissions. You must also remember to allow domain name lookups in your egress rules. If you block outbound port traffic without allowing DNS, pods cannot find other services.
You can also control traffic that enters or leaves the cluster through IP block rules. These rules let pods talk to known external servers while blocking unknown internet addresses. Teams check these rules by running test pods and attempting to reach restricted ports. If the packet drops, the node firewall is doing its job as planned.
End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What packet rules solve and what they miss
Network policies are great at stopping east-west pod traffic across your cluster nodes. They keep a compromised web pod from scanning internal services in other namespaces. They also stop test workloads from sending data to live databases by mistake. At the network layer, packet filters give you strong walls between different apps.
Still, packet rules only check network addresses, port numbers, and pod labels. They do not inspect what an engineer or service does over an allowed path. And they do not control how humans run commands through the cluster API server. Once a user has cluster role permissions, network policies cannot filter their interactive commands. A user who logs in can still read secrets or delete rows in a database. Network rules also cannot mask private fields like emails, phone numbers, or card numbers. To control human sessions and data queries, teams need controls above the packet layer.
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 proxy, a sidecar for your Kubernetes API, inline on the API connection. On every kubectl or API call an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
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, or hold risky calls for approval. On the way back, hoop.dev data masking walks JSON responses by key and masks matched values in Secrets, ConfigMaps, and pod logs in memory. View the project on GitHub.
Frequently asked questions
Does K3s support network policies out of the box?
Yes, K3s includes a built-in network policy controller in its standard setup. It reads standard Kubernetes network policy objects and enforces them using node firewall rules.
Why can pods still talk after I apply a rule?
Check that the pod labels in your rule match the target pods without typos. Also make sure the built-in network policy controller is not turned off on your nodes.
Do network policies block human kubectl commands?
No, network policies only filter pod-to-pod and pod-to-network packet traffic. Human commands go through the cluster API server and rely on role-based access rules.
Related guides
In this post