执行kubectl apply部署Redis遇DNS解析错误,求解决方案
Let’s work through resolving your connection problems step by step:
1. Remove the conflicting environment variable
The KUBERNETES_MASTER environment variable you set is overriding your kubeconfig settings, and it’s pointing to the wrong port (your cluster uses 6443, not 8080). First, unset this variable to let kubectl use your valid config:
unset KUBERNETES_MASTER
2. Fix your kubeconfig server address
Your ./kube/config shows the server as https://****:6443, but kubectl cluster-info confirms the master runs at 192.168.219.107:6443. Update the config to match the actual IP:
- Open your config file (either
~/.kube/configor./kube/configif using a custom path) - Find the
serverline under theclusterssection and replace****with192.168.219.107, so it reads:server: https://192.168.219.107:6443 - Save the file, and set secure permissions to avoid warnings:
chmod 600 ~/.kube/config
3. Resolve the DNS lookup failure
The error dial tcp: lookup MasterIP on 127.0.0.53:53: server misbehaving means your system can’t resolve the MasterIP hostname to an IP.
- If
MasterIPis just a placeholder, replace it with192.168.219.107wherever you’re referencing the master node. - If
MasterIPis supposed to be a valid hostname, add an entry to your local hosts file to bypass DNS issues:echo "192.168.219.107 MasterIP" | sudo tee -a /etc/hosts
4. Test the connection and reapply your deployment
After making these changes, verify kubectl can connect to the cluster:
kubectl cluster-info
You should see the master running at 192.168.219.107:6443 without errors. Then try applying your Redis deployment again:
kubectl apply -f redis.yaml
5. Additional checks if issues persist
- Confirm your master node is reachable: ping
192.168.219.107to test network connectivity. - If connecting to a remote cluster, ensure port 6443 is open in any firewalls between your machine and the master node.
内容的提问来源于stack exchange,提问作者chichi

