前言 CoreDNS 是一个从 Caddy 中 Fork 出来的项目(同时继承了它的链式中间件风格),作为 CNCF 项目中的一员,它的目标是提供一个快速且灵活的 DNS 服务。
CoreDNS - DNS and Service Discovery
更新历史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 上下载安装(以官方新版本为基准)
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 . { proxy . 223.5.5.5:53 { except example.org protocol dns } prometheus # enable metrics errors stdout # show errors log stdout # show query logs } example.org { file /etc/coredns/zones/example.org prometheus # enable metrics errors stdout # show errors log stdout # show query logs }
具体 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 # 编辑本地 nameserver vi /etc/resolv.conf nameserver 8.8.8.8 # 编辑 corefile 文件 vi /etc/coredns/corefile coredns:53 { errors # show errors log # enable query logs 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 # show errors log # enable query logs proxy . /etc/resolv.conf loadbalance round_robin cache 1 } # 运行 CoreDNS 很简单,命令如下 coredns -conf /etc/coredns/Corefile # 使用 dig 命令测试 https://www.diggui.com/ dig +short @10.65.200.105 google.com dig google.com
参考文档CoreDNS Manual
https://coredns.io/manual/toc/