Skip to content

Kubernetes NetworkPolicy: prove effective DNS egress

An orders worker resolves through CoreDNS in a standard cluster, with a separate NodeLocal branch; distinguish selector intersection from additive grants.

Dopstack Engineering

· 9 min read

Original conceptual route map from a workload through its configured nameserver, with a separate node-local branch showing why the first DNS hop must be identified.

Quick answer

Kubernetes NetworkPolicy DNS failures need a trace from the affected Pod to its actual resolver. Inspect the Pod’s resolver configuration, identify all policies selecting it, and check the union of their egress permissions. Allow the intended DNS path, then test both successful lookups and destinations that must remain blocked.

Kubernetes NetworkPolicy DNS failures need a trace from the affected Pod to its actual resolver. Inspect the Pod’s resolver configuration, identify all policies selecting it, and check the union of their egress permissions. Allow the intended DNS path, then test both successful lookups and destinations that must remain blocked. [1][3]

Scenario: an orders worker starts normally but cannot resolve its pricing service after an egress policy change. Its database connections already in progress look healthy, and a diagnostic Pod in another namespace resolves the name. Neither observation establishes that DNS egress works from the worker. Put the worker’s identity, resolver destination and selected policies in the same evidence record.

The case below assumes a cluster whose network plugin enforces standard Kubernetes NetworkPolicy. It first uses CoreDNS Pods reached through the cluster DNS Service, then branches for NodeLocal DNSCache. Labels, addresses and workload names are illustrative inputs. Treat the YAML as a reviewed starting point for that topology, rather than a universal DNS exception. [1][4]

Which resolver is the workload actually using?#

Start with the resolver configuration inside the failing workload. A DNS Service named kube-dns does not prove that this Pod sends packets directly to it. Kubernetes’ DNS debugging guide begins with the resolver file, and NodeLocal DNSCache introduces a node-local caching agent into the path. [3][4]

sh
# Read-only examples; substitute an existing Pod and container.
kubectl -n orders exec orders-worker -- cat /etc/resolv.conf
kubectl -n orders get pod orders-worker --show-labels
kubectl -n orders get networkpolicy -o yaml
kubectl -n kube-system get service kube-dns -o yaml
kubectl -n kube-system get pods --show-labels

Record the namespace, container, Pod UID, node, nameserver address, search domains and time of the failed request. Capture the exact name the application attempted, including whether it was fully qualified. These details make later observations comparable. A replacement Pod may have different labels or a different node-local path, even when it belongs to the same Deployment.

If the production container lacks diagnostic tools, use your organization’s approved debugging method. A separate test Pod is useful only when its namespace, policy-relevant labels and network path reproduce the failing workload. Calico’s advanced tutorial deliberately retains a test Pod throughout its policy exercise; apply that discipline to your own investigation. Do not infer equivalence from a similar image name. [5]

Make a small evidence record before changing the policy: “application lookup failed from this Pod; nameserver was this address; these egress policies selected the Pod.” Keep the application error alongside the resolver test. A successful command-line lookup can narrow the problem while leaving an application-specific resolver, proxy or configuration issue unresolved.

Separate DNS resolution from connecting to the resolved application. First ask whether the resolver answers the intended question. Then ask whether the resulting destination and application port are reachable. A DNS allow rule is permission to ask a resolver, not permission to contact every address it returns. That separation avoids a broad application-port exception being mistaken for a DNS repair.

Why can a restrictive policy still allow traffic?#

Standard NetworkPolicy grants combine as a union for each direction. A restrictive policy does not cancel another policy’s broad permission. The source’s egress and destination’s ingress also both matter for a Pod-to-Pod connection. Applying a new object therefore cannot be evaluated in isolation. [1]

Suppose an illustrative allow-observability policy already selects every Pod in orders and permits all egress. Adding worker-dns-only does not make the worker DNS-only. Its name and narrow rules are irrelevant to the existing wider grant. List every matching grant, including the policy another team owns; that list explains the access the worker actually has.

Read the target podSelector and policyTypes first. The target selector chooses Pods in the policy’s namespace; an empty selector selects all of them. Then read each peer and port rule. The API reference documents these selector fields, including the empty-selector behavior. An empty map in a target selector and an empty list of egress rules have very different jobs. [2]

