当前位置:网站首页>Introduction to coredns
Introduction to coredns
2022-08-02 06:20:00 【Granny who loves watching square dancing】
目录
一、coredns的用途
CoreDNS 是一个灵活可扩展的 DNS 服务器,可以作为 Kubernetes 集群 DNS,在Kubernetes1.12version later became the defaultDNS服务. 与 Kubernetes 一样,CoreDNS 项目由 CNCF 托管.
coredns在K8S中的用途,Mainly used for service discovery,也就是服务(应用)之间相互定位的过程.
在k8s中,用service资源代理pod,通过暴露serviceThe fixed address of the resource(集群IP),to solve the abovePODresource changesIP变动问题,但是针对service还存在以下问题:
- service IP地址难以记忆
- serviceResources may also be destroyed and created
- pod ipThere are also needs to be exposed
为了解决以上问题,引入了coredns,在K8S,It is mainly used for service discovery,也就是服务(应用)之间相互定位的过程.
二、coredns的部署
coredns部署参考
部署后,可在dns中,通过如下命令查询coredns是否运行正常
dig @127.0.0.1 -p 53 www.example.com
三、corddns配置
3.1 K8s DNS策略
Kubernetes 中 Pod 的 DNS 策略有四种类型:
- Default:Pod 继承所在主机上的 DNS 配置;
- ClusterFirst:K8s 的默认设置;先在 K8s 集群配置的 coreDNS 中查询,查不到的再去继承自主机的上游 nameserver 中查询;
- ClusterFirstWithHostNet:对于网络配置为 hostNetwork 的 Pod 而言,其 DNS 配置规则与 ClusterFirst 一致;
- None:忽略 K8s 环境的 DNS 配置,只认 Pod 的 dnsConfig 设置.
3.2 resolv.conf
在部署 pod 的时候,如果用的是 K8s 集群的 DNS,那么 kubelet 在起 pause 容器的时候,会将其 DNS 解析配置初始化成集群内的配置.
Such as creating a call my-nginx 的 deployment,其 pod 中的 resolv.conf 文件如下:
# DNS 服务的 IP,即coreDNS 的 clusterIP
nameserver 169.254.25.10
# DNS search 域.解析域名的时候,将要访问的域名依次带入 search 域,进行 DNS 查询
# 比如访问your-nginx,其进行的 DNS 域名查询的顺序是:your-nginx.default.svc.cluster.local. -> your-nginx.svc.cluster.local. -> your-nginx.cluster.local.
search default.svc.cluster.local svc.cluster.local cluster.local
# 其他项,最常见的是 dnots.dnots 指的是如果查询的域名包含的点 “.” 小于 5,则先走search域,再用绝对域名;如果查询的域名包含点数大于或等于 5,则先用绝对域名,再走search域
# K8s 中默认的配置是 5.
options ndots:5
3.3 coreDNS Corefile 文件
CoreDNS 实现了应用的插件化,用户可以选择所需的插件编译到可执行文件中;CoreDNS 的配置文件是 Corefile 形式的,coreDNS 的 configMap如下所示:
apiVersion: v1
data:
Corefile: |
.:53 {
errors
health
# 指明 cluster.local 后缀的域名,都是 kubernetes 内部域名,coredns 会监听 service 的变化来维护域名关系,所以cluster.local 相关域名都在这里解析
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
upstream
fallthrough in-addr.arpa ip6.arpa
}
# CoreDNS 的监控地址为:http://localhost:9153/metrics
prometheus :9153
# proxy 指 coredns 中没有找到记录,则去 /etc/resolv.conf 中的 nameserver 请求解析,而 coredns 容器中的 /etc/resolv.conf 是继承自宿主机的.
# 实际效果是如果不是 k8s 内部域名,就会去默认的 dns 服务器请求解析,并返回给 coredns 的请求者.
forward . /etc/resolv.conf
cache 30 # 允许缓存
loop # 如果找到循环,则检测简单的转发循环并停止 CoreDNS 进程
reload # 允许 Corefile 的配置自动更新.在更改 ConfigMap 后两分钟,修改生效
loadbalance # 这是一个循环 DNS 负载均衡器,可以在答案中随机化 A,AAAA 和 MX 记录的顺序
}
kind: ConfigMap
metadata:
creationTimestamp: "2019-06-10T03:19:01Z"
name: coredns
namespace: kube-system
四、node local dns
4.1 DNS间歇性5秒延迟
由于 Linux 内核中的缺陷,在 Kubernetes 集群中你很可能会碰到恼人的 DNS 间歇性 5 秒延迟问题.
原因是镜像底层库 DNS 解析行为默认使用 UDP 在同一个 socket 并发 A 和 AAAA 记录请求,由于 UDP 无状态,两个请求可能会并发创建 conntrack 表项,如果最终 DNAT 成同一个集群 DNS 的 Pod IP 就会导致 conntrack 冲突,由于 conntrack 的创建和插入是不加锁的,最终后面插入的 conntrack 表项就会被丢弃,从而请求超时,默认 5s 后重试,造成现象就是 DNS 5 秒延时.
For specific reasons, see:
4.2 NodeLocal DNSCache
NodeLocal DNSCache通过在集群上运行一个dnsCache daemonset来提高clusterDNS性能和可靠性.相比于纯coredns方案,nodelocaldns + coredns方案能够大幅降低DNS查询timeout的频次,提升服务稳定性.
nodelocaldns配置如下,nodelocaldns只配置了一个server,监听默认的UDP 53端口,4个zone.域名后缀为cluster.localof all domains as wellin-addr.arpa和ip6.arpaForm domain name to gocoredns进行域名解析,Other external domain names use the host's/etc/resolv.conf文件配置的nameserver进行解析.
缓存分为 256 个分片,Each shard can hold at most by default 39 个项目 - 总大小为 256 * 39 = 9984 个项目.
# 其中cluster.local、in-addr.arpa、ip6.arpa表示kubernetesThe plugin will handle the domain name suffix as cluster.localof all domains and handles all of themin-addr.arpa中的反向dns查找和ip6.arpa形式域名,其中kuberne# The cluster domain name suffix is in kubelet参数中配置的,默认值为cluster.local
apiVersion: v1
data:
Corefile: |
cluster.local:53 {
errors
cache {
success 9984 30 # Cache at most for successful caches9984A domain name resolution record,缓存时间为30s
denial 9984 5 # Cache at most for failed caches9984A domain name resolution record,缓存时间为5s
}
reload
loop
bind 169.254.25.10
forward . 10.233.0.3 {
force_tcp
}
prometheus :9253
health 169.254.25.10:9254
}
in-addr.arpa:53 {
errors
cache 30
reload
loop
bind 169.254.25.10
forward . 10.233.0.3 {
force_tcp
}
prometheus :9253
}
ip6.arpa:53 {
errors
cache 30
reload
loop
bind 169.254.25.10
forward . 10.233.0.3 {
force_tcp
}
prometheus :9253
}
.:53 {
errors
cache 30
reload
loop
bind 169.254.25.10
forward . /etc/resolv.conf
prometheus :9253
}
kind: ConfigMap
......
nodelocaldns + coredns方案,DNSThe query flow is as follows:
边栏推荐
- [PSQL] 函数、谓词、CASE表达式、集合运算
- Redis-cluster mode (master-slave replication mode, sentinel mode, clustering mode)
- Matlab paper illustration drawing template No. 41 - bubble chart (bubblechart)
- ApiPost is really fragrant and powerful, it's time to throw away Postman and Swagger
- The original question on the two sides of the automatic test of the byte beating (arranged according to the recording) is real and effective 26
- Google Chrome(谷歌浏览器)安装使用
- PSQL function, predicate, CASE expression and set operations
- Stress testing and performance analysis of node projects
- ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘解决方法
- LeetCode brush topic series - 787 K station transfer within the cheapest flight
猜你喜欢
Google Chrome(谷歌浏览器)安装使用
C语言小游戏——扫雷小游戏
Alluxio为Presto赋能跨云的自助服务能力
MySQL导入sql文件的三种方法
navicat连接MySQL报错:1045 - Access denied for user ‘root‘@‘localhost‘ (using password YES)
MySQL数据表的基本操作和基于 MySQL数据表的基本操作的综合实例项目
18 years of programmer career, read more than 200 programming books, pick out some essence to share with you
Redis-集群模式(主从复制模式,哨兵模式,集群化模式)
Introduction and use of apifox (1).
MySQL 8.0.29 set and modify the default password
随机推荐
ELK log analysis system
C语言入门实战(13):十进制数转二进制
leetcode 665. Non-decreasing Array 非递减数列(中等)
golang的time包:时间间隔格式化和秒、毫秒、纳秒等时间戳格式输出的方法
[PSQL] window function, GROUPING operator
ATM系统
C语言基础知识梳理总结:零基础入门请看这一篇
【C语言】LeetCode26.删除有序数组中的重复项&&LeetCode88.合并两个有序数组
Google notes cut hidden plug-in installation impression
Alluxio为Presto赋能跨云的自助服务能力
高防服务器防御的原理是什么
About the directory structure of the web application
Three methods of importing sql files in MySQL
公司不重视软件测试,新来的阿里P8给我们撰写了测试用例编写规范
非关系型数据库MongoDB的特点及安装
Detailed installation and configuration of golang environment
为什么4个字节的float要比8个字节的long大呢?
金山云团队分享 | 5000字读懂Presto如何与Alluxio搭配
ApiPost 真香真强大,是时候丢掉 Postman、Swagger 了
Linux CentOS8安装Redis6