Home / Azure

AzureRunbookAdvanced

Sev1: AKS services down after a NetworkPolicy change. Default-deny blocked DNS, ingress or the database

A new default-deny or tightened NetworkPolicy cut pods off from DNS, the ingress controller or their dependencies. Find the policy, restore traffic in minutes, then reapply it with the missing allow rules.

Deepak Bhardwaj5 min read

Applies toAKS with Azure Network Policy Manager, Calico or Azure CNI powered by Cilium; Kubernetes NetworkPolicy v1. Policy engine behavior differs slightly, so check your engine's docs

Symptoms

  • Right after a deployment (Helm release, GitOps sync, platform baseline), apps in one or more namespaces start failing.
  • Pods log getaddrinfo EAI_AGAIN, no such host or i/o timeout when calling other services by name.
  • Ingress returns 502/504 for the namespace; the ingress controller logs upstream connect timeouts.
  • Pods are Running, nodes are healthy, and nothing changed on the NSG, UDR or firewall.

The usual cause: a policy that selects all pods (podSelector: {}) with policyTypes: [Ingress, Egress] and no egress rule for DNS. Once any policy selects a pod for a direction, all traffic in that direction not explicitly allowed is dropped.

1. Confirm scope and impact (5 minutes)

# Which engine is enforcing policy?
az aks show -g rg-aks -n aks-prod --query "networkProfile.{plugin:networkPlugin, policy:networkPolicy, dataplane:networkDataplane}" -o table

# What policies exist and when were they created?
kubectl get networkpolicy -A --sort-by=.metadata.creationTimestamp \
  -o custom-columns=NS:.metadata.namespace,NAME:.metadata.name,CREATED:.metadata.creationTimestamp

# Calico or Cilium can also have their own policy types
kubectl get globalnetworkpolicies.crd.projectcalico.org 2>/dev/null
kubectl get ciliumnetworkpolicies -A 2>/dev/null
kubectl get ciliumclusterwidenetworkpolicies 2>/dev/null

Match the newest policies against the incident start time. Then prove it is policy and not something else:

kubectl run nettest -n app-prod --rm -it --image=busybox:1.36 --restart=Never -- \
  sh -c 'nslookup kubernetes.default.svc.cluster.local; wget -qO- -T 3 http://orders-api:8080/healthz'

If DNS fails from inside the namespace but works from a namespace with no policies, you have found it.

Tip

The test pod only carries the label run=nettest, so it is selected only by policies with podSelector: {}. That is exactly the policy shape that causes most of these outages. To test a specific app's policies, add its labels with --labels app=orders.

2. Read the policy that broke it

kubectl get networkpolicy -n app-prod default-deny -o yaml
What you see Effect Missing rule
podSelector: {}, policyTypes: [Egress], no egress: All egress dropped, including DNS Allow UDP/TCP 53 to CoreDNS
policyTypes: [Ingress], no ingress: All ingress dropped Allow from the ingress controller namespace
namespaceSelector uses a custom label Label not on the target namespace Use kubernetes.io/metadata.name
Egress allows only pod CIDRs Azure SQL, Key Vault, private endpoints blocked ipBlock for the private endpoint subnet or 0.0.0.0/0 with exceptions
Egress to the API server not allowed Operators and controllers fail Allow TCP 443 to the API server IP

3. Restore traffic now

The fastest safe mitigation is to remove or back out the new policy, not to edit it under pressure.

# Save it first, so the fix can be reapplied properly
kubectl get networkpolicy -n app-prod default-deny -o yaml > default-deny.backup.yaml

kubectl delete networkpolicy -n app-prod default-deny

If GitOps (Flux, Argo CD) owns the policy, it will put it back within minutes. Revert the commit or suspend reconciliation for that path first:

flux suspend kustomization platform-netpol        # Flux
argocd app set platform-netpol --sync-policy none  # Argo CD

Warning

Deleting a deny policy re-opens the namespace to all traffic it had before the change. That is usually what you want during the incident, but tell the security team and set a time to reapply the corrected policy.

If you can't delete it (policy owned by a central team, for example), add an allow policy instead. Allow policies are additive, so this works on all engines:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-dns-egress
  namespace: app-prod
spec:
  podSelector: {}
  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

Then allow traffic from the ingress controller and within the namespace:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-ingress-and-same-namespace
  namespace: app-prod
spec:
  podSelector: {}
  policyTypes: [Ingress]
  ingress:
    - from:
        - podSelector: {}
        - namespaceSelector:
            matchLabels:
              kubernetes.io/metadata.name: ingress-nginx

Change ingress-nginx to the namespace your ingress controller runs in (for the application routing add-on it is app-routing-system; names vary by version, so check kubectl get pods -A | grep -i ingress).

4. Verify recovery

kubectl run nettest -n app-prod --rm -it --image=busybox:1.36 --restart=Never -- \
  sh -c 'nslookup orders-api; wget -qO- -T 3 http://orders-api:8080/healthz'
kubectl get pods -n app-prod
  • DNS resolves and service calls succeed from a test pod.
  • Ingress error rate returns to baseline (check the controller's 5xx metric or Application Gateway / Front Door logs).
  • Readiness probes are passing and no pods are restarting.

5. Reapply the policy correctly

Build the corrected set in a staging namespace with the same labels: default-deny plus explicit allows for DNS, the ingress controller, same-namespace traffic, each external dependency (by private endpoint subnet ipBlock) and the API server if controllers run there. Roll it out to one namespace at a time and run the test pod after each.

Communicate

"Traffic to was blocked by a network security policy rolled out at

Prevent it next time

  • Ship every default-deny policy together with its DNS allow policy, in the same manifest or Helm chart.
  • Test policy changes in a staging namespace with an automated connectivity check (the test pod above, run as a Job).
  • Use kubernetes.io/metadata.name for namespace selectors; it is set automatically on every namespace.
  • Roll out per namespace, not cluster-wide, and watch ingress 5xx and DNS error metrics for 15 minutes before the next one.
  • With Cilium, Hubble flow logs show dropped flows and the policy that dropped them; turn them on before you need them.