2 min read

CoreDNS部署笔记

CoreDNS部署笔记

  在企业高可用DNS架构部署方案博文中我们使用的是传统老牌DNS软件--Bind, 现在不少企业内部流行容器化部署,所以我们也可以将Bind替换为 CoreDNS。同时CoreDNS是 Kubernetes的一个重要组件,稳定性不必担心。

部署

CoreDNS部署方式非常简单

  • config/corefile
vqiu.cn.:53 {
    whoami
    forward . 10.10.100.20
    cache {
        success 200
        denial 100
    }
}

.  {


    hosts {
        fallthrough
    }
    forward . 223.5.5.5:53 223.6.6.6:53
    reload 30s
    health
    errors
    cache 180
    log
    loadbalance

    prometheus 0.0.0.0:9153

    file /etc/coredns/db.example.com example.com
}

配置文件各参数的含义如下:

名称 含义
errors 错误会被记录到标准输出。
health 健康状况,可以通过http://localhost:8080/health查看。
kubernetes 根据服务的IP响应DNS查询请求,Cluster Domain默认为cluster.local。
prometheus 可以通过http://localhost:9153/metrics获取prometheus格式的监控数据。
proxy 本地无法解析后,向上级地址进行查询,默认使用宿主机的/etc/resolv.conf配置。
cache 缓存时间。

vqiu.cn需要条件转发的域名

  • config/db.example.com
$ORIGIN example.com.
@   3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. (
                2018070500 ; serial
                7200       ; refresh in seconds (2 hours is 7200)
                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.

gateway    IN A     192.168.1.1
  • docker-compose.yml
version: '2.4'
services:
  coredns:
    cpus: 1
    mem_limit: 512m
    memswap_limit: 512m
    mem_swappiness: 0
    image: coredns/coredns:1.8.3
    #container_name: coredns
    restart: always
    networks:
      - dns
    volumes:
      - './config:/etc/coredns:ro'
    scale: 1
    ports:
      - "53:53/udp"
      - "53:53/tcp"
      - "9153:9153/tcp"
      - "8080:8080/tcp" # 健康检测URL /health
    command: -conf /etc/coredns/Corefile

networks:
  dns:
    external:
      name: dns-net

Tips:单机跑一个应用容器时网络建议使用 host模式

服务启动

docker-compose up -d 

监控数据预览

----_2020-09-15T00-31-18.716Z

Grafana

ID:12539

引用参考