Keep namespace and Pod conditions in the same peer item when you intend their intersection. Splitting them into separate list entries permits alternatives. For a DNS exception, “Pods carrying the DNS label inside the system namespace” is narrower than “any Pod in the system namespace or any DNS-labelled Pod in the policy’s namespace.” Indentation changes the access decision. [1][2]

Provider-specific policy resources need their own evaluation. Calico resources and Cilium resources can introduce controls beyond this standard API. Inventory those resources when the cluster uses them, and ask the platform owner how they interact with Kubernetes NetworkPolicy. Do not carry the standard union rule into a different policy language without checking its documentation.

A narrow CoreDNS policy for the worked case#

For the CoreDNS branch, the proposed permission selects the orders worker and permits DNS traffic to the observed DNS Pods. Before applying it, confirm the actual namespace label, DNS Pod labels, resolver path and plugin behavior. The example labels below are assumptions to verify, not names that Kubernetes promises every installation will use. [2][3]

yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: orders-worker-dns
  namespace: orders
spec:
  podSelector:
    matchLabels:
      app: orders-worker
  policyTypes:
    - Egress
  egress:
    - to:
        - namespaceSelector:
            matchLabels:
              kubernetes.io/metadata.name: kube-system
          podSelector:
            matchLabels:
              k8s-app: kube-dns
      ports:
        - protocol: UDP
          port: 53
        - protocol: TCP
          port: 53

Scenario: the worker also needs its pricing API and database. Keep those permissions in separate, explicit rules or policies that remain part of the same effective review. This DNS object is not a complete application connectivity policy. If it is the first egress-isolating policy selecting the worker, other previously permitted outbound connections may stop working. [1]

The paired selector is deliberate. Both selectors belong to the same to entry, so the destination must satisfy both. The port entries are also deliberate: the intended DNS service must support the transports your clients use. Test each expected transport explicitly rather than treating a successful small lookup as evidence for every DNS exchange. [2][3]

Service address translation introduces another reason to verify behavior. Kubernetes documents that address rewriting and policy processing can vary with the network plugin, cloud provider and Service implementation. A selector-based rule that looks correct in an abstract diagram still needs a packet observation in your actual cluster. Record that implementation detail beside the policy review. [1]

Avoid solving an uncertain destination by granting the entire system namespace on every port. That repair makes a later successful lookup ambiguous: the new permission may have allowed much more than the intended resolver. Narrowness is useful for diagnosis as well as security because it reduces the number of explanations for the changed result.

What changes when NodeLocal DNSCache is present?#

NodeLocal DNSCache changes the first hop: a caching agent runs on each node rather than every lookup following the simple workload-to-DNS-Pod picture. Its configured local listen address must be identified from the installation and the affected Pod. A CoreDNS Pod selector alone does not describe that entire route. [4]

Return to the resolver evidence. Match the nameserver address to the node-local configuration and ask the platform owner which policy mechanism controls that hop. Standard NetworkPolicy behavior involving host-network traffic is not portable enough to justify copying a generic address exception from another cluster. Capture the CNI mode, node-local setup and any host policy involved. [1][4]

Do not switch the Pod to a public resolver merely to obtain a successful lookup. That changes the experiment and may bypass internal naming, data handling or platform controls. The intended outcome is a functioning approved resolver path. A temporary alternative resolver can be a carefully scoped diagnostic comparison, but it cannot establish that the original path was repaired.

Caching also changes what a test proves. A warm response from a local cache does not exercise every upstream step. Agree with the DNS operator on a test name and method that cover the intended route without flushing shared caches or generating uncontrolled traffic. Record whether the observation came from the local agent, its upstream path, or only the client.

This branch ends with an environment-specific change proposal. If the team cannot explain the first hop and enforcement point, hold the policy mutation and gather that evidence. A narrow rule for the wrong topology is still the wrong rule, and an unexplained broad rule is difficult to maintain when the cluster changes.

How do you prove the repair without widening access?#

Verify the affected workload and include negative controls. A successful lookup proves less than a successful lookup plus continued rejection of unauthorized destinations. Keep the same Pod identity and test conditions where possible, and record replacements when the workload restarts. Review fresh observations after policy propagation rather than assuming API acceptance means dataplane completion. [1]

ObservationExpected result in this caseMeaning of a mismatch
Approved internal name through configured resolverValid answerResolver path or DNS service remains unresolved
Required application connectionSuccessful requestSeparate destination permission or application failure
Unapproved destination on an unrelated portRejectedAnother grant or enforcement gap needs investigation
DNS-labelled Pod in an unrelated namespaceNo permission from this rulePeer selectors may have been split
Existing broad egress grant removed in a test namespaceOnly intended paths remainThe narrow policy was previously masked
Decision criteria for the illustrative case

