How to Configure MicroK8s Network Policy

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a microk8s network policy by turning on a CNI plugin. Then you apply pod traffic rules to each namespace in your cluster. Many teams start with flat cluster networks where every pod talks to everything. When a single pod gets compromised, attackers can move across the whole cluster. Broad cluster admin roles also let engineers change or delete these rules by mistake. How a microk8s network policy works in your cluster By default, a fresh cluster lets all pods send traffic to each o

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 microk8s network policy by turning on a CNI plugin. Then you apply pod traffic rules to each namespace in your cluster. Many teams start with flat cluster networks where every pod talks to everything. When a single pod gets compromised, attackers can move across the whole cluster. Broad cluster admin roles also let engineers change or delete these rules by mistake.

How a microk8s network policy works in your cluster

By default, a fresh cluster lets all pods send traffic to each other. Any service in one namespace can reach a database pod in another namespace. To stop this, you must use a network plugin that reads policy objects. Standard plugins like Calico watch the cluster API for new traffic rules.

When you add a microk8s network policy, the plugin updates Linux kernel routing rules. Every policy uses labels to pick which pods it will protect. You start by setting a default deny rule for a specific namespace. That baseline rule blocks all incoming and outgoing packets for those pods.

Next, you write allow rules for the exact paths your apps need. You can match source pods by label or by namespace label. You can also limit traffic to specific port numbers and protocols. If a packet does not match an allow rule, the node drops it.

Teams also use IP block rules to control traffic outside the cluster. This stops pods from calling unknown external servers on the public internet. You should test each rule in a staging cluster before production rollout. A wrong label match can break talk between your web app and database.

Why pod network rules depend on strict cluster role design

A network rule only works if people cannot turn it off at will. In many teams, engineers share broad cluster admin roles to fix issues fast. Anyone with write rights to a namespace can edit or remove traffic rules. During an outage, an engineer might delete a rule to test a hunch.

If they forget to put it back, the namespace stays wide open. Native role bindings decide who can reach the cluster API. You can create read-only roles so most devs only view pod status. Still, on-call staff need write rights when a real incident hits.

End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Static admin files on laptops create another big risk for your team. If a laptop is lost, that static key gives full cluster control. Standard role checks happen only when a user first calls the API. They do not inspect the exact command payload or log terminal output.

What network rules solve and what they leave open

Pod traffic rules do a great job of blocking lateral movement between apps. They keep a frontend pod from talking to a payment database pod. They also stop rogue containers from scanning your internal network ports. Every production cluster needs these rules as a base layer of defense.

Still, network rules do not govern human engineers or automated scripts. When an engineer runs a pod shell command, traffic goes through the API. The network plugin sees valid API traffic and lets the session run. It cannot tell who the human is or what commands they type.

Once inside a pod shell, a user can read secret keys or data. They can also run database queries that return emails, phone numbers, or card numbers. Network rules only check IP addresses and ports at the packet level. They never inspect commands in flight or rewrite sensitive fields in results.

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 sits inline as an open-source proxy, a sidecar for your Kubernetes API, without replacing RBAC. On every production call from an engineer or AI agent, hoop.dev decides to pass, mask, block, or hold it for human approval.

First, hoop.dev guardrails refuse banned methods, paths, or headers before they run or hold risky deletes for review. 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 is my microk8s network policy not blocking pod traffic?

Your cluster needs an active CNI plugin that enforces network policy objects. Also check that your pod labels match the selector labels in your rule.

Do network policies block engineers from running kubectl exec?

No, pod shell sessions travel through the cluster control plane and node agent. You must use role rules and command controls to limit human shell sessions.

Should I start with ingress or egress rules first?

Start with default deny ingress rules to protect your backend services first. Add egress rules after you map out all external DNS and API calls.

The query runs. The emails stay hidden.