当前位置:网站首页>Kubernetes 1.24: 避免为 Services 分配 IP 地址时发生冲突
Kubernetes 1.24: 避免为 Services 分配 IP 地址时发生冲突
2022-06-10 14:45:00 【CNCF】
作者: Antonio Ojea (Red Hat)
在 Kubernetes 中,Services[1]是一种抽象,用来暴露运行在一组 Pod 上的应用。Service 可以有一个集群范围的虚拟 IP 地址(使用 type: ClusterIP 的 Service)。客户端可以使用该虚拟 IP 地址进行连接, Kubernetes 为对该 Service 的访问流量提供负载均衡,以访问不同的后端 Pod。
Service ClusterIP 是如何分配的?
Service ClusterIP 有如下分配方式:
动态:群集的控制平面会自动从配置的 IP 范围内为 type:ClusterIP 的 Service 选择一个空闲 IP 地址。
静态:你可以指定一个来自 Service 配置的 IP 范围内的 IP 地址。
在整个集群中,每个 Service 的 ClusterIP 必须是唯一的。尝试创建一个已经被分配了的 ClusterIP 的 Service 将会返回错误。
为什么需要预留 Service Cluster IP?
有时,你可能希望让 Service 运行在众所周知的 IP 地址上,以便集群中的其他组件和用户可以使用它们。
最好的例子是集群的 DNS Service。一些 Kubernetes 安装程序将 Service IP 范围中的第 10 个地址分配给 DNS Service。假设你配置集群 Service IP 范围是 10.96.0.0/16,并且希望 DNS Service IP 为 10.96.0.10, 那么你必须创建一个如下所示的 Service:
apiVersion: v1
kind: Service
metadata:
labels:
k8s-app: kube-dns
kubernetes.io/cluster-service: "true"
kubernetes.io/name: CoreDNS
name: kube-dns
namespace: kube-system
spec:
clusterIP: 10.96.0.10
ports:
- name: dns
port: 53
protocol: UDP
targetPort: 53
- name: dns-tcp
port: 53
protocol: TCP
targetPort: 53
selector:
k8s-app: kube-dns
type: ClusterIP
但正如我之前解释的,IP 地址 10.96.0.10 没有被保留;如果其他 Service 在动态分配之前创建或与动态分配并行创建,则它们有可能分配此 IP 地址, 因此,你将无法创建 DNS Service,因为它将因冲突错误而失败。
如何避免 Service ClusterIP 冲突?{#avoid-ClusterIP-conflict}
在 Kubernetes 1.24 中,你可以启用一个新的特性门控 ServiceIPStaticSubrange。启用此特性允许你为 Service 使用不同的 IP 分配策略,减少冲突的风险。
ClusterIP 范围将根据公式 min(max(16, cidrSize / 16), 256) 进行划分, 该公式可描述为 “在不小于 16 且不大于 256 之间有一个步进量(Graduated Step)”。
分配默认使用上半段地址,当上半段地址耗尽后,将使用下半段地址范围。这将允许用户使用下半段地址中静态分配的地址并且降低冲突的风险。
举例:
Service IP CIDR 地址段:10.96.0.0/24
地址段大小:28 - 2 = 254 地址段偏移:min(max(16,256/16),256) = min(16,256) = 16 静态地址段起点:10.96.0.1 静态地址段终点:10.96.0.16 地址范围终点:10.96.0.254
Service IP CIDR 地址段:10.96.0.0/20
地址段大小:212 - 2 = 4094 地址段偏移:min(max(16,4094/16),256) = min(256,256) = 256 静态地址段起点:10.96.0.1 静态地址段终点:10.96.1.0 地址范围终点:10.96.15.254
Service IP CIDR 地址段:10.96.0.0/16
地址段大小:216 - 2 = 65534 地址段偏移:min(max(16,65536/16),256) = min(4096,256) = 256 静态地址段起点:10.96.0.1 静态地址段终点:10.96.1.0 地址范围终点:10.96.255.254
参考资料
[1]
Services: /zh/docs/concepts/services-networking/service/
[2]
KEPs: https://github.com/orgs/kubernetes/projects/10
[3]
issues: https://github.com/kubernetes/kubernetes/issues?q=is%3Aopen+is%3Aissue+label%3Asig%2Fnetwork
[4]
SIG Network 会议: https://github.com/kubernetes/community/tree/master/sig-network
CNCF (Cloud Native Computing Foundation)成立于2015年12月,隶属于Linux Foundation,是非营利性组织。
CNCF(云原生计算基金会)致力于培育和维护一个厂商中立的开源生态系统,来推广云原生技术。我们通过将最前沿的模式民主化,让这些创新为大众所用。
边栏推荐
- golang使用反射将一个结构体的数据直接复制到另一个结构体中(通过相同字段)
- What is CAS and ABA in CAS
- 【原创】POI 5.x XSSF和HSSF使用自定义字体颜色
- Scrollview is not at the top during initialization?
- JMeter 中如何实现接口之间的关联?
- SIGIR 2022 | HKU and Wuhan University put forward kgcl: a recommendation system based on knowledge map comparative learning
- CVPR 2022 Oral | SCI:实现快速、灵活与稳健的低光照图像增强
- 【離散數學期複習系列】二、一階邏輯(謂詞邏輯)
- WordPress的管理员用户名是如何泄露的
- Flutter listview, column, row learning personal summary 2
猜你喜欢

As a programmer, is it really that important for the underlying principles?

产品开发的早期阶段,是选择开发app还是小程序?

【離散數學期複習系列】二、一階邏輯(謂詞邏輯)

AUTOCAD——设置文字间距与行距

小程序网络请求Promise化

【离散数学期复习系列】三、集合的概念及运算
![[logodetection dataset processing] (4) extract the logo area of each picture](/img/cf/a8d5f840f52a56d498fa36b2343c07.png)
[logodetection dataset processing] (4) extract the logo area of each picture

【LogoDetection 数据集处理】(2)画出训练集图片的标注框

2022 practice questions and online simulation test for the third batch of Guangdong Provincial Safety Officer a certificate (principal)

Main features of IIC bus / communication process / read / write process
随机推荐
Data Lake (VI): Hudi and Flink integration
QT将接收到的json数据(含中文)unicode转utf8
QT transfers the received JSON data (including Chinese) Unicode to utf8
Wechat applet date comparison, calculation days
C # list of shallow copy and deep copy customized classes <>
Singleton pattern and special class design
Ue5 how to convert screen coordinates to world coordinates and World Directions
Shutter wrap button bottomnavigationbar learning summary 4
Euclidean algorithm for finding the greatest common factor
Consumption mode of Message Oriented Middleware
Brief description of adaptive function
洞见科技入选「爱分析· 隐私计算厂商全景报告」,获评金融解决方案代表厂商
Basic concept of data warehouse
【离散数学期复习系列】三、集合的概念及运算
golang使用反射将一个结构体的数据直接复制到另一个结构体中(通过相同字段)
Adding, deleting, modifying and querying databases with JDBC
[discrete mathematics review series] IV. figure
How the WordPress administrator user name was leaked
【Rust日报】2022-04-19 Rust异步框架的性能评估
【離散數學期複習系列】二、一階邏輯(謂詞邏輯)