Keep negative-control fixtures in an approved test namespace. Do not create a fake DNS workload in the system namespace merely to test a selector. Instead, review the selector logic locally, then use a platform-approved test environment for packet enforcement. The test should exercise the boundary without changing the identity or availability of shared DNS.

Also identify who may change the namespace and Pod labels the rule trusts. A correct selector cannot establish a useful boundary if an unrelated workload owner can assign itself the trusted identity. Include that ownership question in the handoff to the platform team; NetworkPolicy selection and authorization to edit labels are separate parts of the design.

Use plugin flow visibility when available. With an existing, healthy Cilium/Hubble installation, inspect the CLI help and filter observations to the workload and relevant drop verdicts. Hubble’s own tutorial shows how to inspect forwarded and dropped traffic. Other plugins need their documented tools; do not install a new observability stack during a narrow policy investigation merely to match a tutorial. [6]

Save the failed probe beside the successful one, the selected policies and the final diff. Include the test time because policy propagation and workload changes can make old observations misleading. When the negative control unexpectedly succeeds, stop treating the repair as complete. Find the matching grant or enforcement difference before tightening another object at random.

For nearby symptoms, compare Service endpoint diagnosis with application resolver behavior. They answer different questions. A Service can have usable endpoints while egress is blocked, and a valid policy cannot correct an application that asks the wrong name.

Frequently asked questions#

Does a default-deny policy override an allow policy?
Standard Kubernetes NetworkPolicy permissions are additive. A default-deny object establishes isolation but does not subtract traffic another matching policy permits. Review every policy selecting the Pod in the relevant direction, plus any provider-specific policy controls. [1]
Can I test from any diagnostic Pod?
Use a diagnostic context that reproduces the failing workload’s namespace, policy-relevant labels and resolver path. A Pod elsewhere can resolve successfully while the application remains blocked. Record differences instead of treating the diagnostic image as proof of equivalent access. [3][5]
Why allow TCP as well as UDP for DNS?
The policy should cover the transports required by your resolver and clients. Test the intended DNS exchanges explicitly, including TCP where your setup uses it. A successful lookup over one transport does not establish that the other path is permitted. [2][3]
Does this policy support NodeLocal DNSCache?
The example targets observed CoreDNS Pods in a conventional path. NodeLocal DNSCache adds a node-local agent and may require different enforcement rules. Identify the configured nameserver and platform policy behavior before adapting the example; there is no universal address exception. [1][4]

Technologies

  • Kubernetes
  • NetworkPolicy
  • DNS

Sources

  1. [1]
    Network Policies, Kubernetes

    Observed 2026-11-11; English-language primary documentation. Publication/update date not listed unless stated in the source ledger; documentation is version-scoped or rolling.

  2. [2]
    NetworkPolicy API, Kubernetes

    Observed 2026-11-11; English-language primary documentation. Publication/update date not listed unless stated in the source ledger; documentation is version-scoped or rolling.

  3. [3]
    Debugging DNS Resolution, Kubernetes

    Observed 2026-11-11; English-language primary documentation. Publication/update date not listed unless stated in the source ledger; documentation is version-scoped or rolling.

  4. [4]
    NodeLocal DNSCache, Kubernetes

    Observed 2026-11-11; English-language primary documentation. Publication/update date not listed unless stated in the source ledger; documentation is version-scoped or rolling.

  5. [5]
    Calico advanced Kubernetes policy tutorial, Tigera

    Observed 2026-11-11; English-language primary documentation. Publication/update date not listed unless stated in the source ledger; documentation is version-scoped or rolling.

  6. [6]
    Inspecting Network Flows with Hubble, Cilium

    Observed 2026-11-11; English-language primary documentation. Publication/update date not listed unless stated in the source ledger; documentation is version-scoped or rolling.

Written by

Dopstack Engineering

Engineering team

The engineering team at Dopstack. Illustrative scenarios are composites written to explain a pattern, not accounts of client work.

All articles Website

Get new articles by email

Engineering notes on AI, cloud and SaaS. Occasional, never sold or shared.

Send me new Dopstack Insights articles by email. I can unsubscribe at any time. We’ll email you once to confirm. Privacy

Continue reading