Default deny and DNS access
Start from a flow inventory
Instead of denying traffic blindly, enumerate required connections. In this example the frontend needs the API and a resolver. The operations monitor needs the API. No new outbound API connection is required. The monitor and resolver are in separate fictional namespaces and are unisolated in this restricted exercise; real deployments must review policies in those namespaces too. This is a narrow teaching topology, not a universal baseline.
frontend -> api TCP/8080: allowfrontend -> resolver UDP/53 and TCP/53: allowmonitor -> api TCP/8080: allowother -> api TCP/8080: denyapi -> frontend new TCP/8080: denyMake isolation explicit
The baseline selects every Pod in shop-study for both directions, and contributes no permitted connections. Explicit policyTypes prevents ambiguity, especially for an egress-only policy with no rules. An empty list of rules differs from a list containing an empty rule: the latter can allow all traffic in that direction. Never install a default-deny policy into an existing namespace without an approved dependency inventory, change plan and recovery path. These files are static examples.
apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: default-deny namespace: shop-studyspec: podSelector: matchLabels: {} policyTypes: - Ingress - Egress ingress: [] egress: []Restore the application path
The frontend egress declaration permits new TCP connections to API Pods in its own namespace on port 8080. It is not sufficient by itself: the API ingress policy from the previous lesson must also allow the frontend. The separate ops-ingress policy adds monitoring access; it does not remove frontend access. A Service port can differ from its target port, so do not simply copy a Service port into a NetworkPolicy without reviewing how the data plane handles translation.
apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: frontend-egress namespace: shop-studyspec: podSelector: matchLabels: app: frontend policyTypes: - Egress egress: - to: - podSelector: matchLabels: app: api ports: - protocol: TCP port: 8080Restore the actual DNS path
A frontend may need to resolve the name of the API before contacting it. The example resolver is an ordinary Pod in dns-study, selected by namespace and app label. Allow UDP and TCP destination port 53: TCP is needed for some DNS responses and clients. The real resolver might instead be CoreDNS with different labels, NodeLocal DNSCache or an external server. Inspect the approved lab resolver configuration and data-plane documentation; the example is not a drop-in CoreDNS rule. DNS reachability does not imply the API is reachable, nor does permitting DNS limit which names a client can look up.
apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: dns-egress namespace: shop-studyspec: podSelector: matchLabels: app: frontend policyTypes: - Egress egress: - to: - namespaceSelector: matchLabels: kubernetes.io/metadata.name: dns-study podSelector: matchLabels: app: resolver ports: - protocol: UDP port: 53 - protocol: TCP port: 53Prepare rollout and rollback evidence
In an authorized disposable environment, first establish baseline connectivity and an application health control. Review the policy diffs and all required dependencies, including telemetry and startup behavior. Install required allowances and isolation in a reviewed sequence; policy convergence is asynchronous and ordering alone is not an atomic guarantee. Verify allowed and blocked new connections after convergence. Preserve the previous approved policy set for restoration, and stop the exercise if an unrelated flow is affected. Avoid broad allow-all fixes. No change is made by this lesson.
inventory -> baseline -> review -> approved isolated change -> positive/negative tests -> accept or restorePractice
Use flow-cases.json to decide whether each connection is allowed. Remove the DNS allowance in your written design, and explain why a direct Pod address and a DNS name could yield different application outcomes. Identify the two independent checks for the frontend-to-API path.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Default deny and DNS access — knowledge check
Reason about synthetic segmentation and enforcement evidence.
What does podSelector: {} select at policy top level?
What does ingress: [] contribute to ingress permissions?
Which transport choices should a typical DNS allowance consider?
What else is required besides frontend egress in the fixture?
Why inspect the actual resolver before copying the example?