Inspect the existing deny policy
Bob first inspects the NetworkPolicy that is supposed to provide a default deny for ingress in thedefault namespace:
podSelector is an empty selector ({}), and policyTypes contains Ingress.
ingress section with a rule that includes podSelector: {} under from. That empty selector matches all pods in the namespace — meaning the rule permits ingress from every pod.
In selector contexts an empty map (
{}) means “match all.” For podSelector: {} that equates to every pod in the namespace. So an explicit from: - podSelector: {} actually allows traffic from all namespace pods — which defeats a default-deny policy.default-deny-ingress was, in practice, allowing all namespace-internal ingress. Any subsequent “allow” policy would be redundant while this permissive rule exists.
Fix the default-deny baseline
To turn the resource back into a true deny-all baseline Bob keeps the same resource metadata but removes the permissive rule by settingingress to an empty list. An empty ingress: [] means “no sources are allowed”:
Be careful with
kubectl replace — it overwrites the existing resource. Use kubectl replace -f only when you intend to fully replace the live object with the file contents. If you want to create or update, kubectl apply -f is generally safer.Add specific allow rules (front-end → middleware → MySQL)
Bob creates two focused ingress policies that open only the intended paths.- Allow frontend → middleware (targets middleware pods):
ingress rules, Kubernetes treats it as an ingress policy even though policyTypes is omitted.
- Allow middleware → MySQL (targets MySQL pods):
Verify connectivity (quick Netcat checks)
Bob tests connectivity from inside pods usingnc. He uses -w1 so checks time out quickly when connections are blocked.
- From a frontend pod to the middleware service on port 80 — expected: open.
- From the frontend pod to the MySQL service on port 3306 — expected: blocked (times out).
- From a middleware pod to the MySQL service on port 3306 — expected: open.

Quick summary & best practices
- Always inspect the actual
ingress/egressrules — resource names can be misleading. podSelector: {}or omitting selector means “match all” in selector contexts.- Use
ingress: []to explicitly deny all sources for the selected pods. - Build explicit allow policies to create minimal paths (principle of least privilege).
- Test connectivity from within pods; quick TCP checks with
nc -zv -w1are helpful.