CoreDNS 说明

最近更新时间:2026-04-03 11:31:50

我的收藏

简介

组件介绍

CoreDNS 是 Kubernetes 集群的 DNS 服务组件,负责为集群内的 Service 和 Pod 提供 DNS 解析服务。它基于插件链架构,支持灵活的 DNS 配置,包括服务发现、缓存、转发、健康检查等功能。CoreDNS 通过 Corefile 配置文件定义 DNS 服务行为,支持多种插件组合满足不同场景需求。
CoreDNS 为集群创建时默认安装的组件,无需手动安装。

默认 Corefile 配置

.:53 {
template ANY HINFO . {
rcode NXDOMAIN
}
errors
health {
lameduck 30s
}
ready
kubernetes cluster.local. in-addr.arpa ip6.arpa {
pods insecure
fallthrough in-addr.arpa ip6.arpa
}
prometheus :9153
forward . /etc/resolv.conf {
prefer_udp
}
cache 30
reload
loadbalance
}
主要插件说明:
errors:将错误日志输出到标准输出。
health:提供健康检查端点(默认端口 8080),lameduck 30s 表示收到关闭信号后继续服务 30 秒。
ready:提供就绪检查端点(默认端口 8181)。
kubernetes:Kubernetes 服务发现插件,解析集群内 Service 和 Pod 的 DNS 记录。
prometheus:在 9153 端口暴露 Prometheus 指标。
forward:将非集群域名的 DNS 请求转发到上游 DNS 服务器。
cache:DNS 记录缓存,TTL 30 秒。
reload:支持 Corefile 热加载。
loadbalance:DNS 记录轮询负载均衡。

部署在集群内的 Kubernetes 对象

Kubernetes 对象名称
类型
请求资源
所属 Namespace
coredns
Deployment
每实例100mCPU,30Mi内存
kube-system
coredns
ConfigMap
-
kube-system
kube-dns
Service
-
kube-system
coredns
ServiceAccount
-
kube-system
system:coredns
ClusterRole
-
-
system:coredns
ClusterRoleBinding
-
-

限制条件

仅在 1.12 版本以上的 Kubernetes 集群支持。
Kubernetes 1.24+ 集群默认使用 CoreDNS v1.11.1-tke.1 镜像,低版本集群使用 CoreDNS 1.8.4 镜像。

特别说明

CoreDNS 默认部署 2 个副本,通过 Pod 反亲和性确保副本分布在不同节点上,避免单点故障。
支持多 AZ 高可用部署:通过 global.cluster.highAvailability 配置控制 zone 级别拓扑分布约束的强度。普通集群使用软约束(ScheduleAnyway),高可用集群使用硬约束(DoNotSchedule)。
如需进行 CoreDNS 升级,强烈建议先进行平滑升级配置,最大程度保证 DNS 服务的可用性,详情可参见 配置 CoreDNS 平滑升级

组件权限说明

权限说明

该组件权限是当前功能实现的最小权限依赖。

权限场景

功能
涉及对象
涉及操作权限
监听集群内 Service、Pod、Namespace、Endpoint 资源,实现服务发现。
endpoints、services、pods、namespaces
list/watch
监听 EndpointSlice 资源(Kubernetes 1.21+ 的服务发现优化)。
endpointslices
list/watch

权限定义

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: system:coredns
rules:
- apiGroups:
- '*'
resources:
- endpoints
- services
- pods
- namespaces
verbs:
- list
- watch
- apiGroups:
- discovery.k8s.io
resources:
- endpointslices
verbs:
- list
- watch

使用方法

CoreDNS 为集群创建时默认安装的组件,无需手动安装,暂不支持在控制台页面进行参数配置。
如需修改 Corefile,可直接编辑 kube-system 命名空间下的 configmap/coredns。配置修改后 CoreDNS 会自动热加载,无需重启 Pod。详细配置请参见 CoreDNS 官方文档

参数说明

参数
说明
类型
默认值
global.image.host
镜像仓库地址
string
ccr.ccs.tencentyun.com
global.kubednsClusterIP
kube-dns Service 的 ClusterIP,为空表示自动分配
string
""
global.cluster.highAvailability
是否为高可用集群(控制 zone 拓扑分布约束强度)
bool
false
global.podSpec.tolerations
额外的容忍配置(追加到默认的 CriticalAddonsOnly 之后)
list
[]
global.podSpec.priorityClassName
Pod 优先级类名
string
system-cluster-critical
coredns.replicas
CoreDNS 副本数
int
2
coredns.hostNetwork
是否使用主机网络
bool
false
coredns.image
自定义镜像地址,为空表示根据 Kubernetes 版本自动选择
string
""
coredns.server.port
DNS 服务端口
int
53
coredns.livenessProbe.port
存活探针端口
int
8080
coredns.readinessProbe.port
就绪探针端口
int
8181
coredns.resources.requests.cpu
CPU 请求
string
100m
coredns.resources.requests.mem
内存请求
string
30Mi
coredns.resources.limits.cpu
CPU 限制,为空表示不设置
string
""
coredns.resources.limits.mem
内存限制
string
2Gi