Skip to main content
So far Bob has written rules that answer one question: who may come in? Those were ingress rules, protecting pods from incoming connections. But that’s only half the story. What stops a pod from sending traffic wherever it wants? Right now, nothing. If an attacker compromises a pod — for example, the web pod from earlier — they can open outbound connections to internet servers and exfiltrate data. Ingress rules won’t stop that because ingress only controls traffic coming to Bob’s pods. The outbound direction has its own name: egress. Egress is simply traffic leaving a pod — the opposite of ingress.
A diagram titled "Egress – Traffic Leaving a Pod" showing a pod (labeled pod-b in the default namespace) sending outbound traffic to an Internet server. The graphic also shows a user "Bob" and an in/out policy checkbox inside the pod boundary.
An egress policy decides where a pod may send traffic. Think of it as a second fence that prevents data from leaking out accidentally. Summary: how egress policies compare to ingress policies The syntax is almost identical to the ingress policies Bob already knows:
  • In policyTypes list Egress (instead of Ingress).
  • Put rules under an egress array with to: destinations (instead of from:).
  • Use the same selectors (podSelector, namespaceSelector) inside the rules.
  • Only the direction changes.
Example: an ingress rule that lets frontend pods accept connections from middleware pods
The equivalent egress rule that allows frontend pods to send traffic to middleware pods

A real example Bob finds in default namespace

Bob opens a policy file called deny-egress-to-ns. Its intent is to restrict egress to the gamma namespace.
Which namespace does this allow traffic to? The namespaceSelector matches kubernetes.io/metadata.name: gamma, so it allows destinations in the gamma namespace. When Bob applies the file, Kubernetes warns him there might be errors. One common YAML mistake to watch for is capitalization of field names.
YAML and Kubernetes field names are case-sensitive. The egress key must be lowercase. Using Egress: (capitalized) under spec is invalid and will cause errors.
This policy is also too broad: it allows egress to every pod in gamma. To restrict it, add a podSelector inside the same to element to target only pods labeled role: access-admin in gamma:

DNS: a common egress requirement

Pods discover services using DNS, which typically answers on port 53 (UDP and TCP). If you restrict egress, you often still want to allow DNS queries. An example policy that explicitly permits egress to port 53 (both UDP and TCP) to any destination:
One more important behavior to remember: with no NetworkPolicies selecting a pod, that pod’s traffic is unaffected (default-allow). Only when a NetworkPolicy selects a pod and declares restrictions does the pod become subject to those rules.

Konoha Corp: multiple namespaces and desired egress behaviors

A new customer, Konoha Corp, runs microservices across multiple namespaces:
  • Ramen runs in genin
  • Chakra runs in jonin
  • Hokage (admin) runs in default
Shikamaru (the admin) needs three egress policies:
  • jonin-to-genin: let jonin namespace send traffic only to Ramen pods in genin.
  • genin-no-egress: block all egress from genin.
  • hokage-allow: let default (Hokage) reach both Ramen and Chakra.
A diagram titled "Two More Policies" showing three dotted boxes labeled genin, jonin, and default, each containing a small smiling blue pod (ramen, chakra, hokage). A dashed arrow shows traffic between the genin and jonin pods, with policy badges ("jonin-to-genin" and "genin-no-egress") and user icons (Bob, Shikamaru) beneath.
One final nuance: genin-no-egress needs one exception — allow DNS on port 53 (UDP and TCP). How do you express that?
  • To block all egress from a namespace: create a NetworkPolicy that selects the namespace’s pods and declares policyTypes: [Egress] with an empty egress list. A policy that selects pods and declares Egress but provides no egress rules denies all egress for those pods.
  • To allow DNS as an exception: create a separate policy in genin that permits egress to port 53 (both protocols). NetworkPolicy behavior is additive — the union of allowed traffic from all matching policies is permitted.
Example deny-all egress in genin (silence everything):
Example allow-DNS exception in genin:
Where was the original mistake? The original file used Egress: (capitalized) instead of the correct lowercase egress. And how do you let a namespace go silent except for DNS? Combine a deny-all egress policy (egress: []) with an explicit allow policy for DNS — the allowed traffic will be the union of both policies.
Quick best-practices:
  • Start by denying broad egress for sensitive namespaces, then add specific allow rules (least privilege).
  • Keep DNS and essential control-plane access explicit so pods can resolve and reach cluster services.
  • Validate YAML keys and capitalization (egress vs Egress) before applying manifests.

Useful references

Watch Video