Minikube中Kubernetes Pod DNS nameserver IP错误致服务解析失败
Got it, let's work through this DNS resolution issue you're hitting in Minikube. I've seen this exact scenario a few times, so here's how to diagnose and fix it properly—no temporary manual edits required!
问题根源
The core issue here is that your Pod's DNS configuration is pointing to the wrong kube-dns Cluster IP:
- Inside the Pod,
/etc/resolv.conflists10.96.0.10as the nameserver, but your actual kube-dns service has a Cluster IP of10.0.0.10 - That's why using the service name
web-server:8081/endpointfails (it can't reach the correct DNS server to resolve the name), but accessing the direct IP works (it skips DNS entirely)
Quick Temporary Fix (You Already Did This!)
Manually updating the nameserver in /etc/resolv.conf to 10.0.0.10 will get DNS working immediately, but this is a band-aid—restarting the Pod will reset the config. Let's fix the root cause.
Root Cause Troubleshooting Steps
Confirm kube-dns's actual Cluster IP
Run this command to verify the kube-dns service details:kubectl get service kube-dns -n kube-systemDouble-check that the
CLUSTER-IPmatches10.0.0.10(which you already confirmed it does).Check the Pod's DNS Policy
Look at your problematic Pod's configuration to see if the DNS policy is misconfigured:kubectl get pod <your-pod-name> -o yaml | grep -A5 dnsPolicy- The default
dnsPolicyisClusterFirst, which automatically points the Pod's nameserver to kube-dns's Cluster IP - If it's set to
Noneor a custom value, that could override the correct DNS settings
- The default
Verify DNS Component Health
Make sure kube-dns (or CoreDNS, which Minikube uses in newer versions) is running properly:kubectl get pods -n kube-system | grep -E 'kube-dns|coredns'If the DNS Pod is in
CrashLoopBackOfforNotReadystate, it might have restarted and picked up a new IP, or be unable to serve requests.Check Kubelet's DNS Configuration
Minikube's kubelet might be configured with the wrong DNS IP. SSH into the Minikube node to check:minikube ssh cat /var/lib/kubelet/config.yaml | grep clusterDNSThe
clusterDNSvalue here should match kube-dns's Cluster IP (10.0.0.10). If it's10.96.0.10, that's the source of the misconfiguration.
Permanent Fixes
Pick the fix that matches your troubleshooting findings:
- If kubelet's clusterDNS is wrong:
Delete and restart Minikube with the correct DNS IP specified:minikube delete minikube start --extra-config=kubelet.cluster-dns=10.0.0.10 - If Pod's dnsPolicy is misconfigured:
Update your Pod's YAML to use the defaultClusterFirstpolicy, then redeploy:apiVersion: v1 kind: Pod metadata: name: your-pod-name spec: dnsPolicy: ClusterFirst # ... rest of your Pod spec - If DNS Pod is unhealthy:
Delete the faulty DNS Pod—Kubernetes will automatically spin up a new healthy one:kubectl delete pod <dns-pod-name> -n kube-system
Verify the Fix
After applying the fix, check the Pod's DNS config again to confirm:
kubectl exec -it <your-pod-name> -- cat /etc/resolv.conf
You should see 10.0.0.10 as the nameserver. Then test the service name resolution:
kubectl exec -it <your-pod-name> -- wget web-server:8081/endpoint
This should now work as expected!
内容的提问来源于stack exchange,提问作者Sergii Bishyr

