【博客628】k8s pod访问集群外域名原理以及主机开启了systemd-resolved的不同情况
k8s pod访问集群外域名原理以及使用了systemd-resolved的不同情况
1、不同情况下的linux主机访问外部域名原理
没有使用systemd-resolved的linux主机上访问外部域名一般是按照以下步骤来的:
-
从dns缓存里查找域名与ip的映射关系
-
从/etc/hosts里查找域名与ip的映射关系
-
从/etc/resolv.conf里查找dns server,并发起解析请求
/etc/resolv.conf的内容一般如下:
nameserver 8.8.8.8
使用systemd-resolved的linux主机上访问外部域名一般是按照以下步骤来的:
-
从dns缓存里查找域名与ip的映射关系
-
从/etc/hosts里查找域名与ip的映射关系
-
将dns解析请求发给本地systemd-resolved,由其去代理处理,因为systemd-resolved修改了 /etc/resolv.conf,使得本地解析请求全部发到127.0.0.1:53
此时/etc/resolv.conf的内容一般如下:
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.nameserver 127.0.0.53
options edns0 trust-ad
-
然后systemd-resolved再根据/run/systemd/resolve/resolv.conf里面的dns server去发起请求
/run/systemd/resolve/resolv.conf记录的就是真正的后端dns server
cat /run/systemd/resolve/resolv.conf
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients directly to
# all known uplink DNS servers. This file lists all configured search domains.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.nameserver 8.8.8.8
nameserver 4.4.4.4
2、pod内访问集群内service域名
当pod启动的时候,一般用的是dnsPolicy: ClusterFirst,此时就会将pod的/etc/resolv.conf改为集群内coredns的地址,此时将解析请求发给coredns,由其代理处理:
集群内coredns的service ip:
kubectl get svc -n kube-systemNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 14d
pod内的/etc/resolv.conf在启动的时候被指定dns server为coredns service ip:
# cat /etc/resolv.conf in pod
nameserver 10.96.0.10
search default.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
3、pod内访问集群外service域名
-
使用dnsPolicy: ClusterFirst时:
pod内的/etc/resolv.conf在启动的时候被指定dns server为coredns service ip。
coredns的默认配置如下,此时如果用在集群内找不到这个service域名,就会用forward去转发请求,此时默认配置的是使用coredns内的 /etc/resolv.conf文件里的dns server
coredns default config:
.:53 {logerrorshealth {lameduck 5s}readykubernetes cluster.local in-addr.arpa ip6.arpa {pods insecurefallthrough in-addr.arpa ip6.arpattl 30}prometheus :9153forward . /etc/resolv.conf {max_concurrent 1000}cache 30loopreloadloadbalance}
-
使用dnsPolicy: Default时:
这种方式其实是让 kubelet 来决定使用何种 DNS 策略。而 kubelet 默认的方式,就是使用宿主机的 /etc/resolv.conf
简述: pod将dns代理到coredns,coredns使用kubelet的resolv指定的conf里面的内容来解析集群外的ip
4、coredns pod内的/etc/resolv.conf为什么有时跟主机/etc/resolv.conf不一致
场景:
当主机使用systemd-resolved来代理dns解析请求的时候,此时coredns pod内的/etc/resolv.conf跟主机/etc/resolv.conf不一致。
coredns pod内的/etc/resolv.conf:
cat /run/systemd/resolve/resolv.conf
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients directly to
# all known uplink DNS servers. This file lists all configured search domains.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.nameserver 8.8.8.8
nameserver 4.4.4.4
主机/etc/resolv.conf:
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.nameserver 127.0.0.53
options edns0 trust-ad
coredns pod内的/etc/resolv.conf为什么有时跟主机/etc/resolv.conf不一致的原因:
coredns的pod使用的是dnsPolicy: Default,此时就会使用kubelet指定的resolvConf的地址,默认是/etc/resolv.conf,但是当主机使用了systemd-resolved,则kubelet的的resolvConf变成了:resolvConf: /run/systemd/resolve/resolv.conf,也就是systemd-resolved存放真实后端dns server的文件路径,所以其实coredns的pod使用的是/run/systemd/resolve/resolv.conf里的真实后端dns server
使用了systemd-resolved的主机,kubelet使用/run/systemd/resolve/resolv.conf,而不用/etc/resolv.conf的原因:
-
如果coredns也是用/etc/resolv.conf,则集群里的dns解析请求都要代理到systemd-resolved,如果systemd-resolved挂了或者更新,那上层k8s集群里的dns解析也全部受到影响
-
这里面会有循环依赖的问题,参考coredns的官方文档解析:
Troubleshooting Loops In Kubernetes Clusters
A common cause of forwarding loops in Kubernetes clusters is an interaction with a local DNS cache on the host node (e.g. systemd-resolved). For example, in certain configurations systemd-resolved will put the loopback address 127.0.0.53 as a nameserver into /etc/resolv.conf. Kubernetes (via kubelet) by default will pass this /etc/resolv.conf file to all Pods using the default dnsPolicy rendering them unable to make DNS lookups (this includes CoreDNS Pods). CoreDNS uses this /etc/resolv.conf as a list of upstreams to forward requests to. Since it contains a loopback address, CoreDNS ends up forwarding requests to itself.
简述: coredns转到127.0.0.53,此时源目ip都是自己,自己在给自己转,就会有循环问题
5、在node上如何访问集群内的service域名
-
通用方法:直接修改网卡interface的配置文件,在里面配上DNS的解析server
-
不通用方法:linux没有使用systemd-resolved时:
在/etc/resolv.conf里加入coredns的service ip
-
不通用方法:linux使用systemd-resolved时:
- 在/etc/systemd/resolved.conf里加入coredns的service ip
[Resolve]
DNS=10.96.0.10
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#DNSOverTLS=no
#Cache=no-negative
#DNSStubListener=yes
#ReadEtcHosts=yes - systemctl restart systemd-resolved.service
- systemd-resolve --status查看结果
Global
LLMNR setting: no
MulticastDNS setting: no
DNSOverTLS setting: no
DNSSEC setting: no
DNSSEC supported: no
DNS Servers: 10.96.0.10
DNSSEC NTA: 10.in-addr.arpa
16.172.in-addr.arpa
168.192.in-addr.arpa
17.172.in-addr.arpa
18.172.in-addr.arpa
19.172.in-addr.arpa
20.172.in-addr.arpa
21.172.in-addr.arpa
…
…
- 在/etc/systemd/resolved.conf里加入coredns的service ip
-
注意:不可以直接改/etc/resolv.conf,否则重启后丢失配置,因为此时/etc/resolv.conf被systemd-resolved接管,每次重启由其来生成其中的内容
example:
# 指定使用coredns来解析集群内service:
root@:/home/ubuntu# nslookup vmselect-example-vmcluster-persistent.default.svc.cluster.local 10.96.0.10
Server: 10.96.0.10
Address: 10.96.0.10#53Name: vmselect-example-vmcluster-persistent.default.svc.cluster.local
Address: 10.244.0.5
Name: vmselect-example-vmcluster-persistent.default.svc.cluster.local
Address: 10.244.1.3
Name: vmselect-example-vmcluster-persistent.default.svc.cluster.local
Address: 10.244.1.4# /etc/resolv.conf加入:
nameserver 10.96.0.10# node上直接访问集群内service域名,此时会转到coredns去解析
root@:/home/ubuntu# curl vmselect-example-vmcluster-persistent.default.svc.cluster.local:8481/metrics
...
flag{name="promscrape.suppressScrapeErrors", value="false", is_set="false"} 1
flag{name="promscrape.suppressScrapeErrorsDelay", value="0s", is_set="false"} 1
flag{name="promscrape.yandexcloudSDCheckInterval", value="30s", is_set="false"} 1
flag{name="pushmetrics.extraLabel", value="", is_set="false"} 1
flag{name="pushmetrics.interval", value="10s", is_set="false"} 1
flag{name="pushmetrics.url", value="secret", is_set="false"} 1
flag{name="replicationFactor", value="1", is_set="false"} 1
flag{name="search.cacheTimestampOffset", value="5m0s", is_set="false"} 1
flag{name="search.denyPartialResponse", value="false", is_set="false"} 1
...
...
6、使用了systemd-resolved的主机,如果关闭systemd-resolved则机器的dns解析都会不同,即使主机能通后端dns server
ubuntu@:~$ sudo systemctl stop systemd-resolved.service
ubuntu@:~$ nslookup www.baidu.com
^C
ubuntu@:~$ dig www.baidu.com
^C
ubuntu@:~$ host www.baidu.com
^C
7、主机如何修改dns server
- 没有systemd-resolved,直接修改/etc/resolv.conf
- 如果机器装了systemd-resolved,那么就不可以直接改/etc/resolv.conf,则改法如下:
以加上8.8.8.8为例
root@:/home/ubuntu# cat /etc/systemd/resolved.conf
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details[Resolve]
DNS=8.8.8.8
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#DNSOverTLS=no
#Cache=no-negative
#DNSStubListener=yes
#ReadEtcHosts=yessystemctl restart systemd-resolved.serviceroot@:/home/ubuntu# systemd-resolve --status
GlobalLLMNR setting: no
MulticastDNS setting: noDNSOverTLS setting: noDNSSEC setting: noDNSSEC supported: noDNS Servers: 8.8.8.8DNSSEC NTA: 10.in-addr.arpa16.172.in-addr.arpa168.192.in-addr.arpa17.172.in-addr.arpa18.172.in-addr.arpa19.172.in-addr.arpa20.172.in-addr.arpa21.172.in-addr.arpa......
相关文章:
【博客628】k8s pod访问集群外域名原理以及主机开启了systemd-resolved的不同情况
k8s pod访问集群外域名原理以及使用了systemd-resolved的不同情况 1、不同情况下的linux主机访问外部域名原理 没有使用systemd-resolved的linux主机上访问外部域名一般是按照以下步骤来的: 从dns缓存里查找域名与ip的映射关系 从/etc/hosts里查找域名与ip的映射…...
测试3.测试方法的分类
3.测试分类 系统测试包括回归测试和冒烟测试 回归测试:修改了旧的代码后,重新测试功能是否正确,有没有引入新的错误或导致其它代码产生错误 冒烟测试:目的是确认软件基本功能正常,可以进行后续的正式测试工作 按是否…...
Android 基础知识4-2.9 FrameLayout(帧布局)详解
一、FrameLayout(帧布局)概述 FrameLayout又称作帧布局,它相比于LinearLayout和RelativeLayout要简单很多,因为它的应用场景也少了很多。这种布局没有方便的定位方式,所有的控件都会默认摆放在布局的左上角。 示例1代…...
Go语言xorm框架
xorm xorm是一个简单而强大的Go语言ORM库通过它可以使数据库操作非常简便。 官网: https://xorm.io/ 中文文档: https://gitea.com/xorm/xorm/src/branch/master/README_CN.md 特性 支持 Struct 和数据库表之间的灵活映射,并支持自动同步事务支持同时支持原始SQL…...
19_微信小程序之优雅实现侧滑菜单
19_微信小程序之优雅实现侧滑菜单一.先上效果图 要实现这样一个效果,布局其实很简单,整体布局是一个横向滚动的scroll-view,难点在于怎么控制侧滑菜单的回弹,以及寻找回弹的边界条件? 此篇文章主要是基于uni-app来实现的…...
JSP中JDBC与javaBean学习笔记
本博文源于博主偷偷复习期末的java web,博文主要讲述JDBC API与JavaBean,涉及driver,driver Manager\connection、statement接口、PreparedStatement接口、ResultSet接口,JavaBean包含一些标记介绍。 1.JDBC API JDBC由一组接口和类组成&am…...
编译Android系统源码推荐的电脑配置
工欲善其事,必先利其器。 看到很多客户,搞Android产品开发,用的电脑配置是惨不忍睹。 这些老板脑子有坑吗... ------------ 编译Android9推荐电脑配置: 处理器:酷睿i7 5代系列 8线程以上 内存: 8GB以上…...
加油站会员管理小程序实战开发教程10
上一篇我们介绍了计算距离及到店导航的功能,本篇我们介绍一下今日油价的功能。 如果要按日显示最新的数据,那么我们首先需要有数据源来存放每日的油价数据。这里涉及数据源的时候要考虑你的数据是只录入一条,还是每日录入一条。 录入一条呢,比较简单,但有个问题是如果我…...
shell编程之条件判断和流程控制
typora-copy-images-to: pictures typora-root-url: …\pictures 文章目录typora-copy-images-to: pictures typora-root-url: ..\..\pictures本节课程目标一、条件判断语法结构2. 条件判断相关参数㈠ 判断文件类型㈡ 判断文件权限㈢ 判断文件新旧㈣ 判断整数㈤ 判断字符串㈥ 多…...
第一次接触jquery
文章目录一.关于jqurey二.什么是jqurey三.上课实例1.表格 2.鼠标移动效果 3隐藏和显示效果代码如下注意一.关于jqurey 简而言之:jQuery 是一个 JavaScript 库。 jQuery 极大地简化了 JavaScript 编程。 二.什么是jqurey jQuery 是一个 JavaScript 函数库。 jQu…...
Vue中 引入使用 babel-polyfill 兼容低版本浏览器
注意:本文主要介绍的 vue-cli 版本:3.x, 4.x; 最近在项目中使用 webpack 打包后升级,用户反馈使用浏览器(chrome 45)访问白屏。经过排查发现:由于 chrome 45 无法兼容 ES6 语法导致的…...
ArcGIS Enterprise on Kubernetes 11.0安装示例
博客主页:https://tomcat.blog.csdn.net 博主昵称:农民工老王 主要领域:Java、Linux、K8S 期待大家的关注💖点赞👍收藏⭐留言💬 目录安装前置条件基本安装解压文件生成秘钥执行安装脚本配置DNS方法一方法二…...
js 防抖函数 节流函数
某些事件中(如 onresize onscroll onkeydown onkeyup onmousemove …),会连续触发函数的执行,如果函数执行一些耗时的操作(如请求数据…),会影响性能,也有可能造成服务器压力。这时可以用 防抖函数 或 节流函数解决这种问题。 防…...
Yarn节点unhealthy解决办法
这几天用Spark计算任务时,发现yarn上有两个节点不参与计算,很是tm的离谱。使用下面的命令查看Yarn上的nodemanager节点状态yarn node -list -all发现两个节点处于unhealthy状态。经过Google查明原因:这种情况一般是因为那个节点上HDFS文件过多…...
【jumpServer 功能梳理】
用户管理 1.1 用户列表 创建jumpServe 账号 ;角色分为用户 管理员;更新账号信息;查看用户详情以及授权的资产; 1.2 用户组 用户组,这个组的意义在于用一个统称对接资源;用户组包含多个用户,可以操作增加删除…...
中国各省人力资本测算就业人员受教育程度构成(2000-2021年)
数据来源:自主整理 时间跨度:2000-2021年 区域范围:全国各省 指标说明: 人力资本测算公式:(小学*6初中*9高中*12大专及以上*16)/六岁及以上人口 参考文献: [1]罗仁福, 刘承芳,…...
java面试题-集合篇
Collection1.Collection有哪些类?Java集合框架中的Collection接口是所有集合类的基础接口,定义了一些基本的集合操作,如添加元素、删除元素、判断是否包含某个元素等。常见的集合类包括List、Set和Queue。ListList接口定义了按照索引访问和操…...
Python 异步: 同时运行多个协程(10)
asyncio 的一个好处是我们可以同时运行许多协程。这些协同程序可以在一个组中创建并存储,然后同时一起执行。这可以使用 asyncio.gather() 函数来实现。 让我们仔细看看。 1. 什么是 Asyncio gather() asyncio.gather() 模块函数允许调用者将多个可等待对象组合在一…...
SVN 获取多版本间的更新内容
文章目录背景介绍操作步骤 - 获取某段时间内的代码更新内容背景介绍 公司有个项目期初明确要做微信小程序,没有做其他端的意向,并且当时团队人数有限,没有项目实践过 uniapp,项目时间周期紧,就没有用 uniapp 去实现 然…...
c++ const使用说明
作⽤ 1. 修饰变量,说明该变量不可以被改变; 2. 修饰指针,分为指向常量的指针和指针常量; 3. 常量引⽤,经常⽤于形参类型,即避免了拷⻉,⼜避免了函数对值的修改; 4. 修饰成员函数…...
挑战杯推荐项目
“人工智能”创意赛 - 智能艺术创作助手:借助大模型技术,开发能根据用户输入的主题、风格等要求,生成绘画、音乐、文学作品等多种形式艺术创作灵感或初稿的应用,帮助艺术家和创意爱好者激发创意、提高创作效率。 - 个性化梦境…...
docker详细操作--未完待续
docker介绍 docker官网: Docker:加速容器应用程序开发 harbor官网:Harbor - Harbor 中文 使用docker加速器: Docker镜像极速下载服务 - 毫秒镜像 是什么 Docker 是一种开源的容器化平台,用于将应用程序及其依赖项(如库、运行时环…...
云启出海,智联未来|阿里云网络「企业出海」系列客户沙龙上海站圆满落地
借阿里云中企出海大会的东风,以**「云启出海,智联未来|打造安全可靠的出海云网络引擎」为主题的阿里云企业出海客户沙龙云网络&安全专场于5.28日下午在上海顺利举办,现场吸引了来自携程、小红书、米哈游、哔哩哔哩、波克城市、…...
在HarmonyOS ArkTS ArkUI-X 5.0及以上版本中,手势开发全攻略:
在 HarmonyOS 应用开发中,手势交互是连接用户与设备的核心纽带。ArkTS 框架提供了丰富的手势处理能力,既支持点击、长按、拖拽等基础单一手势的精细控制,也能通过多种绑定策略解决父子组件的手势竞争问题。本文将结合官方开发文档,…...
【位运算】消失的两个数字(hard)
消失的两个数字(hard) 题⽬描述:解法(位运算):Java 算法代码:更简便代码 题⽬链接:⾯试题 17.19. 消失的两个数字 题⽬描述: 给定⼀个数组,包含从 1 到 N 所有…...
ETLCloud可能遇到的问题有哪些?常见坑位解析
数据集成平台ETLCloud,主要用于支持数据的抽取(Extract)、转换(Transform)和加载(Load)过程。提供了一个简洁直观的界面,以便用户可以在不同的数据源之间轻松地进行数据迁移和转换。…...
快刀集(1): 一刀斩断视频片头广告
一刀流:用一个简单脚本,秒杀视频片头广告,还你清爽观影体验。 1. 引子 作为一个爱生活、爱学习、爱收藏高清资源的老码农,平时写代码之余看看电影、补补片,是再正常不过的事。 电影嘛,要沉浸,…...
消息队列系统设计与实践全解析
文章目录 🚀 消息队列系统设计与实践全解析🔍 一、消息队列选型1.1 业务场景匹配矩阵1.2 吞吐量/延迟/可靠性权衡💡 权衡决策框架 1.3 运维复杂度评估🔧 运维成本降低策略 🏗️ 二、典型架构设计2.1 分布式事务最终一致…...
Pydantic + Function Calling的结合
1、Pydantic Pydantic 是一个 Python 库,用于数据验证和设置管理,通过 Python 类型注解强制执行数据类型。它广泛用于 API 开发(如 FastAPI)、配置管理和数据解析,核心功能包括: 数据验证:通过…...
如何在Windows本机安装Python并确保与Python.NET兼容
✅作者简介:2022年博客新星 第八。热爱国学的Java后端开发者,修心和技术同步精进。 🍎个人主页:Java Fans的博客 🍊个人信条:不迁怒,不贰过。小知识,大智慧。 💞当前专栏…...
