CN112202940B - 一种kubernetes对外暴露Pod服务方式 - Google Patents

一种kubernetes对外暴露Pod服务方式 Download PDF

Info

Publication number
CN112202940B
CN112202940B CN202011161470.8A CN202011161470A CN112202940B CN 112202940 B CN112202940 B CN 112202940B CN 202011161470 A CN202011161470 A CN 202011161470A CN 112202940 B CN112202940 B CN 112202940B
Authority
CN
China
Prior art keywords
pod
public network
kubernets
cluster
service
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202011161470.8A
Other languages
English (en)
Other versions
CN112202940A (zh
Inventor
蔡锡生
王玉虎
李逸锋
王一钧
吴江法
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Softcom Power Information Technology Co ltd
Original Assignee
Hangzhou Langche Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hangzhou Langche Technology Co ltd filed Critical Hangzhou Langche Technology Co ltd
Priority to CN202011161470.8A priority Critical patent/CN112202940B/zh
Publication of CN112202940A publication Critical patent/CN112202940A/zh
Application granted granted Critical
Publication of CN112202940B publication Critical patent/CN112202940B/zh
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/50Address allocation
    • H04L61/5053Lease time; Renewal aspects
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/2514Translation of Internet protocol [IP] addresses between local and global IP addresses
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/4557Distribution of virtual machine instances; Migration and load balancing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45595Network integration; Enabling network access in virtual machine instances

Abstract

本发明公开了一种kubernetes对外暴露Pod服务方式,包括kubernetes集群、服务暴露控制器、弹性IP管理器、Pod IP漂移监听器,包括以下步骤:调用kubernetes API创建Pod;弹性IP管理器添加从电信运营商已购买的公网IP,并记录公网IP与租户的申请关系、公网IP与kubernetes集群上的集群节点的绑定关系;服务暴露控制器选择需要绑定的公网IP地址;服务暴露控制器查询Pod所在集群节点并远程登录,绑定公网IP到网卡接口上;通过执行iptables命令实现公网IP到Pod IP的数据包转发;Pod IP漂移监听器实时监听kubernetes集群中Pod IP的变更事件。

Description

一种kubernetes对外暴露Pod服务方式
技术领域
本发明涉及计算机软件技术应用技术领域,具体为kubernetes技术领域,特别涉及一种kubernetes对外暴露Pod服务方式。
背景技术
随着容器技术的成熟,容器编排工具也应运而生,其中Google开源的kubernetes容器编排工具目前在处于主流地位。kubernetes可以实现容器集群的自动化部署、自动扩缩容、维护等功能。
kuberetes上运行容器的最小资源调度单位是Pod,但是如果Pod运行在私有网络上,那么外部的公网用户是无法访问的;现在需要让公网的用户能访问到每个Pod的服务,且支持任意端口,任意4层或7层协议(如tcp/http),目前的kubernetes开源社区的解决方案是LoadBalancer,但是LoadBalancer的实现难度较大,只有云计算厂商才支持;由此如何在自建的私有云上实现容器服务的任意端口暴露就成了一个需要解决的问题。
现有的技术中,kuberntes可通过service提供五种服务暴露方式,其中可以用来做公网服务暴露的有NodePort和LoadBalancer。
对于NodePort服务暴露方式存在着以下缺陷:
1、必须是30000以上的端口,不符合任意端口暴露的需求;
2、NodePort会在所有节点暴露同一个端口,造成端口资源浪费。
对于LoadBalancer服务暴露方式存在着以下缺陷:
1、开发成本高,需要实现kubernetes负载均衡器的相关接口;
2、链路转发效率低,需要经过Loadbalancer—>NodePort—>Service—>Pod多个环节;
3、故障排查和修复成本高。
发明内容
针对现有技术存在的不足,本发明的目的在于提供一种kubernetes对外暴露Pod服务方式,针对现有两种服务暴露方式的不足,可以实现将kuberetes的Pod的服务暴露到公网、无传输协议限制、无端口号限制、Pod IP漂移后自动绑定。
本发明的上述技术目的是通过以下技术方案得以实现的:
一种kubernetes对外暴露Pod服务方式,包括kubernetes集群、服务暴露控制器、弹性IP管理器、Pod IP漂移监听器。
针对上述的多个模块,现进行具体的解释:
一、kubernetes中Pod服务暴露方案设计
1、申请公网IP地址;
2、在Pod运行的集群节点上实现公网IP与服务器网卡的绑定;
3、执行iptables命令,实现数据包由公网IP转发到Pod私网IP。
二、Pod IP漂移监听方案设计
1、监听kubernetes集群中Pod IP变更事件;
2、通知服务暴露控制器;
3、如果只是Pod IP发生变动,可以通过执行iptables命令实现公网IP到新Pod IP的数据包转发,删除旧的iptables规则;如果Pod漂移到了新的节点,先登陆Pod之前的节点将公网IP与网卡接口解绑,删除iptables规则,再重复步骤4,最终实现公网IP到Pod IP数据的转发。
根据上面的模块设计,本发明整个对外暴露Pod服务方式包括以下步骤:
步骤1,调用kubernetes API创建Pod;
步骤2,弹性IP管理器添加从电信运营商已购买的公网IP,并记录公网IP与租户的申请关系、公网IP与kubernetes集群上的集群节点的绑定关系;
步骤3,服务暴露控制器选择需要绑定的公网IP地址;
步骤4,服务暴露控制器查询Pod所在集群节点并远程登录,绑定公网IP到网卡接口上;通过执行iptables命令实现公网IP到Pod IP的数据包转发;
步骤5,Pod IP漂移监听器实时监听kubernetes集群中Pod IP的变更事件;如果只是Pod IP发生变动,通过执行iptables命令实现公网IP到新Pod IP的数据包转发,删除旧的iptables规则;如果Pod漂移到了新的节点,先登陆Pod之前的节点将公网IP与网卡接口解绑,删除iptables规则,再重复步骤4,最终实现公网IP到Pod IP数据的转发。
综上所述,本发明对比于现有技术的有益效果为:
1、转发效率高,弹性IP直接通过iptables地址转换到Pod IP,且在同节点绑定,不需要经过任何负载均衡器转发;
2、实现无传输协议限制和无端口号限制;
3、同一个集群节点上,同一个端口可以被多个IP地址复用而不冲突。
附图说明
附图1为kubernetes中Pod服务暴露方案设计示意图;
附图2和附图3为Pod IP漂移监听方案设计示意图。
具体实施方式
为了使本发明所要解决的技术问题、技术方案及有益效果更加清楚明白,以下结合实施例,对本发明进行详细的说明。应当说明的是,此处所描述的具体实施例仅用以解释本发明,并不用于限定本发明。
下面对本发明中所涉及的技术术语进行简单描述,以便相关人员更好地理解本方案。
kubernetes API是集群系统中的重要组成部分,Kubernetes中各种资源(对象)的数据通过该API接口被提交到后端的持久化存储(etcd)中,Kubernetes集群中的各部件之间通过该API接口实现解耦合。
Pod是Kubernetes中的最小调度单位,容器是应用程序部署的一种新方式,具有快速和轻量化的特性;一个Pod就是一个容器组,可以管理多个容器的生命周期。
iptables是一个配置Linux内核防火墙的命令行工具,可以检测、修改、转发、重定向和丢弃IPv4数据包。
Service是kubernetes中负载均衡器,通过标签关联到Pod,当用户访问service提供的IP时可以均衡地访问到各个Pod IP。
LoadBalancer是kubernetes中service的一种类型,依赖于云服务商底层资源调用。
NodePort是kubernetes中service的一种类型,在kubernetes集群所有节点上开放一个特定端口,任何发送到该端口的流量都被转发到关联的Pod。
一种kubernetes对外暴露Pod服务方式,包括kubernetes集群、服务暴露控制器、弹性IP管理器、Pod IP漂移监听器,由上述多个模块实现整个方案,在进行kubernetes对外暴露Pod服务之前,需预先构建kubernetes集群、服务暴露控制器、弹性IP管理器、Pod IP漂移监听器,现对上述模块的构建步骤和所具备功能进行具体介绍,具体内容如下:
搭建kubernetes集群,可调用kubernetes API创建Pod。
开发弹性IP管理器,此模块要实现功能如下:
1、添加从电信运营商已购买的公网IP;2、记录公网IP和租户的申请关系;3、记录公网IP和集群节点的绑定关系。
开发服务暴露控制器,此模块要实现功能如下:
1、选择要绑定的公网IP地址;2、查询Pod所在集群节点,然后登录到Pod所在的集群节点,执行IP到网卡接口的绑定;3、执行iptables命令,实现数据包由公网IP转发到PodIP;4、记录Pod和公网IP的绑定关系。
开发Pod IP漂移监听器,此模块要实现功能如下:
实时监听kubernetes集群中Pod IP的变更事件;通过执行iptables命令实现公网IP到新Pod IP的数据包转发。
根据上述预先构建的模块基础,现对本发明的kubernetes对外暴露Pod服务方式进行具体描述,参照图1所示,包含以下步骤:
步骤1,调用kubernetes API创建Pod;
步骤2,弹性IP管理器添加从电信运营商已购买的公网IP,并记录公网IP与租户的申请关系、公网IP与kubernetes集群上的集群节点的绑定关系;
步骤3,服务暴露控制器选择需要绑定的公网IP地址;
步骤4,服务暴露控制器查询Pod所在集群节点并远程登录,绑定公网IP到网卡接口上;通过执行iptables命令实现公网IP到Pod IP的数据包转发;
步骤5,Pod IP漂移监听器实时监听kubernetes集群中Pod IP的变更事件;通过执行iptables命令实现公网IP到新Pod IP的数据包转发。
针对步骤5中Pod IP漂移监听器实时监听kubernetes集群中Pod IP的变更事件,存在着两种变更事件或情形;现分开对在不同情形下,步骤5具体的操作进行具体阐述,设定旧Pod IP:10.244.0.2。
情形1:Pod同一个节点内IP漂移
参照图2所示,Pod IP漂移监听器实时监听kubernetes集群中的Pod状态,如果只是Pod IP发生变动,kubernetes集群发送Pod IP变动信息(新Pod IP:10.244.0.3)给PodIP漂移监听器,Pod IP漂移监听器并将此变更事件通知给服务暴露控制器,服务暴露控制器远程登陆到Pod之前的集群节点上,通过执行iptables命令实现公网IP到新Pod IP的数据包转发,删除旧的iptables规则。
情形2:不同Pod跨节点IP漂移
参照图3所示,Pod IP漂移监听器实时监听kubernetes集群中的Pod状态,如果Pod漂移到了新的节点,kubernetes集群发送Pod IP变动信息(新Pod IP:10.244.0.5)给PodIP漂移监听器,Pod IP漂移监听器并将此变更事件通知给服务暴露控制器,服务暴露控制器先远程登陆到Pod之前的集群节点上将公网IP与网卡接口解绑,并删除iptables规则;最后,服务暴露控制器查询Pod所在集群节点并远程登录,绑定公网IP到网卡接口上,通过执行iptables命令实现公网IP到Pod IP的数据包转发。
以上所述仅是本发明的示范性实施方式,而非用于限制本发明的保护范围,本发明的保护范围由所附的权利要求确定。

Claims (4)

1.一种kubernetes对外暴露Pod服务方式,其特征在于,包括kubernetes集群、服务暴露控制器、弹性IP管理器、Pod IP漂移监听器,该对外暴露Pod服务方式包括以下步骤:
步骤1,调用kubernetes API创建Pod;
步骤2,弹性IP管理器添加从电信运营商已购买的公网IP,并记录公网IP与租户的申请关系、公网IP与kubernetes集群上的集群节点的绑定关系;
步骤3,服务暴露控制器选择需要绑定的公网IP地址;
步骤4,服务暴露控制器查询Pod所在集群节点并远程登录,绑定公网IP到网卡接口上;通过执行iptables命令实现公网IP到Pod IP的数据包转发;
步骤5,Pod IP漂移监听器实时监听kubernetes集群中Pod IP的变更事件;通过执行iptables命令实现公网IP到新Pod IP的数据包转发。
2.根据权利要求1所述的一种kubernetes对外暴露Pod服务方式,其特征在于,步骤5中实时监听kubernetes集群中Pod IP的变更事件,如果只是Pod IP发生变动,通过执行iptables命令实现公网IP到新Pod IP的数据包转发;如果Pod漂移到了新的节点,先登陆Pod之前的节点将公网IP与网卡接口解绑,删除iptables规则,再重复步骤4,最终实现公网IP到Pod IP的数据包转发。
3.根据权利要求2所述的一种kubernetes对外暴露Pod服务方式,其特征在于,当只是Pod IP发生变动,其具体处理步骤如下:
kubernetes集群发送Pod IP变动信息给Pod IP漂移监听器;
Pod IP漂移监听器将此变更事件通知给服务暴露控制器;
服务暴露控制器远程登陆到Pod之前的集群节点上,通过执行iptables命令实现公网IP到新Pod IP的数据包转发,删除旧的iptables规则。
4.根据权利要求2所述的一种kubernetes对外暴露Pod服务方式,其特征在于,当Pod漂移到了新的节点,其具体处理步骤如下:
kubernetes集群发送Pod IP变动信息给Pod IP漂移监听器;
Pod IP漂移监听器并将此变更事件通知给服务暴露控制器;
服务暴露控制器先远程登陆到Pod之前的节点上将公网IP与网卡接口解绑,并删除iptables规则;
服务暴露控制器查询Pod所在集群节点并远程登录,绑定公网IP到网卡接口上,通过执行iptables命令实现公网IP到Pod IP的数据包转发。
CN202011161470.8A 2020-10-27 2020-10-27 一种kubernetes对外暴露Pod服务方式 Active CN112202940B (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011161470.8A CN112202940B (zh) 2020-10-27 2020-10-27 一种kubernetes对外暴露Pod服务方式

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011161470.8A CN112202940B (zh) 2020-10-27 2020-10-27 一种kubernetes对外暴露Pod服务方式

Publications (2)

Publication Number Publication Date
CN112202940A CN112202940A (zh) 2021-01-08
CN112202940B true CN112202940B (zh) 2022-03-04

Family

ID=74011535

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011161470.8A Active CN112202940B (zh) 2020-10-27 2020-10-27 一种kubernetes对外暴露Pod服务方式

Country Status (1)

Country Link
CN (1) CN112202940B (zh)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112448856B (zh) * 2021-01-28 2021-05-07 杭州朗澈科技有限公司 一种内网kubernetes对外提供公网访问的方法和系统
US11671401B2 (en) 2021-03-25 2023-06-06 Cisco Technology, Inc. Providing persistent external internet protocol address for extra-cluster services
CN112822061B (zh) * 2021-04-16 2021-07-20 杭州朗澈科技有限公司 一种边缘节点对外暴露服务的方法和系统
CN114189455B (zh) * 2021-12-08 2023-06-06 兴业银行股份有限公司 基于ebpf技术的容器网络流量监控统计方法及系统
CN114584373A (zh) * 2022-03-03 2022-06-03 浪潮云信息技术股份公司 一种公有云MySQL集群的公网限制访问方法及系统

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20200067789A1 (en) * 2016-06-24 2020-02-27 QiO Technologies Ltd. Systems and methods for distributed systemic anticipatory industrial asset intelligence
CN107947961B (zh) * 2017-10-17 2021-07-30 上海数讯信息技术有限公司 基于SDN的Kubernetes网络管理系统与方法
CN110881007B (zh) * 2018-09-05 2023-03-07 北京京东尚科信息技术有限公司 一种容器集群网络接入的方法和装置
CN108924268B (zh) * 2018-09-11 2021-05-25 网宿科技股份有限公司 一种容器云服务系统及pod创建方法、装置
CN109525590B (zh) * 2018-12-11 2021-12-07 中科曙光国际信息产业有限公司 数据包的传输方法及装置
CN111522628B (zh) * 2020-04-27 2024-04-09 上海仪电(集团)有限公司中央研究院 一种基于OpenStack的Kubernetes集群搭建部署方法、架构及存储介质

Also Published As

Publication number Publication date
CN112202940A (zh) 2021-01-08

Similar Documents

Publication Publication Date Title
CN112202940B (zh) 一种kubernetes对外暴露Pod服务方式
US20240039895A1 (en) Virtual private gateway for encrypted communication over dedicated physical link
US11150963B2 (en) Remote smart NIC-based service acceleration
US11463511B2 (en) Model-based load balancing for network data plane
CN107947961B (zh) 基于SDN的Kubernetes网络管理系统与方法
CN106850324B (zh) 虚拟网络接口对象
US7257817B2 (en) Virtual network with adaptive dispatcher
CN113037560B (zh) 业务流量切换方法及装置、存储介质、电子设备
CN103368768A (zh) 混合云环境中具有启发式监视的自动缩放网络覆盖
US20150169353A1 (en) System and method for managing data center services
US20220030055A1 (en) Bidirectional Communication Clusters
US20210112119A1 (en) High Availability and High Utilization Cloud Data Center Architecture for Supporting Telecommunications Services
EP3588859B1 (en) Network device configuration versioning
Scazzariello et al. Megalos: A scalable architecture for the virtualization of network scenarios
CN114363164B (zh) 云网络服务编排控制方法、系统、存储介质和电子设备
CN115987990A (zh) 多集群负载均衡方法、装置、电子设备及存储介质
Kaur et al. Live migration of containerized microservices between remote Kubernetes Clusters
CN114500545A (zh) 适用于容器的网络负载均衡方法、装置及电子设备
Bartolomeo Enabling Microservice Interactions within Heterogeneous Edge Infrastructures
CN106789380A (zh) 一种虚拟机网络一体化监管系统
Chaudhry et al. A distributed sdn application for cross-institution data access
US11616721B2 (en) In-packet version tagging utilizing a perimeter NAT
Kamarudin et al. A comparative study for bandwidth on demand using ONOS Reactive and Intent forwarding
US20240143448A1 (en) Distributed cloud system, data processing method of distributed cloud system, and storage medium
CN115378993B (zh) 支持命名空间感知的服务注册与发现的方法和系统

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20220805

Address after: 100094 Room 502, floor 5, building 16, East District, yard 10, northwest Wangdong Road, Haidian District, Beijing

Patentee after: Softcom power information technology (Group) Co.,Ltd.

Address before: Room 802, building 12, 1818-2, Wenyi West Road, Yuhang street, Yuhang District, Hangzhou City, Zhejiang Province, 310012

Patentee before: HANGZHOU LANGCHE TECHNOLOGY Co.,Ltd.

TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20220831

Address after: 518000 floor 2-24, building a, Zhongshe Plaza, No.1028, Buji Road, Dongxiao street, Luohu District, Shenzhen City, Guangdong Province

Patentee after: Shenzhen Softcom Power Information Technology Co.,Ltd.

Address before: 100094 Room 502, floor 5, building 16, East District, yard 10, northwest Wangdong Road, Haidian District, Beijing

Patentee before: Softcom power information technology (Group) Co.,Ltd.