前言 CoreDNS 是一个从 Caddy 中Fork出来的项目(同时继承了它的链式中间件风格),作为CNCF项目中的一员,它的目标是提供一个快速且灵活的DNS服务。
CoreDNS - DNS and Service Discovery
更新历史 2022年05月06日 - 增加CoreDNS Deployment 2018年07月10日 - 初稿
阅读原文 - https://wsgzao.github.io/post/coredns/
扩展阅读
CoreDNS - https://coredns.io/
CoreDNS 简介
In Kubernetes 1.11, CoreDNS is the default DNS server.
CoreDNS is a DNS server. It is written in Go. It can be used in a multitude of environments because of its flexibility. CoreDNS is licensed under the Apache License Version 2, and completely open source. Development takes place on Github. Most devs hang out on Slack on the #coredns channel.
CoreDNS 安装 直接在Github上下载对应执行文件压缩包https://github.com/coredns/coredns/releases
Linux上下载安装(以官方新版本为基准)
1 2 3 wget https://github.com/coredns/coredns/releases/download/v1.1.4/coredns_1.1.4_linux_amd64.tgz tar xzf coredns_1.1.4_linux_amd64.tgz mv coredns /usr/local/bin
CoreDNS 配置 参考 QuickStart 中的配置https://coredns.io/2017/07/24/quick-start/
配置文件Corefile示例如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 . { proxy . 223.5.5.5:53 { except example.org protocol dns } prometheus errors stdout log stdout } example.org { file /etc/coredns/zones/example.org prometheus errors stdout log stdout }
具体Corefile配置说明请参考文档https://coredns.io/2017/07/23/corefile-explained/
而/etc/coredns/zones/example.org的配置文件示例如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 $ORIGIN example.org.@ 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. ( 2017042745 ; serial 7200 ; refresh (2 hours) 3600 ; retry (1 hour) 1209600 ; expire (2 weeks) 3600 ; minimum (1 hour) ) 3600 IN NS a.iana-servers.net. 3600 IN NS b.iana-servers.net. www IN A 127.0.0.1 IN AAAA ::1 tt IN A 192.168.2.4 IN AAAA ::1 IN TXT HelloExampleTest
CoreDNS 测试 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 vi /etc/resolv.conf nameserver 8.8.8.8 vi /etc/coredns/corefile coredns:53 { errors log zookeeper up_timeout=5 zk_timeout=10 zk_ttl=5 zk_addrs=10.65.200.36:2181,10.65.200.37:2181,10.65.200.138:2181 zk_znode=/dns loadbalance round_robin cache 1 } .:53 { errors log proxy . /etc/resolv.conf loadbalance round_robin cache 1 } coredns -conf /etc/coredns/Corefile https://www.diggui.com/ dig +short @10.65.200.105 google.com dig google.com
CoreDNS Deployment https://github.com/coredns/deployment
建议使用systemd方式部署,方便后续管理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 git clone https://github.com/coredns/deployment cd deploymentdpkg-buildpackage -us -uc -b dpkg -i coredns_1.9.1-0~100_amd64.deb xxx:53 { errors forward . xxx cache 30 log } .:53 { errors forward . /etc/resolv.conf cache 30 log } systemctl restart coredns tail -f /var/log/syslog
参考文档
CoreDNS Manual
https://coredns.io/manual/toc/