企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## CoreDNS ConfigMap选项 先来看看默认的CoreDns的配置文件 ``` Corefile: |s .:53 { errors health kubernetes cluster.local in-addr.arpa ip6.arpa { pods insecure upstream fallthrough in-addr.arpa ip6.arpa } prometheus :9153 forward . /etc/resolv.conf cache 30 loop reload loadbalance } ``` - error: 错误记录到stdout - [health](https://coredns.io/plugins/health/):CoreDNS的运行状况报告为[http:// localhost:8080 / health](http://localhost:8080/health) - [kubernetes](https://coredns.io/plugins/kubernetes/):CoreDNS将根据Kubernetes服务和pod的IP回复DNS查询 - [prometheus](https://coredns.io/plugins/prometheus/):CoreDNS的度量标准可以在[http://localhost:9153/](http://localhost:9153/metrics)Prometheus格式的[指标](https://prometheus.io/)中找到 - [proxy](https://coredns.io/plugins/proxy/):任何不在Kubernetes集群域内的查询都将转发到预定义的解析器(/etc/resolv.conf) - [cache](https://coredns.io/plugins/cache/):启用前端缓存 - [loop](https://coredns.io/plugins/loop/):检测简单的转发循环,如果找到循环则停止CoreDNS进程 - [reload](https://coredns.io/plugins/reload):允许自动重新加载已更改的Corefile。编辑ConfigMap配置后,请等待两分钟以使更改生效 - [loadbalance](https://coredns.io/plugins/loadbalance):这是一个循环DNS负载均衡器,可以在答案中随机化A,AAAA和MX记录的顺序 ## 使用CoreDNS配置Stub域和上游名称服务器 有些服务不在kubernetes内部,在内部环境内需要通过dns去访问,名称后缀为`carey.com` ``` carey:53 { errors cache 30 proxy . 10.150.0.1 } ``` 完整的配置文件 ``` Corefile: | .:53 { errors health kubernetes cluster.local in-addr.arpa ip6.arpa { pods insecure upstream fallthrough in-addr.arpa ip6.arpa } prometheus :9153 forward . /etc/resolv.conf cache 30 loop reload loadbalance } carey.com:53 { errors cache 30 proxy . 10.150.0.1 } ``` - 添加自定义hosts ``` Corefile: | .:53 { errors health kubernetes cluster.local in-addr.arpa ip6.arpa { pods insecure upstream fallthrough in-addr.arpa ip6.arpa } hosts { 10.0.20.231 gateway.carey.com 10.0.20.231 api.carey.com } prometheus :9153 forward . /etc/resolv.conf cache 30 loop reload loadbalance } ``` --- 参考文档:[https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/#coredns](https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/#coredns)