K8S-Demo集群实践:部署集群CoreDNS
程序员文章站
2022-03-12 12:43:55
...
K8S-Demo集群实践:部署集群CoreDNS
一、下载CoreDNS
[[email protected] ~]# cd /opt/install
[[email protected] install]# mkdir coredns
[[email protected] install]# cd coredns
[[email protected] coredns]# git clone https://github.com/coredns/deployment.git
[[email protected] 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并部署
[[email protected] ~]# cd /opt/install/coredns
[[email protected] coredns]# ./deploy.sh > coredns.yaml
[[email protected] coredns]# kubectl apply -f coredns.yaml
- yaml文件中的镜像 是1.8.0版本,测试有问题,修改为1.7.0后测试成功
- 在Corefile部分添加了宿主机的解析
... ... ... ...
kubernetes cluster.demo in-addr.arpa ip6.arpa {
fallthrough in-addr.arpa ip6.arpa
}
hosts {
192.168.66.10 master1
192.168.66.11 master2
192.168.66.12 master3
192.168.66.13 node1
192.168.66.14 node2
192.168.66.15 node3
192.168.66.106 harbor
192.168.66.106 harbor.demo
}
prometheus :9153
... ... ... ...
2、查看服务状态
[[email protected] ~]# kubectl get rs,deploy,svc,pods -n kube-system| grep dns
replicaset.apps/coredns-7f44d46d8d 2 2 2 23d
deployment.apps/coredns 2/2 2 2 23d
service/kube-dns ClusterIP 10.8.0.2 <none> 53/UDP,53/TCP,9153/TCP 23d
pod/coredns-7f44d46d8d-9btdv 1/1 Running 2 7d
pod/coredns-7f44d46d8d-dc4b9 1/1 Running 2 7d
3、创建一个 busybox Pod
[[email protected] ~]# cd /opt/install/coredns
[[email protected] coredns]# vim busybox.yaml
apiVersion: v1
kind: Pod
metadata:
name: busybox
namespace: default
spec:
containers:
- name: busybox
image: busybox:1.28.3
command:
- sleep
- "3600"
imagePullPolicy: IfNotPresent
restartPolicy: Always
[[email protected] coredns]# kubectl apply -f busybox.yaml
4、进入busybox容器测试CoreDNS,执行nslookup
[[email protected] ~]# kubectl exec -it busybox /bin/sh
/ # nslookup kubernetes
Server: 10.8.0.2
Address 1: 10.8.0.2 kube-dns.kube-system.svc.cluster.demo
Name: kubernetes
Address 1: 10.8.0.1 kubernetes.default.svc.cluster.demo
/ # nslookup metrics-server.kube-system.svc.cluster.demo
Server: 10.8.0.2
Address 1: 10.8.0.2 kube-dns.kube-system.svc.cluster.demo
Name: metrics-server.kube-system.svc.cluster.demo
Address 1: 10.8.20.170 metrics-server.kube-system.svc.cluster.demo
/ # nslookup kube-dns.kube-system.svc.cluster.demo
Server: 10.8.0.2
Address 1: 10.8.0.2 kube-dns.kube-system.svc.cluster.demo
Name: kube-dns.kube-system.svc.cluster.demo
Address 1: 10.8.0.2 kube-dns.kube-system.svc.cluster.demo
/ # nslookup 192.168.66.12
Server: 10.8.0.2
Address 1: 10.8.0.2 kube-dns.kube-system.svc.cluster.demo
Name: 192.168.66.12
Address 1: 192.168.66.12 192-168-66-12.kubernetes.default.svc.cluster.demo
/ # nslookup 10.8.234.157
Server: 10.8.0.2
Address 1: 10.8.0.2 kube-dns.kube-system.svc.cluster.demo
Name: 10.8.234.157
Address 1: 10.8.234.157 kubernetes-dashboard.kubernetes-dashboard.svc.cluster.demo
四、问题
- 问题:./deploy.sh:行61: jq: 未找到命令
- 解决方法
[[email protected] ~]# yum install epel-release
[[email protected] ~]# yum list jq
[[email protected] ~]# yum install jq
参考
- KubeDNS对比CoreDNS https://zhuanlan.zhihu.com/p/80141656
- https://coredns.io/plugins/loop/#troubleshooting
- 先用起来,通过操作实践认识k8s,积累多了自然就理解了
- 把理解的知识分享出来,自造福田,自得福缘
- 追求简单,容易使人理解,知识的上下文也是知识的一部分,例如版本,时间等
- 欢迎留言交流,也可以提出问题,一般在周末回复和完善文档
- [email protected] 2021-1-22