CertGrid CertGrid
Hands-on Lab·Certified Kubernetes Administrator

NetworkPolicy Patterns

Allow a whole namespace, then restrict egress and watch the Pod lose DNS while still reaching the same backend by IP. That one result explains more about NetworkPolicy than any diagram, and the AND-versus-OR distinction in a from block is the bug behind most broken policies.

Services and Networking Guide 62 of 103 Advanced

The kube-dns pod label k8s-app: kube-dns is what the DNS allowance matches. Verify it on your cluster before copying.

Same four Pods as the default-deny guide, across two namespaces.
Server NameIP AddressOSRolesCPURAMHDD
CKA1001192.168.0.175Ubuntu 26.04 LTSControl Plane Node2 Core4 GB50 GB
CKA1001-NODE01192.168.0.176Ubuntu 26.04 LTSWorker Node2 Core4 GB50 GB
CKA1001-NODE02192.168.0.177Ubuntu 26.04 LTSWorker Node2 Core4 GB50 GB
CKA1001-NODE03192.168.0.178Ubuntu 26.04 LTSWorker Node2 Core4 GB50 GB

This guide includes

Use this when a policy has closed more than you intended - which usually means DNS. This matters because restricting egress breaks name resolution before it breaks anything you were actually thinking about, and the fix turns on understanding AND versus OR inside a rule.

Before you start

  1. Allow a whole namespace, and see policies add up

  2. Restrict egress, and break the Pod in an unexpected way

  3. The DNS allowance, and AND versus OR

  4. Everything back on, verified together

Official sources