kubernetes
network_error
ai_generated
true
connection refused: dial tcp 10.96.0.10:53: connect: connection refused (due to NetworkPolicy)
ID: kubernetes/networkpolicy-blocking-dns
88%Fix Rate
86%Confidence
1Evidence
2024-04-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Calico v3.27.2 | active | — | — | — |
| Cilium v1.15.0 | active | — | — | — |
| Kubernetes v1.28.5 | active | — | — | — |
| Kubernetes v1.29.1 | active | — | — | — |
Root Cause
A NetworkPolicy is blocking DNS traffic (port 53) from the pod to the CoreDNS service, either by ingress or egress rules, preventing DNS resolution.
generic中文
NetworkPolicy阻止了Pod到CoreDNS服务的DNS流量(端口53),可能是入站或出站规则,导致DNS解析失败。
Official Documentation
https://kubernetes.io/docs/concepts/services-networking/network-policies/Workarounds
-
90% success Add an egress rule to allow DNS traffic in the pod's namespace: `kubectl edit networkpolicy <policy-name>` and add under egress: `- ports: [{port: 53, protocol: UDP}, {port: 53, protocol: TCP}]` and ensure the destination includes the kube-system namespace or the CoreDNS pod selector.
Add an egress rule to allow DNS traffic in the pod's namespace: `kubectl edit networkpolicy <policy-name>` and add under egress: `- ports: [{port: 53, protocol: UDP}, {port: 53, protocol: TCP}]` and ensure the destination includes the kube-system namespace or the CoreDNS pod selector. -
85% success Test connectivity to CoreDNS: `kubectl run -it --rm debug --image=busybox -- sh` then run `nslookup kubernetes.default.svc.cluster.local`. If it fails, inspect NetworkPolicies in the namespace: `kubectl describe networkpolicy -n <namespace>`
Test connectivity to CoreDNS: `kubectl run -it --rm debug --image=busybox -- sh` then run `nslookup kubernetes.default.svc.cluster.local`. If it fails, inspect NetworkPolicies in the namespace: `kubectl describe networkpolicy -n <namespace>`
中文步骤
Add an egress rule to allow DNS traffic in the pod's namespace: `kubectl edit networkpolicy <policy-name>` and add under egress: `- ports: [{port: 53, protocol: UDP}, {port: 53, protocol: TCP}]` and ensure the destination includes the kube-system namespace or the CoreDNS pod selector.Test connectivity to CoreDNS: `kubectl run -it --rm debug --image=busybox -- sh` then run `nslookup kubernetes.default.svc.cluster.local`. If it fails, inspect NetworkPolicies in the namespace: `kubectl describe networkpolicy -n <namespace>`
Dead Ends
Common approaches that don't work:
-
Restart the pod or delete and recreate it
95% fail
The NetworkPolicy is still in place, so restarting the pod will result in the same DNS failure. The policy must be modified.
-
Disable all NetworkPolicies by deleting them
60% fail
This is a security risk and defeats the purpose of network segmentation. A targeted fix is better, e.g., adding a policy that allows DNS.