K8S-Demo集群实践13:部署集群CoreDNS
先说本实践案例遇到的问题和答案,k8s集群中遇到CoreDNS解析失败的问题:
- server can’t find kubernetes.default.svc.cluster.demo: NXDOMAIN
- Can’t find kubernetes.svc.cluster.local: No answer
- nslookup: can’t resolve ‘kubernetes’
- Readiness probe failed: HTTP probe failed with statuscode: 503
- Failed to list *v1.Namespace: Get “https://10.8.0.1:443/api/v1/namespaces?limit=500&resourceVersion=0”: dial tcp 10.8.0.1:443: i/o timeout
主要尝试以下方法解决:
- CentOS系统,内核版本为 3.10,里面的 IPVS 模块比较老旧,缺少新版 Kubernetes IPVS 所需的依赖,通过升级内核到4.4.xx解决
- 测试用的busybox 1.29版本有问题,换成1.28版本试试
- CoreDNS配置问题,参考 https://coredns.io/manual/toc/#configuration
- 网络插件是否安装成功,即Pod夸主机通讯以及Pod和ServiceIP通讯是否正常(本案例使用Calico)
解决问题的大概步骤
- 查看CoreDNS Pod状态(kubectl get pod,svc,deploy,rc,rs -A | grep dns)
- 查看CoreDNS pod Events(kubectl describe pod coredns-6746cb5997-nnw7h -n kube-system)
- 查看CoreDNS pod日志 (kubectl logs -f pod/coredns-6746cb5997-nnw7h -n kube-system)
- 查看kube-proxy日志(journalctl -f -u kube-proxy)
- 查看kube-apiserver日志(journalctl -f -u kube-apiserver)
一、下载CoreDNS
[root@master1 ~]# cd /opt/install
[root@master1 install]# mkdir coredns
[root@master1 install]# cd coredns
[root@master1 coredns]# git clone https://github.com/coredns/deployment.git
[root@master1 coredns]# cd ./deployment/kubernetes
二、修改部署脚本 deploy.sh
- 找到 CLUSTER_DNS_IP=$(kubectl get service --namespace kube-system kube-dns -o jsonpath="{.spec.clusterIP}")
- 修改为:CLUSTER_DNS_IP=10.8.0.2
三、部署CoreDNS并测试
1、生成coredns.yaml并部署
[root@master1 ~]# cd /opt/install/coredns
[root@master1 coredns]# ./deploy.sh > coredns.yaml
[root@master1 coredns]# kubectl apply -f coredns.yaml
- 修改 coredns.yaml,在Corefi