惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
Help Net Security
Help Net Security
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
C
Cisco Blogs
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
L
LINUX DO - 热门话题
Security Latest
Security Latest
A
Arctic Wolf
G
GRAHAM CLULEY
月光博客
月光博客
S
Securelist
D
Docker
J
Java Code Geeks
T
Troy Hunt's Blog
T
Tenable Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
SecWiki News
SecWiki News
S
Security @ Cisco Blogs
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
LINUX DO - 最新话题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
aimingoo的专栏
aimingoo的专栏
博客园 - 【当耐特】
H
Heimdal Security Blog
The Hacker News
The Hacker News
博客园 - 三生石上(FineUI控件)
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
Netflix TechBlog - Medium
Vercel News
Vercel News
Forbes - Security
Forbes - Security
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
B
Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
S
Secure Thoughts
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Check Point Blog
云风的 BLOG
云风的 BLOG
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Blog of Author Tim Ferriss
L
Lohrmann on Cybersecurity
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed

博客园 - fengjian1585

关闭ingress 8443 端口 tomcat 设置 catalina.out 按天切割 Harbor 启用 Trivy 禁用 MinIO 的 Web Console 重定向功能 堆设置了8G,java进程却占用了12G内存 k8s优化选项 pod启动后一直containerCreating状态解决 Kubernetes Cilium网络组件和CoreDNS配置 mkfs对磁盘设置标签 nginx代理两套k8s ingress 不同域名 pip 搭建源 使用 kubectl debug 创建临时调试容器 openvpn server证书过期处理 - fengjian1585 Harbor Swagger接口泄露漏洞处理 "too many open files" 文件句柄 Kafka 常见故障及解决方案 华为昇腾 910B GPU Nginx与Upstream之间产生大量TIME_WAIT连接的解决办法 debian libc.musl-x86_64.so.1 => not found
K8S的CoreDns配置文件添加域名解析
fengjian1585 · 2025-09-22 · via 博客园 - fengjian1585

一、CoreDns的概述
负责为整个k8s集群提供 DNS 服务,属于DNS插件。

基于dns的接口去实现集群内部的dns内部域名解析的一种能力。

k8s集群创建后,会在kube-system名称空间下默认生成两个coredns的pod,所有pod的域名请求会以负载均衡的方式向这两个coredns的pod进行域名解析。

kubectl get  pod -n kube-system  -o wide

二、CoreDns域名解析链路

image

coredns配置相应的域名解析后,会将配置结果存储在etcd键值对数据库中,当pod发起域名请求,这个域名就会经过kube-dns服务负载到coredns的pod上,coredns会通过api-server向etcd获取解析结果,然后将结果返回给pod,pod再根据域名解析结果,通过svc发起访问请求。

三、CoreDns域名解析配置

1.将特定域名解析到单个IP

kubectl edit cm -n kube-system coredns
#加入下面的配置
#注意,“缩进”不能使用tab,要使用空格,
 hosts {
   192.168.159.82 www.aaa.com
   fallthrough
 }

image

2.将特定域名解析到特定的DNS服务器

kubectl edit cm -n kube-system coredns
    #加入如下配置
    #缩进与 .:53 同级
 
    bbb.com:53 {
        errors
        cache 30
        forward . 192.168.159.82 {
          prefer_udp
        }

image

3.将所有域名解析到特定的DNS服务器 

kubectl edit cm -n kube-system coredns
    #加入一下配置
forward . 192.168.159.82 {
  prefer_udp
}

image

kubectl debug 进入到coredns 内部,coredns 无法使用 exec 登录
无需改镜像、无需重建 Pod,就能把一只 临时调试容器 注入目标 Pod,与其共享 PID/Net/IPC/Mount,像“开启外挂”一样查看系统状态。本文将借助 kubectl debug 实地探访 CoreDNS 的 /etc/resolv.conf,并详解整条命令的每个参数,

kubectl -n kube-system debug -it \
  --image=busybox \
  --target=coredns \
  $(kubectl get pods -n kube-system -l k8s-app=kube-dns -o jsonpath='{.items[0].metadata.name}') \
  -- sh 

参考:
https://blog.csdn.net/qq_44732146/article/details/144050443

https://blog.csdn.net/m0_73562288/article/details/135238255