Try solving what looks like a simple engineering problem: you have a checkout payment service running in Kubernetes, and it should only talk to two external endpoints—the Stripe API and a GitHub webhook server. Everything else outbound needs to be locked down so an attacker who compromises a container can't exfiltrate data to a rogue server.
You open the Kubernetes NetworkPolicy spec, look at the egress section, and hit a brick wall. The built-in mechanism only filters traffic by IP addresses and CIDR masks via ipBlock. Yet Stripe, GitHub, and AWS S3 don't sit on fixed static IPs: they live behind Anycast CDNs where addresses rotate every few minutes and DNS TTLs are measured in seconds.
That leaves you with an ugly dilemma: either open your pods to the entire internet (0.0.0.0/0), or embark on a heavy cluster migration to a specialized CNI like Cilium or a full Service Mesh with Envoy sidecars in every pod.
The open-source controller fqdn-network-policy by developer Kunal solves this without the extra baggage. It introduces an FQDNNetworkPolicy resource that continuously monitors domain names and automatically generates standard NetworkPolicy rules under the hood, staying compatible with any CNI.
The Pain of Standard Egress: Why CIDR Doesn't Play Nice with the Modern Internet
In our earlier guide on Configuring Network Policies in Kubernetes, we broke down the "Default Deny" pattern and how policy rules translate into iptables.
The Linux kernel and packet filters operate at L3/L4, inspecting destination IPs. When your app calls fetch('https://api.stripe.com'):
- The app queries CoreDNS and gets the current IP (say,
3.18.12.10). - The app opens a TCP connection to that IP on port 443.
NetworkPolicy has no idea what a domain name is: it only sees an outbound SYN packet headed to 3.18.12.10. Hardcode that IP manually, and half an hour later the CDN shifts routes, traffic heads to 3.18.12.11, and payments start timing out.
MultiResolver Architecture and Automatic DNS Rebinding Protection
Written in Go with controller-runtime and miekg/dns, fqdn-network-policy runs like a classic Kubernetes operator:
- MultiResolver strategy:
Different DNS servers can return different Anycast IPs for the same domain. To prevent the pod and the controller from drifting out of sync,
fqdn-network-policyqueries four public resolvers in parallel: Cloudflare (1.1.1.1), Google (8.8.8.8), Quad9 (9.9.9.9), and OpenDNS (208.67.222.222). Merging their results covers up to 85% of CDN discrepancies. - DNS Rebinding protection:
If an external domain suddenly resolves to an internal network address (an SSRF vector), the controller automatically drops those answers, filtering out RFC1918 private subnets (
10.0.0.0/8,172.16.0.0/12,192.168.0.0/16), loopback addresses (127.0.0.0/8), and link-local ranges (169.254.0.0/16).
If an external API rotates IPs every minute and your pod's DNS cache refreshes faster than the controller, the very first request might get dropped. For fast-churning services, override the polling interval with resolutionTTLOverride.
Step-by-Step FQDNNetworkPolicy Setup and iptables Translation
You install the controller via its Helm chart with Leader Election enabled:
# Deploy the controller into the cluster
helm install fqdn-network-policy charts/fqdn-network-policy/ \
--namespace fqdn-network-policy-system \
--create-namespace \
--set replicaCount=2 \
--set leaderElection.enabled=true \
--set multiResolver.enabled=true
Next, declare your outbound rules in plain domain-name terms:
apiVersion: netsec.kunal.dev/v1alpha1
kind: FQDNNetworkPolicy
metadata:
name: allow-payment-apis
namespace: payments
spec:
mode: Enforce
podSelector:
matchLabels:
app: checkout
egress:
- match: api.stripe.com
ports:
- port: 443
protocol: TCP
- match: api.github.com
ports:
- port: 443
protocol: TCP
resolutionTTLOverride: 30
The controller picks up the CRD, resolves the domains, allows traffic to CoreDNS (port 53), and generates a standard networking.k8s.io/v1 NetworkPolicy in the same namespace:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: fqdnnp-allow-payment-apis
namespace: payments
spec:
podSelector:
matchLabels:
app: checkout
policyTypes:
- Egress
egress:
- ports:
- port: 53
protocol: UDP
- port: 53
protocol: TCP
- to:
- ipBlock:
cidr: 3.18.12.10/32
- ipBlock:
cidr: 140.82.121.6/32
ports:
- port: 443
protocol: TCP
Your network plugin (Calico, Flannel, AWS VPC CNI, or Azure CNI) picks up the generated manifest as a native policy.
Convenience vs. Security: Where the Gotchas Live
The biggest win with fqdn-network-policy is its near-zero barrier to entry. You don't have to rebuild your cluster or run memory-hungry Envoy sidecars.
Still, it pays to be realistic about the boundaries:
- It's L3/L4 filtering, not L7: The controller doesn't inspect HTTP headers or URI paths. If you need per-endpoint method validation, you'll still want an API Gateway or Service Mesh.
- Fail-Closed behavior: If the controller loses contact with upstream DNS servers, existing IPs stay valid until their cache expires, after which outbound traffic is blocked. Always run at least two replicas in production.
For the vast majority of services that simply need to lock egress down to approved SaaS APIs, this controller closes a long-standing gap in vanilla Kubernetes in about fifteen minutes.

