October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Isolate AI Agent Workloads with Kubernetes NetworkPolicies

A practical guide to selecting AI-agent Pods, denying unnecessary ingress and egress, allowing required services and DNS, and testing NetworkPolicy enforcement without confusing network controls with agent authorization.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To isolate AI-agent Pods in Kubernetes, select them with a NetworkPolicy, isolate their ingress and egress, then add allow rules for only the required peers and ports. Start with default-deny, explicitly account for DNS and other platform dependencies, and test both permitted and blocked traffic in the cluster: a policy object alone does not guarantee enforcement. NetworkPolicy is a useful network-layer boundary, not agent identity, tool authorization, prompt-injection protection, or a complete execution sandbox.

What NetworkPolicy can—and cannot—control

A NetworkPolicy selects Pods in its own namespace using podSelector. An empty selector ({}) selects every Pod in that namespace; labels let you narrow the boundary to agent workloads. A policy can isolate selected Pods for ingress, egress, or both, as described in the Kubernetes NetworkPolicy API reference.

As an Amazon Associate I earn from qualifying purchases.

NetworkPolicy is a Layer 3/4 control: it governs network traffic by peer and port. It does not inherently match a hostname, HTTP path, MCP tool name, agent identity, or the intent of a model-generated action. For those controls, use an appropriate gateway, service mesh, or agent-aware authorization layer and confirm its implementation and maturity rather than assuming ordinary NetworkPolicy provides them.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How isolation and policy rules work

Pods are unrestricted in a direction until a NetworkPolicy isolates them for that direction. Once isolated, only traffic allowed by applicable policies is permitted. Kubernetes documents a local-node exception for ingress and allows reply traffic for permitted connections. See Kubernetes Network Policies for the behavioral details.

  • Ingress: A policy selects the destination Pods whose inbound traffic it governs. Its ingress peers identify allowed sources.
  • Egress: A policy selects the source Pods whose outbound traffic it governs. Its egress peers identify allowed destinations.
  • Pod-to-Pod connections: If the source is isolated for egress, its egress rules must permit the connection. If the destination is isolated for ingress, its ingress rules must also permit it.
  • Policies combine additively: Applicable ingress rules form a union, as do applicable egress rules. Policies have no ordering or deny precedence; another applicable allow rule can broaden access.

A peer can use a Pod selector, namespace selector, IP block, or supported combinations. When a single peer entry combines namespace and Pod selectors, both conditions apply: the Pod must match the Pod labels and be in a namespace matching the namespace labels. YAML indentation and nesting determine whether selectors are combined in one peer or treated as separate peers.

Choose a boundary and establish default-deny

Use labels reserved for the workload role and trust boundary, such as app: ai-agent, and verify which Pods actually carry them. A namespace-wide policy is appropriate only if every Pod in that namespace should share the same boundary. Kubernetes documents the following default-deny pattern; the first policy selects only agent Pods, while the namespace-wide alternative uses podSelector: {}.

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: agent-default-deny
  namespace: app
spec:
  podSelector:
    matchLabels:
      app: ai-agent
  policyTypes:
    - Ingress
    - Egress
  ingress: []
  egress: []

To isolate every Pod in the namespace instead, replace that policy’s podSelector with {}. Keep policyTypes explicit: an empty egress list by itself does not necessarily declare Egress as a policy type. If policyTypes is omitted, Ingress is included by default, and Egress is included when the policy has egress rules. The default-deny behavior and policy-type rules are documented in the Kubernetes Network Policies guide and API reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Add only the required communication paths

The following illustrative allow policy permits inbound traffic from a frontend Pod in a namespace labeled kubernetes.io/metadata.name: app, outbound traffic to a tool-server Pod in the same namespace, and DNS queries to matching Pods in kube-system. The workload labels, namespace, DNS labels, and ports must match the target cluster and application. In particular, verify the actual DNS Pods and service configuration rather than assuming every cluster uses the same labels or DNS destination.

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: agent-required-flows
  namespace: app
spec:
  podSelector:
    matchLabels:
      app: ai-agent
  policyTypes:
    - Ingress
    - Egress
  ingress:
    - from:
        - namespaceSelector:
            matchLabels:
              kubernetes.io/metadata.name: app
          podSelector:
            matchLabels:
              app: frontend
      ports:
        - protocol: TCP
          port: 8080
  egress:
    - to:
        - podSelector:
            matchLabels:
              app: tool-server
      ports:
        - protocol: TCP
          port: 8080
    - to:
        - namespaceSelector:
            matchLabels:
              kubernetes.io/metadata.name: kube-system
          podSelector:
            matchLabels:
              k8s-app: kube-dns
      ports:
        - protocol: UDP
          port: 53
        - protocol: TCP
          port: 53

In this example, the combined namespace and Pod selectors in each peer constrain the peer to Pods meeting both label conditions. The egress rules name the tool-server Pods and DNS Pods, not a universal service list. If the agent needs a model endpoint, telemetry collector, credential broker, or other dependency, determine its actual destination and required port from the workload design and add a narrowly scoped rule only when supported by the cluster’s policy implementation. Do not assume that allowing DNS also permits connections to the IP addresses returned by DNS.

DNS is an explicit dependency

Default-deny egress blocks DNS unless a rule permits it. The DNS example above allows UDP and TCP port 53 only to Pods in the selected namespace that carry the stated label. Confirm the DNS service’s actual namespace, backing Pod labels, and ports in your cluster; adapt the peer accordingly. A different DNS architecture may require a different allowance.

Review all policies selecting the agent Pods

The allow policy adds to the default-deny policy; it does not override it. Inspect every NetworkPolicy whose selector matches the agents. A broad rule in another applicable policy can permit traffic beyond the paths shown here, because Kubernetes does not evaluate these policies in order or give default-deny a special precedence.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Deploy and validate the policy

  1. Confirm the selector boundary. Check that intended agent Pods have the reserved labels and that unrelated Pods do not. Decide whether the policy should cover those agents only or every Pod in the namespace.
  2. Inventory dependencies. Identify required inbound callers and outbound services, ports, DNS, model endpoints, tool servers, telemetry, and credential brokers from the actual workload architecture. Avoid a guessed universal port list.
  3. Apply isolation and allow rules. Create default-deny for the desired direction or directions, then add narrow ingress and egress rules for necessary paths. Inspect the full set of policies that select the Pods.
  4. Verify enforcement support. Confirm that the cluster’s network plugin supports and enforces NetworkPolicy. The Kubernetes Application Security Checklist specifically calls out whether policy is available and enforced; creating a resource is not proof that traffic is filtered.
  5. Test allowed and denied paths. From representative agent Pods, verify that intended calls—including name resolution where needed—succeed, and that unintended ingress and egress are blocked. Repeat in the target cluster and after relevant networking or policy changes.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why network containment is not agent authorization

Network restrictions can limit reachable destinations and reduce opportunities for lateral movement or data exfiltration, but they cannot inspect prompt content or decide whether an allowed endpoint is being used safely. OWASP identifies risks including direct and indirect prompt injection, tool abuse and privilege escalation, data exfiltration, and memory poisoning in its AI Agent Security Cheat Sheet.

Pair network controls with distinct workload identities, authorization for individual tools and actions, auditing, and suitable runtime isolation. A NetworkPolicy rule permitting traffic to a tool server does not authorize every function exposed by that server. Kubernetes SIG Agentic Networking describes broader goals such as agent identity, fine-grained authorization, protocol-aware capabilities, and auditable traffic management; these are evolving project goals, not universal built-in NetworkPolicy features. See the SIG Agentic Networking introduction and verify the maturity and availability of any implementation before relying on it.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.