{"id":193731,"date":"2020-06-21T09:00:11","date_gmt":"2020-06-21T01:00:11","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=193731"},"modified":"2020-06-16T08:56:35","modified_gmt":"2020-06-16T00:56:35","slug":"coredns-kubernetes","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/coredns-kubernetes.html","title":{"rendered":"\u8be6\u89e3\uff1aCoreDNS\u4f5c\u4e3akubernetes\u540e\u7aef\u7684DNS\u670d\u52a1\u5668"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\ncoredns\u4e4b\u6240\u4ee5\u5982\u6b64\u540d\u58f0\u5927\u566a\uff0c\u5c31\u662f\u56e0\u4e3a\u4ecekubernetes1.9\u5f00\u59cb\u5f15\u5165\uff0c\u4f5c\u4e3akubernetes\u5185\u90e8\u670d\u52a1\u53d1\u73b0\u7684\u9ed8\u8ba4dns\u3002\u6beb\u65e0\u7591\u95eekubernetes\u662fcoredns\u7684\u540e\u7aef\u4e4b\u4e00\uff0c\u6240\u4ee5\u6211\u4eec\u8bb2coredns\uff0c\u5c31\u4ecekubernetes\u4f5c\u4e3a\u5176\u540e\u7aef\u5f00\u59cb\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

coredns\u7684\u8bf8\u591a\u7279\u6027\u7f51\u4e0a\u5f88\u591a\u6587\u7ae0\u90fd\u6709\u63d0\u53ca\uff0c\u5728\u8fd9\u91cc\u4e0d\u518d\u8d58\u8ff0\u3002\u7b80\u5355\u5bf9\u6bd4\u4e0b\u5176\u76f8\u5bf9\u4e8ebind\u548cskydns\u7684\u4f18\u52bf\uff1a<\/p>\n

bind\u53ef\u4ee5\u5c06\u89e3\u6790\u5b58\u50a8\u5230mysql\u6216\u8005\u6587\u4ef6\u4e2d\uff0ccoredns\u4e5f\u53ef\u4ee5\u5c06\u89e3\u6790\u5b58\u50a8\u5230etcd\u6216\u8005\u6587\u4ef6\u4e2d\uff0c\u4e5f\u652f\u6301\u5c06kubernetes\u4f5c\u4e3a\u5176\u540e\u7aef\uff0c\u76f4\u63a5\u8c03\u7528kubernetes\u7684api\u83b7\u53d6\u89e3\u6790\u6570\u636e\uff0c\u7136\u540e\u7f13\u5b58\u5230\u672c\u5730\u5185\u5b58\u3002coredns\u652f\u6301\u63d2\u4ef6\u6269\u5c55\uff0c\u76ee\u524d\u5728\u7b2c\u4e09\u65b9\u63d2\u4ef6\u4e2d\u8fd8\u540c\u65f6\u652f\u6301\u5c06powerdns\u53caamazondns\u4f5c\u4e3a\u5176\u540e\u7aef\uff0c\u540e\u7eed\u8fd8\u4f1a\u652f\u6301\u8d8a\u6765\u8d8a\u6765\u7684\u540e\u7aef\u3002bind\u5728kubernetes\u7684\u5e94\u7528\u573a\u666f\u4e0b\uff0c\u57fa\u672c\u65e0\u7528\u6b66\u4e4b\u5730\u3002<\/p>\n

coredns\u672c\u8eab\u5c31\u662fskydns\u7684\u7ee7\u4efb\u8005\uff0c\u652f\u6301skydns\u7684\u6240\u6709\u7279\u6027\uff0c\u800c\u4e14\u6027\u80fd\u66f4\u597d\uff0c\u66f4\u6613\u4e8e\u6269\u5c55\u3002\u5176\u63d2\u4ef6\u5f0f\u7279\u6027\u65e0\u8bba\u662fbind\u8fd8\u662fskydns\u90fd\u65e0\u6cd5\u6bd4\u62df\u3002<\/p>\n

coredns\u5b98\u65b9\u7f51\u7ad9\u5730\u5740\uff1ahttps:\/\/coredns.io<\/a><\/p>\n

coredns\u4ee3\u7801\u5730\u5740\uff1a https:\/\/github.com\/coredns\/coredns<\/a><\/p>\n

coredns\u5b98\u65b9\u63d2\u4ef6\u5730\u5740\uff1ahttps:\/\/coredns.io\/plugins<\/a><\/p>\n

coredns\u7b2c\u4e09\u65b9\u63d2\u4ef6\u5730\u5740\uff1ahttps:\/\/coredns.io\/explugins\/<\/a><\/p>\n

\u914d\u7f6ekubernetes\u540e\u7aef\u5b58\u50a8<\/strong><\/div>\n
\u914d\u7f6e\u8bf4\u660e<\/strong><\/span><\/div>\n

\u5176\u5b9e\u5b98\u65b9\u6709kubernetes\u63d2\u4ef6\u7684\u76f8\u5173\u793a\u4f8b\u53ca\u914d\u7f6e\u8bf4\u660e\uff0c\u5730\u5740\u5982\u4e0b\uff1ahttps:\/\/coredns.io\/plugins\/kubernetes\/<\/a><\/p>\n

\u6211\u8fd9\u91cc\u5c31\u4ee5\u5b98\u65b9\u7684\u914d\u7f6e\u793a\u4f8b\u4f5c\u8bf4\u660e\uff1a<\/p>\n

\r\nkubernetes [ZONES...] {\r\n    resyncperiod DURATION\r\n    endpoint URL [URL...]\r\n    tls CERT KEY CACERT\r\n    namespaces NAMESPACE...\r\n    labels EXPRESSION\r\n    pods POD-MODE\r\n    endpoint_pod_names\r\n    upstream [ADDRESS...]\r\n    ttl TTL\r\n    fallthrough [ZONES...]\r\n}\r\n<\/pre>\n

\u4e0b\u9762\u5bf9\u4e00\u4e9b\u5e38\u7528\u53c2\u6570\u4f5c\u4e0b\u8bf4\u660e\uff1a<\/p>\n

resyncperiod\uff1a \u7528\u4e8e\u4ecekubernetes\u7684api\u540c\u6b65\u6570\u636e\u7684\u65f6\u95f4\u95f4\u9694<\/p>\n

endpoint\uff1a \u6307\u5b9akubernetes\u7684api\u5730\u5740\uff0ccoredns\u4f1a\u81ea\u52a8\u5bf9\u5176\u6267\u884c\u5065\u5eb7\u68c0\u67e5\u5e76\u5c06\u8bf7\u6c42\u4ee3\u7406\u5230\u5065\u5eb7\u7684\u8282\u70b9\u4e0a\u3002\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n

\r\nendpoint https:\/\/10.1.61.129:6443 https:\/\/10.1.61.130:6443\r\n<\/pre>\n

tls\uff1a \u7528\u4e8e\u6307\u5b9a\u8fde\u63a5\u8fdc\u7a0bkubernetes api\u7684\u76f8\u5173\u8bc1\u4e66\u3002\u793a\u4f8b\uff1a<\/p>\n

\r\ntls admin.pem admin-key.pem ca.pem\r\n<\/pre>\n

pods\uff1a \u6307\u5b9aPOD-MODE\uff0c\u6709\u4ee5\u4e0b\u4e09\u79cd\uff1a<\/p>\n

disabled\uff1a\u9ed8\u8ba4<\/p>\n

insecure\uff1a\u8fd4\u56de\u4e00\u4e2aA\u8bb0\u5f55\u5bf9\u5e94\u7684ip\uff0c\u4f46\u5e76\u4e0d\u4f1a\u68c0\u67e5\u8fd9\u4e2aip\u5bf9\u5e94\u7684Pod\u5f53\u524d\u662f\u5426\u5b58\u5728\u3002\u8fd9\u4e2a\u9009\u9879\u4e3b\u8981\u7528\u4e8e\u517c\u5bb9kube-dns<\/p>\n

verified\uff1a\u63a8\u8350\u7684\u65b9\u5f0f\uff0c\u8fd4\u56deA\u8bb0\u5f55\u7684\u540c\u65f6\u4f1a\u786e\u4fdd\u5bf9\u5e94ip\u7684pod\u5b58\u5728\u3002\u6bd4insecure\u4f1a\u6d88\u8017\u66f4\u591a\u7684\u5185\u5b58\u3002<\/p>\n

upstream\uff1a \u5b9a\u4e49\u5916\u90e8\u57df\u540d\u89e3\u6790\u8f6c\u53d1\u7684\u5730\u5740\uff0c\u53ef\u4ee5\u662f\u4e00\u4e2aip\u5730\u5740\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2aresolv.conf\u6587\u4ef6\u3002\u793a\u4f8b\uff1a<\/p>\n

\r\nupstream 8.8.8.8:53 8.8.4.4:53\r\n<\/pre>\n

ttl\uff1a \u9ed8\u8ba45s\uff0c\u6700\u59273600s<\/p>\n

\u793a\u4f8b<\/strong><\/span><\/div>\n

\u4e00\u4e2a\u5b8c\u6574\u7684\u914d\u7f6e\u793a\u4f8b\uff1a<\/p>\n

\r\n# \/opt\/coredns\/cfg\/Corefile\r\n.:53 {\r\n    kubernetes wh01 {\r\n        resyncperiod 10s\r\n        endpoint https:\/\/10.1.61.175:6443\r\n        tls admin.pem admin-key.pem ca.pem\r\n        pods verified\r\n        endpoint_pod_names\r\n        upstream \/etc\/resolv.conf\r\n    }\r\n    health\r\n    log \/var\/log\/coredns.log\r\n    prometheus :9153\r\n    proxy . \/etc\/resolv.conf\r\n    cache 30\r\n    reload 10s\r\n}\r\n<\/pre>\n

\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u5199\u6cd5\uff1a<\/p>\n

\r\nwh01 {\r\n    kubernetes {\r\n        resyncperiod 10s\r\n        endpoint https:\/\/10.1.61.129:6443\r\n        tls admin.pem admin-key.pem ca.pem\r\n        pods verified\r\n        endpoint_pod_names\r\n        upstream \/etc\/resolv.conf\r\n    }\r\n    health\r\n    log\r\n    errors\r\n    prometheus :9153\r\n    proxy . \/etc\/resolv.conf\r\n    cache 30\r\n    reload 10s\r\n}\r\n<\/pre>\n

\u5176\u4ed6\u914d\u7f6e\u4e5f\u7b80\u5355\u4f5c\u4e0b\u8bf4\u660e\uff1a<\/p>\n

health\uff1a\u63d2\u4ef6\uff0c\u7528\u4e8e\u68c0\u6d4b\u5f53\u524d\u914d\u7f6e\u662f\u5426\u5b58\u6d3b\uff0c\u9ed8\u8ba4\u76d1\u542chttp 8080\u7aef\u53e3\uff0c\u53ef\u914d\u7f6e<\/p>\n

log\uff1a \u63d2\u4ef6\uff0c\u5c06\u65e5\u5fd7\u6253\u5370\u5230\u6807\u51c6\u8f93\u51fa<\/p>\n

errors\uff1a\u5c06\u9519\u8bef\u6253\u5370\u5230\u6807\u51c6\u8f93\u51fa<\/p>\n

prometheus\uff1a \u63d2\u4ef6\uff0c\u7528\u4e8eprometheus\u76d1\u63a7<\/p>\n

proxy\uff1a wh01\u4e4b\u5916\u7684\u57df\u540d\u89e3\u6790\u90fd\u901a\u8fc7proxy\u6307\u5b9a\u7684\u5730\u5740\u5b9e\u73b0\u4ee3\u7406<\/p>\n

cache\uff1a \u63d2\u4ef6\uff0c\u7528\u4e8e\u5728\u5185\u5b58\u4e2d\u7f13\u5b58dns\u89e3\u6790\uff0c\u5355\u4f4d\u4e3as<\/p>\n

reload\uff1a \u63d2\u4ef6\uff0c\u5355\u4f4d\u4e3as\uff0c\u5982\u679c\u914d\u7f6e\u6587\u4ef6\u53d1\u751f\u53d8\u66f4\uff0c\u81ea\u52a8reload\u7684\u95f4\u9694<\/p>\n

\u542f\u52a8coredns<\/strong><\/span><\/div>\n
\r\nnohup \/opt\/coredns\/bin\/coredns -conf \/opt\/coredns\/cfg\/Corefile &\r\n<\/pre>\n
\u4f7f\u7528systemd\u542f\u52a8coredns<\/strong><\/span><\/div>\n
\r\n# cat \/lib\/systemd\/system\/coredns.service\r\n\r\n[Unit]\r\nDescription=CoreDNS\r\nDocumentation=https:\/\/coredns.io\r\n\r\n[Service]\r\nExecStart=\/opt\/coredns\/bin\/coredns \\\r\n  -conf \/opt\/coredns\/cfg\/Corefile\r\n\r\nRestart=on-failure\r\nRestartSec=5\r\n\r\n[Install]\r\nWantedBy=multi-user.targe\r\n<\/pre>\n
\r\n# systemctl start coredns\r\n# systemctl enable coredns\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

coredns\u7684\u8bf8\u591a\u7279\u6027\u7f51\u4e0a\u5f88\u591a\u6587\u7ae0\u90fd\u6709\u63d0\u53ca\uff0c\u5728\u8fd9\u91cc\u4e0d\u518d\u8d58\u8ff0\u3002\u7b80\u5355\u5bf9\u6bd4\u4e0b\u5176\u76f8\u5bf9\u4e8ebind\u548cskydns\u7684\u4f18\u52bf\uff1a […]<\/p>\n","protected":false},"author":1479,"featured_media":84231,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-193731","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/193731","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=193731"}],"version-history":[{"count":6,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/193731\/revisions"}],"predecessor-version":[{"id":193955,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/193731\/revisions\/193955"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/84231"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=193731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=193731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=193731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}