2

CoreDNS 使用指北

 2 years ago
source link: https://wsgzao.github.io/post/coredns/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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 上下载安装(以官方新版本为基准)

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 示例如下:

. {
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 的配置文件示例如下:

$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 测试

# 编辑本地 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/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK