Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
Kubernetes

Kubernetes: Fix a NetworkPolicy Silently Blocking DNS Egress

- 26.11.26 - ErcanOPAK

☸️ Kubernetes: Fix a NetworkPolicy Silently Blocking DNS Egress

With no NetworkPolicy selecting a Pod, Kubernetes allows all egress traffic by default – but the moment any NetworkPolicy’s podSelector matches that Pod, its egress switches to default-deny for everything not explicitly listed in an egress rule. DNS lookups (to kube-dns or CoreDNS, almost always on port 53 UDP and TCP) are just another egress connection that has to be allowed like any other destination, and it’s easy to write a policy listing exactly the application’s intended destinations – a database, an external API – while never thinking to list DNS, since application code doesn’t usually think of a hostname lookup as ‘a destination it talks to’ even though literally every outbound call that uses a hostname depends on it.

🔎 The Problem

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: payments-egress
spec:
  podSelector:
    matchLabels: { app: payments }
  policyTypes: [Egress]
  egress:
    - to: [{ podSelector: { matchLabels: { app: postgres } } }]
      ports: [{ protocol: TCP, port: 5432 }]
  # no rule allowing port 53 to kube-dns/CoreDNS anywhere
  # -> every hostname lookup from this pod now times out silently

✅ The Fix

  • Add an explicit egress rule allowing both UDP and TCP port 53 to the cluster’s actual DNS pods (confirm the exact labels with kubectl get pods -n kube-system -l k8s-app=kube-dns -o wide, since the namespace and labels can differ by provider) in every NetworkPolicy that restricts egress.
  • Treat DNS egress as a mandatory line in a reusable policy template or admission check for the team, rather than something each new NetworkPolicy author has to remember independently – a missing DNS rule is one of the easiest lines to forget precisely because it’s rarely a direct dependency of the application’s own code.
  • After applying any egress-restricting NetworkPolicy, test with kubectl exec <pod> — nslookup <service> before assuming the policy is complete, since a DNS failure can otherwise look identical to a broader, harder-to-diagnose application bug.

🚨 Why This Is Dangerous

A Pod that’s lost DNS resolution can still pass a liveness check that only pings a hardcoded IP, so the cluster reports it as perfectly healthy while every outbound call relying on a hostname silently times out – a failure mode that looks like ‘the app is broken’ rather than ‘this pod can no longer resolve a single name.’

An egress policy that never mentions DNS isn’t neutral about DNS – the moment it selects your pod, it’s blocking DNS too, by omission rather than by name.

— Cloud Architect

Related posts:

Kubernetes: Fix a Pod's Readiness Probe Passing While the Application Inside It Is Still Warming Up ...

Kubernetes: Fix a Pod's Readiness Probe Passing While the Application Inside It Is Still Warming Up ...

Kubernetes: Fix an Ingress TLS Certificate That Silently Falls Back to a Self-Signed Cert Because th...

Kubernetes: Fix an Ingress TLS Certificate That Silently Falls Back to a Self-Signed Cert Because th...

Kubernetes: Use Security Context to Control Pod Permissions

Kubernetes: Use Security Context to Control Pod Permissions

Views: 7
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

Git: Fix a Commit Signature Failing After a Key Expiry Rotation
Asp.Net Core: Fix Model Binding Dropping a Record’s Init Property

Leave a Reply Cancel reply

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

Most Read

  1. 01How to make theater mode the default for Youtube 1,080 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 999 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 998 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 874 views
  5. 05How to select distinct rows in a datatable in C# 869 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 673 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 632 views
  8. 08Average of all values in a column that are not zero in SQL 586 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 563 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com