CoreDNS配置etcd作為后端


配置說明

官方有使用etcd插件的詳細說明,地址如下:https://coredns.io/plugins/etcd/

需要特別說明的是,目前coredns只支持etcd v2版本的api

這里直接摘出用法示例:

etcd [ZONES...] {
    stubzones
    fallthrough [ZONES...]
    path PATH
    endpoint ENDPOINT...
    upstream [ADDRESS...]
    tls CERT KEY CACERT
}

常用參數說明:

  • ZONES :經過授權的區域,可以為空
  • stubzones:啟用存根區域功能。stubzone僅在位於指定的第一個區域下方的etcd樹中完成。
  • fallthrough:如果區域匹配但不能生成記錄,則將請求傳遞給下一個插件
  • path:etcd里面的路徑 默認為"/skydns",以后所有的dns記錄就是存儲在該存根路徑底下
  • endpoint:etcd訪問地址,默認http://localhost:2397

示例

添加dns解析

etcd配置示例:

etcd {
    stubzones
    path /skydns
    endpoint http://192.168.0.129:2379
    upstream /etc/resolv.conf
}

那么我們往etcd中添加如下記錄:

curl -XPUT http://192.168.0.129:2379/v2/keys/skydns/com/test/dynamic/coredns -d value='{"host":"192.168.0.134"}'

通過coredns解析coredns.dynamic.test.com可以返回192.168.0.134,可以看出,com/test/dynamic/corednscoredns.dynamic.test.com正好相反

添加指定dns解析

etcd配置示例

etcd test.com{
    stubzones
    path /skydns
    endpoint http://192.168.0.129:2379
    upstream /etc/resolv.conf
}

那么就必須添加/com/test/*/*的域名才能訪問

curl -XPUT http://192.168.0.129:2379/v2/keys/skydns/com/test/dynamic/www -d value='{"host":"192.168.0.133"}'

單個域名對應多個ip:

curl -XPUT http://192.168.0.129:2379/v2/keys/skydns/com/test/www/ttggxuxp -d value='{"host":"192.168.0.134"}'

curl -XPUT http://192.168.0.129:2379/v2/keys/skydns/com/test/www/jzlnykyj -d value='{"host":"192.168.0.135"}'

這樣,解析www.test.com得到的結果就是192.168.0.135和192.168.0.134

反向解析

coredns是支持反向解析的。如果要添加172.0.0.0/24的反向,則需要將zone 0.0.172.in-addr.arpa添加到區域列表中。如果需要添加172.16.80.0/8的反向,則需要將zone 172.in-addr.arpai添加到區域列表中。

下面是將192.168.0.135/8指向breeze.test.com,Corefile配置:

.:53 {
    etcd test.com 10.in-addr.arpa {
        stubzones
        path /skydns
        endpoint http://192.168.0.129:2379
        upstream /etc/resolv.conf
    }
    log
    errors
    proxy . /etc/resolv.conf
}

向etcd中添加記錄如下:

curl -XPUT http://192.168.0.129:2379/v2/keys/skydns/arpa/in-addr/10/1/61/135 -d value='{"host":"breeze.test.com"}'

最后再貼一個完整的etcd的配置示例:

.:53 {
    etcd wh04 test2.com {
        stubzones
        path /coredns
        endpoint http://192.168.0.129:2379
        upstream /etc/resolv.conf
        fallthrough
    }
    health
    log
    errors
    prometheus :9153
    proxy . /etc/resolv.conf
    cache 30
    reload 10s
}
test.com {
    etcd {
        stubzones
        path /coredns
        endpoint http://127.0.0.1:2379
        upstream /etc/resolv.conf
    }
    health :8081
    log
    errors
    prometheus :9253
    proxy . /etc/resolv.conf
    cache 30
    relaod 10s
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM