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 That Silently Blocks Traffic You Meant to Allow

- 27.09.26 - ErcanOPAK

☸️ The NetworkPolicy That Allowed Exactly What It Said and Nothing Else

The moment a single NetworkPolicy selects a given pod, Kubernetes switches that pod’s networking from ‘allow everything by default’ to ‘deny everything except what’s explicitly allowed’ – which means adding one narrowly-scoped policy (meant only to restrict traffic FROM a specific source) can silently start blocking completely unrelated, previously-working traffic to that same pod from every OTHER source, if that traffic was never explicitly allowed by any policy at all. Nothing about applying the new policy warns that it’s about to change the pod’s default posture this broadly.

🔎 The Problem

# Intent: restrict traffic to the "api" pods so ONLY the "frontend"
# pods can reach them, tightening up an app that used to accept
# traffic from anywhere in the cluster.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: api-allow-frontend
spec:
  podSelector:
    matchLabels:
      app: api
  policyTypes:
    - Ingress
  ingress:
    - from:
        - podSelector:
            matchLabels:
              app: frontend

# The moment this policy is applied, EVERY ingress connection to "api"
# pods that isn'"'"'t from something matching app: frontend now gets
# blocked - including the monitoring/metrics scraper, the health-check
# probe from a separate namespace, and any other legitimate consumer
# nobody thought to list, none of which were ever mentioned in this
# policy at all.

✅ Fix: Enumerate Every Legitimate Source Before Applying a Restrictive Policy

  • Before applying any new Ingress-restricting NetworkPolicy, listing every actual current consumer of the target pods (application traffic, a metrics scraper, health probes from the kubelet or a service mesh, anything in a different namespace) and explicitly allowing each one avoids the silent default-deny side effect for traffic nobody remembered to account for.
  • Applying a new policy in a non-production namespace first, then actively testing every known consumer’s connectivity against it before promoting the same manifest to production, catches a missing allow-rule directly rather than discovering it through a production incident once real traffic actually gets blocked.
  • kubectl describe networkpolicy combined with a quick check of exactly which pods/namespaces a policy’s podSelector and namespaceSelector actually match (rather than assuming from the YAML alone) confirms the rule is scoped exactly as intended – a label selector that matches more or fewer pods than expected is a common, separate way this same kind of policy goes wrong.

⚠️ Why This Is Easy to Get Wrong the First Time

  • NetworkPolicy’s default-deny-once-selected behavior is a deliberate security design choice, but it’s genuinely counterintuitive coming from a namespace where no NetworkPolicy has ever existed before – the very first policy ever applied to a given pod selector is the one most likely to silently break something, specifically because everything was implicitly allowed right up until that moment.
  • The blocked traffic often isn’t the main application flow being tested during a policy rollout – it’s a secondary, easy-to-forget consumer (monitoring, health checks, an admin tool in a different namespace) that keeps working fine for a while after the policy is applied, until whatever depends on it eventually notices something’s been silently failing.

The instant a NetworkPolicy touches a pod, everything not explicitly named in some policy is now denied by default – and a policy written to restrict one specific source can just as easily end up restricting every other source nobody thought to mention.

— Cloud Architect

Related posts:

Kubernetes: Liveness vs Readiness Probes - Don't Kill Your Traffic

Kubernetes: Liveness vs Readiness Probes - Don't Kill Your Traffic

Kubernetes Services Work Internally but Fail Externally

Kubernetes Services Work Internally but Fail Externally

Kubernetes: Use Init Containers for Setup Tasks Before App Starts

Kubernetes: Use Init Containers for Setup Tasks Before App Starts

Views: 16
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

C#: Fix a Null-Forgiving Operator That’s Hiding a Genuine Null Reference Bug
Windows 11: Fix a Laptop That Refuses to Charge Past a Fixed Percentage

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 997 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 996 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 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 672 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 631 views
  8. 08Average of all values in a column that are not zero in SQL 585 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 562 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