【博客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. 修饰成员函数…...

STM32F4基本定时器使用和原理详解
STM32F4基本定时器使用和原理详解 前言如何确定定时器挂载在哪条时钟线上配置及使用方法参数配置PrescalerCounter ModeCounter Periodauto-reload preloadTrigger Event Selection 中断配置生成的代码及使用方法初始化代码基本定时器触发DCA或者ADC的代码讲解中断代码定时启动…...

376. Wiggle Subsequence
376. Wiggle Subsequence 代码 class Solution { public:int wiggleMaxLength(vector<int>& nums) {int n nums.size();int res 1;int prediff 0;int curdiff 0;for(int i 0;i < n-1;i){curdiff nums[i1] - nums[i];if( (prediff > 0 && curdif…...
生成 Git SSH 证书
🔑 1. 生成 SSH 密钥对 在终端(Windows 使用 Git Bash,Mac/Linux 使用 Terminal)执行命令: ssh-keygen -t rsa -b 4096 -C "your_emailexample.com" 参数说明: -t rsa&#x…...

04-初识css
一、css样式引入 1.1.内部样式 <div style"width: 100px;"></div>1.2.外部样式 1.2.1.外部样式1 <style>.aa {width: 100px;} </style> <div class"aa"></div>1.2.2.外部样式2 <!-- rel内表面引入的是style样…...
Spring AI 入门:Java 开发者的生成式 AI 实践之路
一、Spring AI 简介 在人工智能技术快速迭代的今天,Spring AI 作为 Spring 生态系统的新生力量,正在成为 Java 开发者拥抱生成式 AI 的最佳选择。该框架通过模块化设计实现了与主流 AI 服务(如 OpenAI、Anthropic)的无缝对接&…...
css3笔记 (1) 自用
outline: none 用于移除元素获得焦点时默认的轮廓线 broder:0 用于移除边框 font-size:0 用于设置字体不显示 list-style: none 消除<li> 标签默认样式 margin: xx auto 版心居中 width:100% 通栏 vertical-align 作用于行内元素 / 表格单元格ÿ…...

使用 Streamlit 构建支持主流大模型与 Ollama 的轻量级统一平台
🎯 使用 Streamlit 构建支持主流大模型与 Ollama 的轻量级统一平台 📌 项目背景 随着大语言模型(LLM)的广泛应用,开发者常面临多个挑战: 各大模型(OpenAI、Claude、Gemini、Ollama)接口风格不统一;缺乏一个统一平台进行模型调用与测试;本地模型 Ollama 的集成与前…...

【分享】推荐一些办公小工具
1、PDF 在线转换 https://smallpdf.com/cn/pdf-tools 推荐理由:大部分的转换软件需要收费,要么功能不齐全,而开会员又用不了几次浪费钱,借用别人的又不安全。 这个网站它不需要登录或下载安装。而且提供的免费功能就能满足日常…...

C/C++ 中附加包含目录、附加库目录与附加依赖项详解
在 C/C 编程的编译和链接过程中,附加包含目录、附加库目录和附加依赖项是三个至关重要的设置,它们相互配合,确保程序能够正确引用外部资源并顺利构建。虽然在学习过程中,这些概念容易让人混淆,但深入理解它们的作用和联…...

uniapp手机号一键登录保姆级教程(包含前端和后端)
目录 前置条件创建uniapp项目并关联uniClound云空间开启一键登录模块并开通一键登录服务编写云函数并上传部署获取手机号流程(第一种) 前端直接调用云函数获取手机号(第三种)后台调用云函数获取手机号 错误码常见问题 前置条件 手机安装有sim卡手机开启…...