Movatterモバイル変換


[0]ホーム

URL:


CN111752681A - Request processing method, apparatus, server, and computer-readable storage medium - Google Patents

Request processing method, apparatus, server, and computer-readable storage medium
Download PDF

Info

Publication number
CN111752681A
CN111752681ACN202010601316.1ACN202010601316ACN111752681ACN 111752681 ACN111752681 ACN 111752681ACN 202010601316 ACN202010601316 ACN 202010601316ACN 111752681 ACN111752681 ACN 111752681A
Authority
CN
China
Prior art keywords
target
service
resource
external communication
communication address
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.)
Granted
Application number
CN202010601316.1A
Other languages
Chinese (zh)
Other versions
CN111752681B (en
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.)
Guangzhou Huaduo Network Technology Co Ltd
Original Assignee
Guangzhou Huaduo Network 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 Guangzhou Huaduo Network Technology Co LtdfiledCriticalGuangzhou Huaduo Network Technology Co Ltd
Priority to CN202010601316.1ApriorityCriticalpatent/CN111752681B/en
Publication of CN111752681ApublicationCriticalpatent/CN111752681A/en
Application grantedgrantedCritical
Publication of CN111752681BpublicationCriticalpatent/CN111752681B/en
Activelegal-statusCriticalCurrent
Anticipated expirationlegal-statusCritical

Links

Images

Classifications

Landscapes

Abstract

Translated fromChinese

本申请涉及一种请求处理方法、装置、服务器和计算机可读存储介质。所述方法包括:接收客户端发送的服务请求,所述服务请求携带有目标URI;基于所述目标URI查询配置文件,得到能够响应所述服务请求的多个目标服务的对外通信地址,其中,各所述目标服务部署于容器或者物理机中,所述配置文件包括URI与部署于容器或者物理机的服务的对外通信地址的对应关系;基于预设的负载均衡策略,从所述多个目标服务中确定标的服务,基于所述标的服务的对外通信地址将所述服务请求定向至所述标的服务。采用本方法能够基于Kubernetes让部署在物理机中的服务响应客户端的服务请求。

Figure 202010601316

The present application relates to a request processing method, apparatus, server, and computer-readable storage medium. The method includes: receiving a service request sent by a client, where the service request carries a target URI; and querying a configuration file based on the target URI to obtain external communication addresses of multiple target services that can respond to the service request, wherein, Each of the target services is deployed in a container or a physical machine, and the configuration file includes a correspondence between the URI and the external communication address of the service deployed in the container or physical machine; A subject service is determined in the service, and the service request is directed to the subject service based on the external communication address of the subject service. By using this method, the service deployed in the physical machine can respond to the service request of the client based on Kubernetes.

Figure 202010601316

Description

Translated fromChinese
请求处理方法、装置、服务器和计算机可读存储介质Request processing method, apparatus, server, and computer-readable storage medium

技术领域technical field

本申请涉及互联网技术领域,特别是涉及一种请求处理方法、装置、服务器和计算机可读存储介质。The present application relates to the field of Internet technologies, and in particular, to a request processing method, apparatus, server, and computer-readable storage medium.

背景技术Background technique

Kubernetes是一个开源的、用于管理容器化的服务的集群,Kubernetes的目标是让部署容器化的服务简单并且高效,Kubernetes提供了服务的应用部署,规划,更新,维护。Kubernetes is an open source cluster for managing containerized services. The goal of Kubernetes is to make the deployment of containerized services simple and efficient. Kubernetes provides application deployment, planning, updating, and maintenance of services.

目前,很多企业的早期服务都是部署在物理机上的,在企业实现容器化、进行服务迁移的过程中,部分存在依赖关系的服务仍然需要继续部署在物理机中。At present, the early services of many enterprises are deployed on physical machines. During the process of containerization and service migration, some services with dependencies still need to be deployed on physical machines.

因此,如何基于Kubernetes让部署在物理机中的服务能够响应客户端的服务请求,成为目前亟待解决的问题。Therefore, how to enable services deployed in physical machines to respond to client service requests based on Kubernetes has become an urgent problem to be solved.

发明内容SUMMARY OF THE INVENTION

基于此,有必要针对上述技术问题,提供一种能够基于Kubernetes让部署在物理机中的服务响应客户端的服务请求的请求处理方法、装置、服务器和计算机可读存储介质。Based on this, it is necessary to provide a request processing method, apparatus, server, and computer-readable storage medium that can make a service deployed in a physical machine respond to a client's service request based on Kubernetes, aiming at the above technical problems.

第一方面,提供了一种请求处理方法,所述方法包括:In a first aspect, a request processing method is provided, the method comprising:

接收客户端发送的服务请求,所述服务请求携带有目标URI;Receive a service request sent by the client, where the service request carries a target URI;

基于所述目标URI查询配置文件,得到能够响应所述服务请求的多个目标服务的对外通信地址,其中,各所述目标服务部署于容器或者物理机中,所述配置文件包括URI与部署于容器或者物理机的服务的对外通信地址的对应关系;Querying a configuration file based on the target URI to obtain the external communication addresses of multiple target services that can respond to the service request, wherein each target service is deployed in a container or a physical machine, and the configuration file includes a URI and a configuration file deployed in a The correspondence between the external communication addresses of the services of the container or physical machine;

基于预设的负载均衡策略,从所述多个目标服务中确定标的服务,基于所述标的服务的对外通信地址将所述服务请求定向至所述标的服务。Based on a preset load balancing policy, a target service is determined from the plurality of target services, and the service request is directed to the target service based on an external communication address of the target service.

在其中一个实施例中,所述基于所述目标URI查询配置文件之前,所述方法还包括:In one of the embodiments, before the querying the configuration file based on the target URI, the method further includes:

获取至少一个Ingress资源,各所述Ingress资源包括URI和service资源名;Obtain at least one Ingress resource, each described Ingress resource includes a URI and a service resource name;

对于各所述Ingress资源,基于所述Ingress资源包括的service资源名查找目标service资源,基于所述目标service资源中的指示信息,获取与所述目标service资源相关联的部署于物理机或者容器的服务的对外通信地址,并建立所述Ingress资源包括的URI和与所述目标service资源相关联的服务的对外通信地址的对应关系;For each of the Ingress resources, the target service resource is searched based on the service resource name included in the Ingress resource, and based on the indication information in the target service resource, the information deployed on the physical machine or container associated with the target service resource is obtained. the external communication address of the service, and establish a correspondence between the URI included in the Ingress resource and the external communication address of the service associated with the target service resource;

基于各所述对应关系,创建所述配置文件。Based on each of the corresponding relationships, the configuration file is created.

在其中一个实施例中,所述指示信息包括自定义资源名,所述基于所述目标service资源中的指示信息,获取与所述目标service资源相关联的部署于物理机或者容器的服务的对外通信地址,包括:In one embodiment, the indication information includes a custom resource name, and based on the indication information in the target service resource, the external information of the service deployed on the physical machine or container associated with the target service resource is obtained. Mailing address, including:

基于所述自定义资源名查找目标自定义资源,所述目标自定义资源包括第一对外通信地址,所述第一对外通信地址为与所述目标service资源相关联的部署于物理机中的服务的对外通信地址;Find a target custom resource based on the custom resource name, where the target custom resource includes a first external communication address, and the first external communication address is a service deployed in a physical machine associated with the target service resource 's external correspondence address;

从所述目标自定义资源中获取所述第一对外通信地址。Obtain the first external communication address from the target custom resource.

在其中一个实施例中,所述目标service资源包括注解字段,所述注解字段包括所述自定义资源名。In one embodiment, the target service resource includes an annotation field, and the annotation field includes the user-defined resource name.

在其中一个实施例中,所述目标自定义资源包括spec字段,所述spec字段包括所述第一对外通信地址;In one of the embodiments, the target custom resource includes a spec field, and the spec field includes the first external communication address;

所述目标自定义资源还包括apiVersion字段、kind字段、metadata字段以及健康检查字段中的至少一个,其中,所述apiVersion字段包括所述目标自定义资源的版本信息,所述kind字段包括所述目标自定义资源的类型信息,所述metadata字段包括所述目标自定义资源的名称以及所述目标自定义资源的命名空间信息,所述健康检查字段包括健康检查地址,所述健康检查地址用于供所述服务器对与所述目标service资源相关联的部署于物理机中的服务进行健康检查。The target custom resource also includes at least one of an apiVersion field, a kind field, a metadata field, and a health check field, wherein the apiVersion field includes version information of the target custom resource, and the kind field includes the target Type information of the custom resource, the metadata field includes the name of the target custom resource and the namespace information of the target custom resource, the health check field includes a health check address, and the health check address is used for The server performs a health check on the service deployed in the physical machine associated with the target service resource.

在其中一个实施例中,在所述目标自定义资源包括所述健康检查字段的情况下,所述方法还包括:In one embodiment, when the target custom resource includes the health check field, the method further includes:

基于所述健康检查地址和所述第一对外通信地址,生成目标地址;generating a target address based on the health check address and the first external communication address;

向所述目标地址发送健康检查指令,得到返回结果,所述返回结果用于表征所述第一对外通信地址对应的部署于物理机中的服务存活或者不存活;Send a health check instruction to the target address, and obtain a return result, where the return result is used to indicate that the service deployed in the physical machine corresponding to the first external communication address is alive or not;

若根据所述返回结果确定所述第一对外通信地址对应的部署于物理机中的服务不存活,则将所述配置文件中的所述第一对外通信地址删除。If it is determined according to the returned result that the service deployed in the physical machine corresponding to the first external communication address does not survive, the first external communication address in the configuration file is deleted.

在其中一个实施例中,所述指示信息包括Pod资源标签以及第二对外通信地址的第一部分,所述第二对外通信地址为与所述目标service资源相关联的部署于容器中的服务的对外通信地址,所述基于所述目标service资源中的指示信息,获取与所述目标service资源相关联的部署于物理机或者容器的服务的对外通信地址,包括:In one embodiment, the indication information includes a Pod resource label and a first part of a second external communication address, where the second external communication address is the external communication address of the service deployed in the container associated with the target service resource The communication address, based on the indication information in the target service resource, to obtain the external communication address of the service deployed on the physical machine or container associated with the target service resource, including:

基于所述Pod资源标签查找目标Pod资源,所述目标Pod资源包括所述第二对外通信地址的第二部分;Find the target Pod resource based on the Pod resource label, and the target Pod resource includes the second part of the second external communication address;

从所述目标Pod资源中获取所述第二部分,并基于所述第一部分和所述第二部分生成所述第二对外通信地址。The second part is obtained from the target Pod resource, and the second external communication address is generated based on the first part and the second part.

第二方面,提供了一种请求处理装置,所述装置包括:In a second aspect, a request processing apparatus is provided, the apparatus comprising:

第一控制模块,用于接收客户端发送的服务请求,所述服务请求携带有目标URI;a first control module, configured to receive a service request sent by a client, where the service request carries a target URI;

第二控制模块,用于基于所述目标URI查询配置文件,得到能够响应所述服务请求的多个目标服务的对外通信地址,其中,各所述目标服务部署于容器或者物理机中,所述配置文件包括URI与部署于容器或者物理机的服务的对外通信地址的对应关系;The second control module is configured to query the configuration file based on the target URI to obtain the external communication addresses of multiple target services that can respond to the service request, wherein each of the target services is deployed in a container or a physical machine, and the The configuration file includes the correspondence between the URI and the external communication address of the service deployed in the container or physical machine;

第三控制模块,用于基于预设的负载均衡策略,从所述多个目标服务中确定标的服务,基于所述标的服务的对外通信地址将所述服务请求定向至所述标的服务。The third control module is configured to determine a target service from the plurality of target services based on a preset load balancing policy, and direct the service request to the target service based on the external communication address of the target service.

第三方面,提供了一种服务器,包括存储器和处理器,所述存储器存储有计算机程序,所述处理器执行所述计算机程序时实现如上述第一方面所述的请求处理方法。In a third aspect, a server is provided, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the request processing method according to the first aspect above is implemented.

第四方面,提供了一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时如上述第一方面所述的请求处理方法。In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the request processing method according to the above-mentioned first aspect is provided.

本申请实施例提供的技术方案带来的有益效果至少包括:The beneficial effects brought by the technical solutions provided in the embodiments of the present application include at least:

传统技术中,在企业实现容器化的过程中,企业早期部署在物理机中的服务将被迁移至Kubernetes的容器内。服务器可以将客户端发送的服务请求定向至某一个容器内的服务,由该服务响应该服务请求。但在实际的容器化过程中,由于一些企业担心容器不稳定可能会导致服务崩溃,或由于某些存在依赖关系的服务必须部署在物理机中,因此仍然会有部分服务继续部署在物理机中;但是,上述传统技术中服务器并不能将客户端的服务请求定向至部署在物理中的服务,这就无法满足实际的业务需求。In traditional technologies, in the process of enterprise containerization, the services deployed in the physical machine in the early stage of the enterprise will be migrated to the Kubernetes container. The server can direct the service request sent by the client to a service in a container, and the service responds to the service request. However, in the actual containerization process, because some enterprises worry that the instability of the container may lead to service crashes, or because some services with dependencies must be deployed in physical machines, some services will still continue to be deployed in physical machines. However, in the above-mentioned traditional technology, the server cannot direct the service request of the client to the service deployed in the physical system, which cannot meet the actual business requirements.

本申请实施例提供的技术方案,通过接收客户端发送的服务请求,其中,服务请求携带有目标URI;而后,基于该目标URI查询配置文件,得到能够响应该服务请求的多个目标服务的对外通信地址,其中,各目标服务部署于容器或者物理机中,配置文件包括URI与部署于容器或者物理机的服务的对外通信地址的对应关系;再基于预设的负载均衡策略,从该多个目标服务中确定标的服务,基于该标的服务的对外通信地址将服务请求定向至该标的服务。由于配置文件中包括部署于物理机的服务的对外通信地址,因此,服务器可以发现配置文件中包括的部署在物理机中的服务,从而能够将服务请求定向至部署在物理机中的标的服务,实现了基于Kubernetes让部署在物理机中的服务能够响应客户端的服务请求,可以更好地满足客户需求。The technical solution provided by the embodiments of the present application is to receive a service request sent by a client, wherein the service request carries a target URI; then, based on the target URI, a configuration file is queried to obtain the external information of multiple target services that can respond to the service request. Communication address, where each target service is deployed in a container or physical machine, and the configuration file includes the correspondence between URI and the external communication address of the service deployed in the container or physical machine; The target service is determined in the target service, and the service request is directed to the target service based on the external communication address of the target service. Since the configuration file includes the external communication address of the service deployed on the physical machine, the server can discover the service deployed in the physical machine included in the configuration file, so that the service request can be directed to the target service deployed in the physical machine. Based on Kubernetes, services deployed in physical machines can respond to client service requests, which can better meet customer needs.

附图说明Description of drawings

图1为一个实施例中请求处理方法的应用环境图;1 is an application environment diagram of a request processing method in one embodiment;

图2为一个实施例中请求处理方法的流程示意图;2 is a schematic flowchart of a request processing method in one embodiment;

图3-1为另一个实施例中请求处理方法的流程示意图;3-1 is a schematic flowchart of a request processing method in another embodiment;

图3-2为一种示例性的基于Kubernetes的服务架构示意图;Figure 3-2 is a schematic diagram of an exemplary Kubernetes-based service architecture;

图4为另一个实施例中服务器进行健康检查的流程示意图;4 is a schematic flowchart of a health check performed by a server in another embodiment;

图5为另一个实施例中请求处理方法的流程示意图;5 is a schematic flowchart of a request processing method in another embodiment;

图6为一个实施例中请求处理装置的结构框图;6 is a structural block diagram of a request processing apparatus in one embodiment;

图7为另一个实施例中请求处理装置的结构框图;7 is a structural block diagram of a request processing apparatus in another embodiment;

图8为一个实施例中服务器的内部结构图。FIG. 8 is an internal structure diagram of a server in one embodiment.

具体实施方式Detailed ways

为了使本申请的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。In order to make the purpose, technical solutions and advantages of the present application more clearly understood, the present application will be described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application, but not to limit the present application.

Kubernetes是一个用于管理容器化的服务的集群。在Kubernetes中,定义了各种各样的资源,例如,Service,Pod等。其中,Pod是Kubernetes中的最小部署单元,Pod是一个环境(包括容器、存储、ip地址:端口号、容器配置),Pod中可以运行一个或多个容器,在一个Pod内部的容器共享所有资源,包括共享Pod的endpoint(ip地址:端口号)和磁盘;Service用于对部署于容器内的服务的自动发现。Kubernetes is a cluster for managing containerized services. In Kubernetes, various resources are defined, for example, Service, Pod, etc. Among them, Pod is the smallest deployment unit in Kubernetes, Pod is an environment (including container, storage, IP address: port number, container configuration), one or more containers can run in a Pod, and containers within a Pod share all resources , including the shared Pod's endpoint (ip address: port number) and disk; Service is used for automatic discovery of services deployed in containers.

Ingress也是Kubernetes中定义的一种资源,Ingress用于将Kubernetes中部署的服务对外暴露。它定义了一组可以供客户端访问的域名、URI、SSL以及Service资源名等,通过Ingress,可以供客户端访问部署在Kubernetes的容器中的服务。但是,Ingress本身并不能进行流量穿透,它仅仅是规则的集合,这些规则想要发挥作用则必须依靠Ingresscontroller来实现。Ingress is also a resource defined in Kubernetes. Ingress is used to expose services deployed in Kubernetes. It defines a set of domain names, URIs, SSL, and Service resource names that can be accessed by clients. Through Ingress, clients can access services deployed in Kubernetes containers. However, Ingress itself cannot carry out traffic penetration, it is only a collection of rules, and these rules must be implemented by Ingresscontroller if they want to work.

Ingress controller可以部署在服务器中,负责在Kubernetes实现Ingress。同时该服务器中还可以部署Nginx,Ingress controller通过与Kubernetes API交互,动态地去感知Kubernetes中Ingress的规则变化,然后读取该规则变化,按照模板生成Nginx的配置文件,并将该配置文件写入Nginx,Nginx则可以按照该配置文件将客户端的服务请求定向至某一个容器内的服务,由该服务响应该服务请求。The Ingress controller can be deployed in the server and is responsible for implementing Ingress in Kubernetes. At the same time, Nginx can also be deployed in the server. The Ingress controller can dynamically perceive the rule changes of Ingress in Kubernetes by interacting with the Kubernetes API, and then read the rule changes, generate the Nginx configuration file according to the template, and write the configuration file into the configuration file. Nginx, Nginx can direct the client's service request to a service in a container according to the configuration file, and the service responds to the service request.

然而,Pod主要供服务所在集群的内部访问使用,对于集群外的客户端是不可见的,而Ingress只定义了外部流量到达Pod,即按照Ingress的定义,客户端的服务请求只能到达部署在容器内的服务。如果存在客户担心容器不稳定需要部分服务部署在物理机中,或由于某些存在依赖关系的服务必须部署在物理机中的情况,这就导致服务器并不能将客户端的服务请求定向至部署在物理中的服务,无法满足实际的业务需求。However, Pod is mainly used for internal access of the cluster where the service is located, and is invisible to clients outside the cluster. Ingress only defines the arrival of external traffic to the Pod, that is, according to the definition of Ingress, the client's service request can only reach the container deployed in the container. services within. If the customer is worried that the container is unstable and some services need to be deployed on the physical machine, or because some services with dependencies must be deployed on the physical machine, the server cannot direct the client's service request to the physical machine. The services in the service cannot meet the actual business needs.

考虑到以上情况,本申请实施例提供了一种请求处理方法、装置、服务器和计算机可读存储介质,在该方法中,服务器接收客户端发送的服务请求,其中,服务请求携带有目标URI;而后,基于该目标URI查询配置文件,查询后得到能够响应该服务请求的多个目标服务的对外通信地址,其中,各目标服务部署于容器或者物理机中,配置文件包括URI与部署于容器或者物理机的服务的对外通信地址的对应关系;再基于预设的负载均衡策略,从该多个目标服务中确定标的服务,基于该标的服务的对外通信地址将服务请求定向至该标的服务。这样,由于配置文件中包括部署于物理机的服务的对外通信地址,所以服务器能够将服务请求定向至部署在物理机中的标的服务,由此,实现了基于Kubernetes让部署在物理机中的服务能够响应客户端的服务请求,从而可以更好地满足客户需求。Considering the above situation, embodiments of the present application provide a request processing method, device, server, and computer-readable storage medium, in which the server receives a service request sent by a client, wherein the service request carries a target URI; Then, query the configuration file based on the target URI, and obtain the external communication addresses of multiple target services that can respond to the service request. The correspondence between the external communication addresses of the services of the physical machine; and then based on the preset load balancing strategy, the target service is determined from the multiple target services, and the service request is directed to the target service based on the external communication address of the target service. In this way, since the configuration file includes the external communication address of the service deployed on the physical machine, the server can direct the service request to the target service deployed on the physical machine, thus realizing the service deployed in the physical machine based on Kubernetes. Able to respond to the client's service request, so as to better meet the customer's needs.

下面,将对本申请实施例提供的请求处理方法所涉及到的实施环境进行简要说明。Below, the implementation environment involved in the request processing method provided by the embodiment of the present application will be briefly described.

如图1所示,该实施环境可以包括客户端101、服务器102、Kubernetes103以及物理机104。服务器102可以通过网络与客户端101通信,服务器102也可以通过网络与Kubernetes103和物理机104进行通信。As shown in FIG. 1 , the implementation environment may include aclient 101 , aserver 102 , aKubernetes 103 and aphysical machine 104 . Theserver 102 can communicate with theclient 101 through the network, and theserver 102 can also communicate with theKubernetes 103 and thephysical machine 104 through the network.

其中,服务器102可以是一台服务器,也可以是由多台服务器组成的服务器集群,服务器102可以是塔式服务器、机架服务器、刀片式服务器、高密度服务器、单路服务器、双路服务器或者多路服务器等,本申请实施例对服务器102的类型不作具体限定。其中,客户端101可以是个人计算机、笔记本电脑、媒体播放器、智能电视、智能手机、平板电脑和便携式可穿戴设备等,本申请实施例对客户端101的类型也不作具体限定。Theserver 102 may be a single server, or a server cluster composed of multiple servers, and theserver 102 may be a tower server, a rack server, a blade server, a high-density server, a single-socket server, a dual-socket server, or A multi-channel server, etc., the type of theserver 102 is not specifically limited in this embodiment of the present application. Theclient 101 may be a personal computer, a notebook computer, a media player, a smart TV, a smart phone, a tablet computer, a portable wearable device, etc. The embodiment of the present application does not specifically limit the type of theclient 101.

在一个实施例中,如图2所示,提供了一种请求处理方法,以该方法应用于图1中的服务器为例进行说明,该方法包括步骤S100、步骤S200以及步骤S300:In one embodiment, as shown in FIG. 2, a request processing method is provided, and the method is applied to the server in FIG. 1 as an example for description. The method includes steps S100, S200 and S300:

步骤S100,服务器接收客户端发送的服务请求。Step S100, the server receives the service request sent by the client.

客户端需要获取某一服务时,客户端则发送服务请求,服务器接收客户端发送的服务请求。本申请实施例中,客户端发送的服务请求携带有目标URI。在一种可能的实施方式中,客户端需要的服务可以是访问某一网页,则该目标URI可以是客户端需要访问的网页的URI。When the client needs to obtain a service, the client sends a service request, and the server receives the service request sent by the client. In this embodiment of the present application, the service request sent by the client carries the target URI. In a possible implementation manner, the service required by the client may be to access a certain web page, and the target URI may be the URI of the web page that the client needs to access.

步骤S200,服务器基于目标URI查询配置文件,得到能够响应服务请求的多个目标服务的对外通信地址。Step S200, the server queries the configuration file based on the target URI, and obtains the external communication addresses of multiple target services that can respond to the service request.

本申请实施例中,配置文件包括URI与部署于Kubernetes的容器或者物理机的服务的对外通信地址的对应关系。服务器基于目标URI查询配置文件,可以是在配置文件中查找与该目标URI对应的多个目标服务的对外通信地址,由此得到能够响应该服务请求的多个目标服务的对外通信地址,其中,各目标服务部署于容器或者物理机中。In the embodiment of the present application, the configuration file includes the correspondence between the URI and the external communication address of the service of the container or physical machine deployed in Kubernetes. The server queries the configuration file based on the target URI, and may search the configuration file for the external communication addresses of multiple target services corresponding to the target URI, thereby obtaining the external communication addresses of multiple target services that can respond to the service request, wherein, Each target service is deployed in a container or a physical machine.

本申请实施例中,配置文件可以是服务器通过服务器中部署的Ingresscontroller创建的。配置文件可以包括多个URI,每个URI在配置文件中可以对应多个服务的对外通信地址,每个URI对应的多个服务均可以响应携带对应URI的服务请求,每个URI在配置文件中对应的各服务可以部署在容器或者部署在物理机中。In this embodiment of the present application, the configuration file may be created by the server through the Ingresscontroller deployed in the server. The configuration file can include multiple URIs, each URI in the configuration file can correspond to the external communication addresses of multiple services, and multiple services corresponding to each URI can respond to service requests that carry the corresponding URI, and each URI is in the configuration file. The corresponding services can be deployed in containers or in physical machines.

作为一种实施方式,配置文件中的URI由域名部分和路径部分组成,例如,域名部分“foo.bar.com”和路径部分“/foo”组成的URI为“http://foo.bar.com/foo”,其中“http://”为协议标识。在一种可能的实施方式中,例如该URI在配置文件中对应有10个服务的对外通信地址,这10个服务中,其中6个服务部署在容器中,另外4个服务部署在物理机中,这10个服务中每个服务均可以提供客户端访问该URI“http://foo.bar.com/foo”对应的网页。若客户端发送的服务请求携带的目标URI也为“http://foo.bar.com/foo”,服务器则在配置文件中查找出与该目标URI“http://foo.bar.com/foo”对应的10个目标服务(即上述的10个服务)的对外通信地址,这10个目标服务中有6个目标服务部署在容器中,另外4个目标服务部署在物理机中。As an implementation manner, the URI in the configuration file is composed of a domain name part and a path part, for example, the URI composed of the domain name part "foo.bar.com" and the path part "/foo" is "http://foo.bar. com/foo", where "http://" is the protocol identifier. In a possible implementation, for example, the URI corresponds to the external communication addresses of 10 services in the configuration file. Among the 10 services, 6 services are deployed in the container, and the other 4 services are deployed in the physical machine. , each of the 10 services can provide clients to access the web page corresponding to the URI "http://foo.bar.com/foo". If the target URI carried in the service request sent by the client is also "http://foo.bar.com/foo", the server searches the configuration file for the target URI "http://foo.bar.com/ foo" corresponds to the external communication addresses of the 10 target services (that is, the above-mentioned 10 services). Among these 10 target services, 6 target services are deployed in containers, and the other 4 target services are deployed in physical machines.

在一种可能的实施方式中,目标服务的对外通信地址可以包括IP地址和端口号。若目标服务是部署在物理机中的,则该IP地址为部署该目标服务的物理机的IP地址;若目标服务是部署在容器内的,则该IP地址为部署该容器的Pod的IP地址。In a possible implementation, the external communication address of the target service may include an IP address and a port number. If the target service is deployed in a physical machine, the IP address is the IP address of the physical machine where the target service is deployed; if the target service is deployed in a container, the IP address is the IP address of the Pod where the container is deployed .

步骤S300,服务器基于预设的负载均衡策略,从多个目标服务中确定标的服务,基于标的服务的对外通信地址将服务请求定向至标的服务。Step S300, the server determines a target service from multiple target services based on a preset load balancing policy, and directs the service request to the target service based on the external communication address of the target service.

服务器从配置文件中查找出与该目标URI对应的多个目标服务的对外通信地址后,按照预设的负载均衡策略,从多个目标服务中确定标的服务,该标的服务用于响应该服务请求。After finding the external communication addresses of multiple target services corresponding to the target URI from the configuration file, the server determines the target service from the multiple target services according to the preset load balancing strategy, and the target service is used to respond to the service request. .

在一种可能的实施方式中,本申请实施例服务器中部署有Nginx,Nginx在Kubernetes中主要负责向外暴露服务,同时提供负载均衡等功能,服务器基于Nginx对后端部署的服务提供反向代理。In a possible implementation, Nginx is deployed in the server of the embodiment of the present application, and Nginx is mainly responsible for exposing services to the outside in Kubernetes, while providing functions such as load balancing, and the server provides a reverse proxy for the services deployed on the backend based on Nginx .

本申请实施例中,配置文件为Nginx的配置文件,Nginx的配置文件中配置有URI与部署于容器或者物理机的服务的对外通信地址的对应关系;当客户端需要访问Kubernetes中部署的服务时,客户端只需要发送服务请求至服务器,服务器运行Nginx来选择部署于容器或者物理机的标的服务对该服务请求作出响应,由此,实现了Nginx的反向代理功能。In the embodiment of the present application, the configuration file is the configuration file of Nginx, and the configuration file of Nginx is configured with the corresponding relationship between URI and the external communication address of the service deployed in the container or physical machine; when the client needs to access the service deployed in Kubernetes , the client only needs to send a service request to the server, and the server runs Nginx to select the target service deployed in the container or physical machine to respond to the service request, thus realizing the reverse proxy function of Nginx.

服务器运行Nginx,选择部署于容器或者物理机的标的服务对该服务请求作出响应时,需要基于预设的负载均衡策略,从多个目标服务中确定标的服务。本申请实施例中,预设的负载均衡策略可以是预先配置在Nginx中的,该负载均衡策略可以是轮询策略、随机策略或者最小连接策略。其中,轮询策略是将接收到的服务请求轮流分配至该服务请求对应的多个目标服务中;随机策略是将接收到的服务请求随机分配至该服务请求对应的多个目标服务中的任意一个中;最小连接策略是将接收到的服务请求分配给该服务请求对应的多个目标服务中,当前具有最小连接数的目标服务中。以预设的负载均衡策略是最小连接策略为例,服务器运行Nginx,从多个目标服务中确定当前具有最小连接数的目标服务作为标的服务,并将该服务请求转发至该标的服务的对外通信地址中,由该标的服务响应该服务请求,由此,实现了Nginx的负载均衡功能。When the server runs Nginx and selects the target service deployed in the container or physical machine to respond to the service request, it needs to determine the target service from multiple target services based on the preset load balancing strategy. In this embodiment of the present application, the preset load balancing strategy may be pre-configured in Nginx, and the load balancing strategy may be a round-robin strategy, a random strategy, or a minimum connection strategy. Among them, the polling strategy is to assign the received service request to multiple target services corresponding to the service request in turn; the random strategy is to randomly assign the received service request to any of the multiple target services corresponding to the service request. One; the minimum connection strategy is to allocate the received service request to the multiple target services corresponding to the service request, and the target service that currently has the smallest number of connections. Taking the preset load balancing strategy as the minimum connection strategy as an example, the server runs Nginx, determines the target service with the minimum number of connections from multiple target services as the target service, and forwards the service request to the external communication of the target service In the address, the target service responds to the service request, thereby realizing the load balancing function of Nginx.

由此,若多个目标服务中某一个部署在物理机中的目标服务满足该预设的负载均衡策略,服务器则确定该目标服务为标的服务。Therefore, if one of the multiple target services deployed in the physical machine satisfies the preset load balancing policy, the server determines that the target service is the target service.

上述请求处理方法,服务器通过接收客户端发送的服务请求,其中,服务请求携带有目标URI;而后,基于该目标URI查询配置文件,查询后得到能够响应该服务请求的多个目标服务的对外通信地址,其中,各目标服务部署于容器或者物理机中,配置文件包括URI与部署于容器或者物理机的服务的对外通信地址的对应关系;再基于预设的负载均衡策略,从该多个目标服务中确定标的服务,基于该标的服务的对外通信地址将服务请求定向至该标的服务。这样,由于配置文件包括URI与部署于容器或者物理机的服务的对外通信地址的对应关系,因此,服务器可以发现配置文件中包括的部署在物理机中的服务,进而能够将服务请求定向至部署在物理机中的标的服务,实现了基于Kubernetes让部署在物理机中的服务能够响应客户端的服务请求,可以更好地满足客户需求。In the above request processing method, the server receives the service request sent by the client, wherein the service request carries the target URI; then, based on the target URI, the configuration file is queried, and after the query, the external communication of multiple target services that can respond to the service request is obtained. address, where each target service is deployed in a container or a physical machine, and the configuration file includes the correspondence between the URI and the external communication address of the service deployed in the container or physical machine; and then based on the preset load balancing strategy, from the multiple targets The target service is determined in the service, and the service request is directed to the target service based on the external communication address of the target service. In this way, since the configuration file includes the correspondence between the URI and the external communication address of the service deployed on the container or the physical machine, the server can discover the service included in the configuration file and deployed in the physical machine, and can then direct the service request to the deployment. The target service in the physical machine realizes that based on Kubernetes, the service deployed in the physical machine can respond to the service request of the client, which can better meet the customer's needs.

可以理解的是,本申请实施例中,由于服务器可以发现配置文件中包括的部署在物理机中的服务,在容器不稳定的情况下,通过将服务请求定向至部署在物理机中的标的服务,可以避免由于容器不稳定造成的服务崩溃。因此,本申请实施例还可以提升服务可靠性,降低服务崩溃的风险。It can be understood that, in this embodiment of the present application, since the server can discover the service included in the configuration file and deployed in the physical machine, when the container is unstable, the service request can be directed to the target service deployed in the physical machine by directing the service request. , which can avoid service crashes due to container instability. Therefore, the embodiments of the present application can also improve service reliability and reduce the risk of service crash.

在一个实施例中,基于上述图2所示的实施例,本实施例涉及的是服务器如何创建配置文件的过程。如图3-1所示,本实施例中,步骤S200之前还包括步骤S400、步骤S500和步骤S600:In one embodiment, based on the above-mentioned embodiment shown in FIG. 2 , this embodiment relates to a process of how a server creates a configuration file. As shown in Figure 3-1, in this embodiment, step S200 further includes step S400, step S500 and step S600 before step S200:

步骤S400,服务器获取至少一个Ingress资源。Step S400, the server acquires at least one Ingress resource.

本申请实施例中,服务器以Nginx作为负载均衡器实现数据面,服务器通过运行Ingress controller程序实现控制面。服务器运行Ingress controller,则可以获取Kubernetes中创建的Ingress资源来生成Nginx的配置文件。In the embodiment of the present application, the server uses Nginx as a load balancer to implement the data plane, and the server implements the control plane by running the Ingress controller program. If the server runs the Ingress controller, you can obtain the Ingress resource created in Kubernetes to generate the Nginx configuration file.

参见图3-2,其为一种示例性的基于Kubernetes的服务架构示意图。如图3-2所示,Kubernetes整个架构分为主节点(又称master节点)和子节点(又称node节点),主节点提供Kubernetes的集群控制,Pod部署在子节点中,一个Pod中可以部署多个容器。需要说明的是,图3-2中示出的结构,并不对本申请实施例在实际实施时,可以设置的子节点的数量、子节点中Pod的数量、物理机的数量以及部署在物理机中服务的数量构成限制。Refer to Figure 3-2, which is a schematic diagram of an exemplary Kubernetes-based service architecture. As shown in Figure 3-2, the entire architecture of Kubernetes is divided into master nodes (also known as master nodes) and child nodes (also known as node nodes). The master node provides cluster control of Kubernetes, and Pods are deployed in child nodes, which can be deployed in one Pod. multiple containers. It should be noted that the structure shown in FIG. 3-2 does not affect the number of sub-nodes that can be set, the number of Pods in sub-nodes, the number of physical machines, and the number of The number of services in the service constitutes a limit.

请继续参见图3-2,服务器运行Ingress controller,通过Ingress controller与Kubernetes的主节点中的API-Server(API服务器)交互,在Ingress资源发生变化后,从APIServer获取至少一个Ingress资源,各Ingress资源包括URI和Service资源名,并根据该Ingress资源生成Nginx的配置文件。Please continue to refer to Figure 3-2. The server runs the Ingress controller and interacts with the API-Server (API server) in the main node of Kubernetes through the Ingress controller. After the Ingress resource changes, it obtains at least one Ingress resource from the APIServer, and each Ingress resource Include URI and Service resource name, and generate Nginx configuration file based on the Ingress resource.

步骤S500,对于各Ingress资源,服务器基于Ingress资源包括的Service资源名查找目标Service资源,基于目标Service资源中的指示信息,获取与目标Service资源相关联的部署于物理机或者容器的服务的对外通信地址,并建立Ingress资源包括的URI和与目标Service资源相关联的服务的对外通信地址的对应关系。Step S500, for each Ingress resource, the server searches for the target Service resource based on the Service resource name included in the Ingress resource, and obtains the external communication of the service deployed on the physical machine or container associated with the target Service resource based on the indication information in the target Service resource. address, and establish a corresponding relationship between the URI included in the Ingress resource and the external communication address of the service associated with the target Service resource.

在一种可能的实施方式中,服务器通过Ingress controller从API-Server获取Ingress资源时,一并获取Service资源以及部署于物理机或者容器的服务的对外通信地址,并将获取的数据存入Ingress controller的缓存。In a possible implementation, when the server obtains the Ingress resource from the API-Server through the Ingress controller, it also obtains the Service resource and the external communication address of the service deployed on the physical machine or container, and stores the obtained data in the Ingress controller cache.

本申请实施例中,每个Ingress资源包括URI和Service资源名,作为一种实施方式,Ingress资源可以包括host字段和path字段,host字段包括的为域名部分,path字段包括的为路径部分,域名部分和路径部分则组成了该Ingress资源对应的URI。例如,一个Ingress资源包括的host字段为“host:foo.bar.com”,path字段为“path:/foo”,则该Ingress资源对应的URI为“http://foo.bar.com/foo”。In the embodiment of this application, each Ingress resource includes a URI and a Service resource name. As an implementation manner, the Ingress resource may include a host field and a path field. The host field includes the domain name part, the path field includes the path part, and the domain name The part and the path part form the URI corresponding to the Ingress resource. For example, if the host field of an Ingress resource is "host:foo.bar.com" and the path field is "path:/foo", the corresponding URI of the Ingress resource is "http://foo.bar.com/foo" ".

对于一个Ingress资源,服务器在缓存中查找该Ingress资源包括的Service资源名对应的目标Service资源,该目标Service资源的资源名与该Ingress资源包括的Service资源名一致。For an Ingress resource, the server searches the cache for the target Service resource corresponding to the Service resource name included in the Ingress resource, and the resource name of the target Service resource is consistent with the Service resource name included in the Ingress resource.

本申请实施例中,目标Service资源包括指示信息,服务器从缓存中查找该指示信息对应的部署于物理机或者容器的服务的对外通信地址,得到与目标Service资源相关联的部署于物理机或者容器的服务的对外通信地址。In the embodiment of this application, the target Service resource includes indication information, and the server searches the cache for the external communication address of the service deployed on the physical machine or container corresponding to the indication information, and obtains the target Service resource associated with the target Service resource deployed on the physical machine or container. The external communication address of the service.

在一种可能的实施方式中,该指示信息包括自定义资源名。步骤S500中,服务器基于目标Service资源中的指示信息,获取与目标Service资源相关联的部署于物理机或者容器的服务的对外通信地址的过程,可以通过执行下述步骤A1和步骤A2实现:In a possible implementation manner, the indication information includes a custom resource name. In step S500, the server obtains, based on the indication information in the target Service resource, the process of obtaining the external communication address of the service deployed on the physical machine or the container associated with the target Service resource, which can be realized by executing the following steps A1 and A2:

步骤A1,服务器基于自定义资源名查找目标自定义资源。Step A1, the server searches for the target custom resource based on the custom resource name.

服务器从缓存中查找资源名称为该自定义资源名的目标自定义资源。该目标自定义资源包括第一对外通信地址,该第一对外通信地址为与目标Service资源相关联的部署于物理机中的服务的对外通信地址。The server searches the cache for the target custom resource whose resource name is the custom resource name. The target custom resource includes a first external communication address, where the first external communication address is an external communication address of a service deployed in a physical machine associated with the target Service resource.

步骤A2,服务器从目标自定义资源中获取第一对外通信地址。Step A2, the server obtains the first external communication address from the target custom resource.

在一种可能的实施方式中,目标Service资源包括annotations注解字段,该注解字段包括自定义资源名。In a possible implementation, the target Service resource includes an annotations field, and the annotation field includes a custom resource name.

例如,目标自定义资源的自定义资源名为phyendpoint-sample,目标Service资源的注解字段可以采用如下方式表示:For example, the custom resource name of the target custom resource is phyendpoint-sample, and the annotation field of the target Service resource can be expressed as follows:

“annotations:"annotations:

aquaman.yy.com/physical.deployment.endpoints:phyendpoint-sample”aquaman.yy.com/physical.deployment.endpoints:phyendpoint-sample”

由此,利用目标Service资源的注解字段将目标Service资源与目标自定义资源关联。服务器基于目标Service资源中的注解字段包括的自定义资源名,可以在缓存中查找到目标自定义资源,避免了传统技术中Service资源仅包括用于发现Pod的字段,如果服务部署在物理机中,基于传统技术中的Service资源则无法发现部署于物理机中的服务的问题。Thus, the target Service resource is associated with the target custom resource by using the annotation field of the target Service resource. Based on the custom resource name included in the annotation field in the target Service resource, the server can find the target custom resource in the cache, avoiding that the Service resource in the traditional technology only includes the field for discovering Pods. If the service is deployed in a physical machine , based on the Service resource in the traditional technology, the problem of the service deployed in the physical machine cannot be found.

本申请实施例中,目标自定义资源定义了部署于物理机中的服务,在一种可能的实施方式中,目标自定义资源包括spec字段,spec字段包括第一对外通信地址。In the embodiment of the present application, the target custom resource defines a service deployed in a physical machine. In a possible implementation, the target custom resource includes a spec field, and the spec field includes a first external communication address.

本申请实施例中,目标自定义资源是利用Kubernetes的自定义资源功能实现的。以目标自定义资源定义部署在物理机10.21.2.49与10.21.2.48上且端口为8084的服务为例,则目标自定义资源的spec字段中可以包括:In the embodiment of the present application, the target custom resource is implemented by using the custom resource function of Kubernetes. Taking the service where the target custom resource definition is deployed on physical machines 10.21.2.49 and 10.21.2.48 and whose port is 8084 as an example, the spec field of the target custom resource can include:

“endpoints:10.21.2.49:8084,10.21.2.48:8084”"endpoints: 10.21.2.49:8084, 10.21.2.48:8084"

该endpoints则表示部署在物理机10.21.2.49上的服务的第一对外通信地址为10.21.2.49:8084、部署在物理机10.21.2.48上的服务的第一对外通信地址为10.21.2.48:8084。The endpoints indicate that the first external communication address of the service deployed on the physical machine 10.21.2.49 is 10.21.2.49:8084, and the first external communication address of the service deployed on the physical machine 10.21.2.48 is 10.21.2.48:8084.

作为一种实施方式,目标自定义资源还可以包括apiVersion字段、kind字段、metadata字段以及健康检查字段中的至少一个,其中,apiVersion字段包括目标自定义资源的版本信息,kind字段包括目标自定义资源的类型信息,metadata字段包括目标自定义资源的名称以及目标自定义资源的命名空间信息,健康检查字段包括健康检查地址,健康检查地址用于供服务器对与目标Service资源相关联的部署于物理机中的服务进行健康检查。As an embodiment, the target custom resource may further include at least one of an apiVersion field, a kind field, a metadata field, and a health check field, where the apiVersion field includes version information of the target custom resource, and the kind field includes the target custom resource The type information of the target custom resource, the metadata field includes the name of the target custom resource and the namespace information of the target custom resource, the health check field includes the health check address, and the health check address is used by the server to deploy the target service resource associated with the target service resource on the physical machine. The services in the health check.

例如,apiVersion:thor.aquaman.io/v1beta1,可以表示目标自定义资源的版本为thor.aquaman.io/v1beta1;kind:PhyEndpoint,可以表示目标自定义资源的类型为PhyEndpoint;name:phyendpoint-sample,可以表示目标自定义资源的名称为phyendpoint-sample;namespace:test,可以表示目标自定义资源的命名空间为test;健康检查字段http_check_path:/conf/以及Interval:10中,/conf/可以表示健康检查地址,Interval:10可以表示健康检查的时间周期,等等。For example, apiVersion: thor.aquaman.io/v1beta1 can indicate that the version of the target custom resource is thor.aquaman.io/v1beta1; kind:PhyEndpoint can indicate that the type of the target custom resource is PhyEndpoint; name:phyendpoint-sample, The name that can represent the target custom resource is phyendpoint-sample; namespace:test can represent the namespace of the target custom resource is test; in the health check field http_check_path:/conf/ and Interval:10, /conf/ can represent the health check Address, Interval: 10 can represent the time period of the health check, etc.

由此,通过将部署在物理机中的服务以目标自定义资源的方式定义,并利用目标Service资源的注解字段将目标Service资源与目标自定义资源关联,服务器基于目标Service资源则可以发现部署于物理机中的服务,并可以获取目标自定义资源包括的与目标Service资源相关联的部署于物理机中的服务的对外通信地址,即第一通信地址。Therefore, by defining the service deployed in the physical machine as a target custom resource, and using the annotation field of the target Service resource to associate the target Service resource with the target custom resource, the server can discover the deployment in the target Service resource based on the target Service resource. The service in the physical machine can obtain the external communication address, that is, the first communication address, of the service deployed in the physical machine that is included in the target custom resource and is associated with the target Service resource.

服务器从目标自定义资源中获取第一对外通信地址后,建立Ingress资源包括的URI和与目标Service资源相关联的服务的对外通信地址的对应关系,也即,将Ingress资源包括的URI与第一对外通信地址进行关联。After obtaining the first external communication address from the target custom resource, the server establishes a correspondence between the URI included in the Ingress resource and the external communication address of the service associated with the target Service resource, that is, the URI included in the Ingress resource is associated with the first external communication address. Associate external communication addresses.

在另一种可能的实施方式中,指示信息包括Pod资源标签以及第二对外通信地址的第一部分,第二对外通信地址为与目标Service资源相关联的部署于容器中的服务的对外通信地址。上述步骤S500中,服务器基于目标Service资源中的指示信息,获取与目标Service资源相关联的部署于物理机或者容器的服务的对外通信地址的过程,可以通过执行下述步骤B1和步骤B2实现:In another possible implementation, the indication information includes the Pod resource label and the first part of the second external communication address, where the second external communication address is the external communication address of the service deployed in the container associated with the target Service resource. In the above step S500, the server obtains, based on the indication information in the target Service resource, the process of obtaining the external communication address of the service deployed on the physical machine or the container associated with the target Service resource, which can be implemented by executing the following steps B1 and B2:

步骤B1,服务器基于Pod资源标签查找目标Pod资源,其中,目标Pod资源包括第二对外通信地址的第二部分。Step B1, the server searches for the target Pod resource based on the Pod resource label, where the target Pod resource includes the second part of the second external communication address.

服务器基于Pod资源标签在缓存中查找具有该Pod资源标签的目标Pod资源,该目标Pod资源包括第二对外通信地址的第二部分。The server searches the cache for a target Pod resource with the Pod resource label based on the Pod resource label, where the target Pod resource includes the second part of the second external communication address.

在一种可能的实施方式中,目标Service资源的“labels”部分包括的内容即为Pod资源标签,目标Service资源的“port”部分即为第二对外通信地址的第一部分,该第二对外通信地址为与目标Service资源相关联的部署于容器中的服务的对外通信地址。In a possible implementation, the content included in the "labels" part of the target Service resource is the Pod resource label, and the "port" part of the target Service resource is the first part of the second external communication address, which is the second external communication address. The address is the external communication address of the service deployed in the container associated with the target Service resource.

本申请实施例通中,通过在目标Service资源的注解字段中添加部署于物理机中的服务的第一对外通信地址,同时,目标Service资源原有的功能可以关联到Pod资源标签对应的部署于容器中的服务。由此,本申请实施例通过改造传统Service资源中服务的发现逻辑,改造后的目标Service资源除了可以识别出Pod,即识别出部署在容器中的服务,同时还能发现物理机上部署的服务。In the embodiment of the present application, by adding the first external communication address of the service deployed in the physical machine in the annotation field of the target Service resource, at the same time, the original function of the target Service resource can be associated with the corresponding Pod resource label deployed in the Services in containers. Therefore, in the embodiment of the present application, by modifying the service discovery logic in the traditional Service resource, the modified target Service resource can not only identify the Pod, that is, identify the service deployed in the container, but also discover the service deployed on the physical machine.

步骤B2,服务器从目标Pod资源中获取第二部分,并基于第一部分和第二部分生成第二对外通信地址。Step B2, the server obtains the second part from the target Pod resource, and generates a second external communication address based on the first part and the second part.

在一个可能的实施方式中,第二对外通信地址包括IP地址和端口号,第一部分为端口号,第二部分为IP地址。服务器将获取的第一部分和第二部分以IP地址:端口号的形式组合,得到第二对外通信地址,该第二对外通信地址为与目标Service资源相关联的部署于容器中的服务的对外通信地址。In a possible implementation manner, the second external communication address includes an IP address and a port number, the first part is the port number, and the second part is the IP address. The server combines the acquired first part and the second part in the form of IP address: port number to obtain a second external communication address, where the second external communication address is the external communication of the service deployed in the container associated with the target Service resource address.

服务器生成第二对外通信地址后,通过运行Ingress controller建立Ingress资源包括的URI和与目标Service资源相关联的服务的对外通信地址的对应关系,也即,将Ingress资源包括的URI与第二对外通信地址进行关联。After the server generates the second external communication address, it runs the Ingress controller to establish a correspondence between the URI included in the Ingress resource and the external communication address of the service associated with the target Service resource, that is, the URI included in the Ingress resource and the second external communication address to associate.

步骤S600,服务器基于各对应关系,创建配置文件。Step S600, the server creates a configuration file based on each corresponding relationship.

服务器基于URI与部署于物理机的服务的对外通信地址的对应关系以及URI与部署于容器的服务的对外通信地址的对应关系,创建Nginx的配置文件,创建的配置文件中包括URI与部署于容器以及物理机的服务的对外通信地址的对应关系,部署于容器以及物理机的服务均可以提供针对该URI的服务。The server creates an Nginx configuration file based on the correspondence between the URI and the external communication address of the service deployed on the physical machine and the correspondence between the URI and the external communication address of the service deployed in the container. The created configuration file includes the URI and the external communication address of the service deployed in the container. As well as the correspondence between the external communication addresses of the services of the physical machine, the services deployed in the container and the physical machine can provide services for the URI.

服务器将创建的配置文件刷新至Nginx中,这样,服务器接收到客户端发送的服务请求后(服务请求如图3-2所示的服务请求1、服务请求2或者服务请求3),则可以通过Nginx在刷新后的配置文件中查询服务请求携带的目标URI对应的多个目标服务的对外通信地址,各目标服务部署于容器或者物理机中,各目标服务均可以用于响应该服务请求;服务器运行Nginx,基于预设的负载均衡策略,从多个目标服务中确定标的服务,基于标的服务的对外通信地址将该服务请求定向至该标的服务,由该标的服务响应该服务请求。The server refreshes the created configuration file to Nginx, so that after the server receives the service request sent by the client (service request 1, service request 2 or service request 3 shown in Figure 3-2), it can pass Nginx queries the external communication addresses of multiple target services corresponding to the target URI carried in the service request in the refreshed configuration file. Each target service is deployed in a container or physical machine, and each target service can be used to respond to the service request; the server Run Nginx, determine the target service from multiple target services based on the preset load balancing strategy, direct the service request to the target service based on the external communication address of the target service, and the target service responds to the service request.

在实际的应用中,对于需要服务同时部署在容器和物理机的应用场景,本申请实施例通过上述实施方式,将部署在容器中的服务和部署在物理机中的服务一起暴露给外部访问,可以更好地满足客户需求;同时,由于服务部署在容器以及物理机中,可以避免由于容器不稳定造成的服务崩溃,可以提升服务的稳定性,但是传统技术只能发现部署在容器中的服务,而不能发现部署在物理机中的服务,本申请实施例通过上述实施方式能够发现部署在物理机中的服务,相较于传统技术,本申请实施例还有利于提升服务的稳定性。In practical applications, for an application scenario that requires services to be deployed in containers and physical machines at the same time, the embodiment of the present application exposes services deployed in containers and services deployed in physical machines to external access through the foregoing implementation manner, It can better meet customer needs; at the same time, because services are deployed in containers and physical machines, service crashes caused by unstable containers can be avoided, and service stability can be improved, but traditional technologies can only discover services deployed in containers , instead of discovering the service deployed in the physical machine, the embodiment of the present application can discover the service deployed in the physical machine through the above implementation manner, and compared with the traditional technology, the embodiment of the present application is also conducive to improving the stability of the service.

在上述图3-1所示实施例的基础上,参见图4,本实施例涉及的是服务器如何根据健康检查字段进行健康检查的过程。如图4所示,本实施例中,目标自定义资源包括健康检查字段,服务器根据健康检查字段进行健康检查的过程可以包括如下步骤:On the basis of the embodiment shown in FIG. 3-1 above, referring to FIG. 4 , this embodiment relates to the process of how the server performs health check according to the health check field. As shown in FIG. 4 , in this embodiment, the target custom resource includes a health check field, and the process of the server performing a health check according to the health check field may include the following steps:

步骤S710,基于健康检查地址和第一对外通信地址,生成目标地址。Step S710: Generate a target address based on the health check address and the first external communication address.

本申请实施例中,对于配置文件中每个部署在物理机上的服务,服务器基于健康检查地址和每个部署在物理机上的服务的第一对外通信地址,生成每个部署在物理机上的服务的目标地址。In this embodiment of the present application, for each service deployed on a physical machine in the configuration file, the server generates a target address.

在一种可能的实施方式中,部署在物理机上的一个服务的第一对外通信地址为10.21.2.49:8084,部署在物理机上的另一个服务的第一对外通信地址为10.21.2.48:8084,服务器基于健康检查地址/conf/,生成这两个服务的目标地址:10.21.2.49:8084/conf/和10.21.2.48:8084/conf/。In a possible implementation manner, the first external communication address of a service deployed on the physical machine is 10.21.2.49:8084, and the first external communication address of another service deployed on the physical machine is 10.21.2.48:8084, Based on the health check address /conf/, the server generates the target addresses of these two services: 10.21.2.49:8084/conf/ and 10.21.2.48:8084/conf/.

步骤S720,向目标地址发送健康检查指令,得到返回结果。Step S720, sending a health check instruction to the target address, and obtaining a return result.

服务器向生成的每个目标地址发送健康检查指令,得到每个目标地址返回的返回结果,该返回结果用于表征第一对外通信地址对应的部署于物理机中的服务存活或者不存活。The server sends a health check instruction to each generated target address, and obtains a return result returned by each target address, where the returned result is used to indicate whether the service deployed in the physical machine corresponding to the first external communication address is alive or not.

在一种可能的实施方式中,返回结果可以是HTTP码的形式,例如,若一个目标地址的返回结果是“200”,则表征该目标地址对应的部署在物理机中的服务存活;而若一个目标地址的返回结果是“405”,则表征该目标地址对应的部署在物理机中的服务不存活。In a possible implementation, the returned result may be in the form of an HTTP code. For example, if the returned result of a target address is "200", it indicates that the service deployed in the physical machine corresponding to the target address is alive; The returned result of a target address is "405", which indicates that the service deployed in the physical machine corresponding to the target address does not survive.

步骤S730,若根据返回结果确定第一对外通信地址对应的部署于物理机中的服务不存活,则将配置文件中的第一对外通信地址删除。Step S730, if it is determined according to the returned result that the service deployed in the physical machine corresponding to the first external communication address does not survive, delete the first external communication address in the configuration file.

服务器若根据返回结果确定第一对外通信地址对应的部署于物理机中的服务不存活,则将配置文件中的第一对外通信地址删除。在一种可能的实施方式中,服务器可以按照目标自定义资源包括的Interval字段的指示,周期性地进行健康检查,例如,上述目标自定义资源的举例中Interval:10,由此,服务器则可以每10秒进行一次健康检查,从而可以及时将不存活的服务从配置文件中删除,确保了配置文件中的服务能够正常提供服务,提升了服务的可靠性。If the server determines according to the returned result that the service deployed in the physical machine corresponding to the first external communication address does not survive, the server deletes the first external communication address in the configuration file. In a possible implementation manner, the server may periodically perform a health check according to the indication of the Interval field included in the target custom resource. For example, Interval: 10 in the above example of the target custom resource. A health check is performed every 10 seconds, so that non-survivable services can be deleted from the configuration file in time, which ensures that the services in the configuration file can provide services normally and improves the reliability of services.

参见图5,其示出了本申请实施例提供的一种请求处理方法的流程图,该方法可以应用于图1所示实施环境中。如图5所示,该方法可以包括以下步骤:Referring to FIG. 5 , it shows a flowchart of a request processing method provided by an embodiment of the present application, and the method can be applied to the implementation environment shown in FIG. 1 . As shown in Figure 5, the method may include the following steps:

步骤S1001,服务器获取至少一个Ingress资源。Step S1001, the server acquires at least one Ingress resource.

步骤S1002,对于各Ingress资源,服务器基于Ingress资源包括的Service资源名查找目标Service资源,基于目标Service资源中的指示信息,获取与目标Service资源相关联的部署于物理机或者容器的服务的对外通信地址,并建立Ingress资源包括的URI和与目标Service资源相关联的服务的对外通信地址的对应关系。Step S1002, for each Ingress resource, the server searches for the target Service resource based on the Service resource name included in the Ingress resource, and based on the indication information in the target Service resource, obtains the external communication of the service deployed on the physical machine or the container associated with the target Service resource address, and establish a corresponding relationship between the URI included in the Ingress resource and the external communication address of the service associated with the target Service resource.

在一种可能的实施方式中,指示信息包括自定义资源名,服务器基于目标Service资源中的指示信息,获取与目标Service资源相关联的部署于物理机或者容器的服务的对外通信地址可以通过以下步骤实现:服务器基于自定义资源名查找目标自定义资源,目标自定义资源包括第一对外通信地址,第一对外通信地址为与目标Service资源相关联的部署于物理机中的服务的对外通信地址;服务器从目标自定义资源中获取第一对外通信地址。In a possible implementation, the indication information includes a user-defined resource name, and the server, based on the indication information in the target Service resource, obtains the external communication address of the service deployed on the physical machine or container associated with the target Service resource through the following Steps to achieve: the server searches for the target custom resource based on the custom resource name, the target custom resource includes a first external communication address, and the first external communication address is the external communication address of the service deployed in the physical machine associated with the target Service resource ; The server obtains the first external communication address from the target custom resource.

其中,目标Service资源包括注解字段,注解字段包括自定义资源名。目标自定义资源包括spec字段,spec字段包括第一对外通信地址;目标自定义资源还包括apiVersion字段、kind字段、metadata字段以及健康检查字段中的至少一个,其中,apiVersion字段包括目标自定义资源的版本信息,kind字段包括目标自定义资源的类型信息,metadata字段包括目标自定义资源的名称以及目标自定义资源的命名空间信息,健康检查字段包括健康检查地址,健康检查地址用于供服务器对与目标Service资源相关联的部署于物理机中的服务进行健康检查。The target Service resource includes an annotation field, and the annotation field includes a custom resource name. The target custom resource includes a spec field, and the spec field includes the first external communication address; the target custom resource also includes at least one of an apiVersion field, a kind field, a metadata field, and a health check field, where the apiVersion field includes the The version information, the kind field includes the type information of the target custom resource, the metadata field includes the name of the target custom resource and the namespace information of the target custom resource, the health check field includes the health check address, and the health check address is used for the server to pair with the target custom resource. The service deployed in the physical machine associated with the target Service resource performs health check.

在一种可能的实施方式中,指示信息包括Pod资源标签以及第二对外通信地址的第一部分,第二对外通信地址为与目标Service资源相关联的部署于容器中的服务的对外通信地址,服务器基于目标Service资源中的指示信息,获取与目标Service资源相关联的部署于物理机或者容器的服务的对外通信地址可以通过如下步骤实现:服务器基于Pod资源标签查找目标Pod资源,目标Pod资源包括第二对外通信地址的第二部分;服务器从目标Pod资源中获取第二部分,并基于第一部分和第二部分生成第二对外通信地址。In a possible implementation, the indication information includes the Pod resource label and the first part of the second external communication address, where the second external communication address is the external communication address of the service deployed in the container associated with the target Service resource, and the server Based on the indication information in the target Service resource, obtaining the external communication address of the service deployed on the physical machine or container associated with the target Service resource can be achieved by the following steps: The server searches for the target Pod resource based on the Pod resource label, and the target Pod resource includes the first The second part of the external communication address; the server obtains the second part from the target Pod resource, and generates the second external communication address based on the first part and the second part.

其中,第二对外通信地址包括IP地址和端口号,第一部分为端口号,第二部分为IP地址。The second external communication address includes an IP address and a port number, the first part is the port number, and the second part is the IP address.

步骤S1003,服务器基于各对应关系,创建配置文件。Step S1003, the server creates a configuration file based on each corresponding relationship.

步骤S1004,客户端发送服务请求,服务请求携带有目标URI。Step S1004, the client sends a service request, and the service request carries the target URI.

步骤S1005,服务器接收客户端发送的该服务请求。Step S1005, the server receives the service request sent by the client.

步骤S1006,服务器基于目标URI查询配置文件,得到能够响应服务请求的多个目标服务的对外通信地址。Step S1006, the server queries the configuration file based on the target URI, and obtains the external communication addresses of multiple target services that can respond to the service request.

其中,各目标服务部署于容器或者物理机中,配置文件包括URI与部署于容器或者物理机的服务的对外通信地址的对应关系。Wherein, each target service is deployed in a container or a physical machine, and the configuration file includes a correspondence between the URI and the external communication address of the service deployed in the container or the physical machine.

步骤S1007,服务器基于预设的负载均衡策略,从多个目标服务中确定标的服务,基于标的服务的对外通信地址将服务请求定向至标的服务。Step S1007, the server determines a target service from multiple target services based on a preset load balancing policy, and directs the service request to the target service based on the external communication address of the target service.

步骤S1008,服务器基于目标自定义资源包括的健康检查字段所包括的健康检查地址和第一对外通信地址,生成目标地址。Step S1008, the server generates the target address based on the health check address and the first external communication address included in the health check field included in the target custom resource.

步骤S1009,向目标地址发送健康检查指令,得到返回结果,返回结果用于表征第一对外通信地址对应的部署于物理机中的服务存活或者不存活。In step S1009, a health check instruction is sent to the target address, and a return result is obtained, and the return result is used to indicate that the service deployed in the physical machine corresponding to the first external communication address is alive or not.

步骤S1010,若根据返回结果确定第一对外通信地址对应的部署于物理机中的服务不存活,则将配置文件中的第一对外通信地址删除。Step S1010, if it is determined according to the returned result that the service deployed in the physical machine corresponding to the first external communication address does not survive, delete the first external communication address in the configuration file.

应该理解的是,虽然图2-5的流程图中的各个步骤按照箭头的指示依次显示,但是这些步骤并不是必然按照箭头指示的顺序依次执行。除非本文中有明确的说明,这些步骤的执行并没有严格的顺序限制,这些步骤可以以其它的顺序执行。而且,图2-5中的至少一部分步骤可以包括多个步骤或者多个阶段,这些步骤或者阶段并不必然是在同一时刻执行完成,而是可以在不同的时刻执行,这些步骤或者阶段的执行顺序也不必然是依次进行,而是可以与其它步骤或者其它步骤中的步骤或者阶段的至少一部分轮流或者交替地执行。It should be understood that although the steps in the flowcharts of FIGS. 2-5 are shown in sequence according to the arrows, these steps are not necessarily executed in the sequence shown by the arrows. Unless explicitly stated herein, the execution of these steps is not strictly limited to the order, and these steps may be performed in other orders. Moreover, at least a part of the steps in FIGS. 2-5 may include multiple steps or multiple stages. These steps or stages are not necessarily executed and completed at the same time, but may be executed at different times. The execution of these steps or stages The order is also not necessarily sequential, but may be performed alternately or alternately with other steps or at least a portion of the steps or phases within the other steps.

在一个实施例中,如图6所示,提供了一种请求处理装置,所述装置包括:In one embodiment, as shown in FIG. 6, a request processing apparatus is provided, and the apparatus includes:

第一控制模块10,用于接收客户端发送的服务请求,所述服务请求携带有目标URI;afirst control module 10, configured to receive a service request sent by a client, where the service request carries a target URI;

第二控制模块20,用于基于所述目标URI查询配置文件,得到能够响应所述服务请求的多个目标服务的对外通信地址,其中,各所述目标服务部署于容器或者物理机中,所述配置文件包括URI与部署于容器或者物理机的服务的对外通信地址的对应关系;Thesecond control module 20 is configured to query the configuration file based on the target URI, and obtain the external communication addresses of multiple target services that can respond to the service request, wherein each of the target services is deployed in a container or a physical machine, and the The configuration file includes the correspondence between the URI and the external communication address of the service deployed in the container or physical machine;

第三控制模块30,用于基于预设的负载均衡策略,从所述多个目标服务中确定标的服务,基于所述标的服务的对外通信地址将所述服务请求定向至所述标的服务。Thethird control module 30 is configured to determine a target service from the plurality of target services based on a preset load balancing policy, and direct the service request to the target service based on the external communication address of the target service.

在图6所示实施例的基础上,参见图7,所述装置还包括:On the basis of the embodiment shown in FIG. 6, referring to FIG. 7, the apparatus further includes:

第四控制模块40,用于获取至少一个Ingress资源,各所述Ingress资源包括URI和Service资源名;Thefourth control module 40 is used to obtain at least one Ingress resource, and each described Ingress resource includes a URI and a Service resource name;

第五控制模块50,用于对于各所述Ingress资源,基于所述Ingress资源包括的Service资源名查找目标Service资源,基于所述目标Service资源中的指示信息,获取与所述目标Service资源相关联的部署于物理机或者容器的服务的对外通信地址,并建立所述Ingress资源包括的URI和与所述目标Service资源相关联的服务的对外通信地址的对应关系;Thefifth control module 50 is configured to, for each of the Ingress resources, search for a target Service resource based on the Service resource name included in the Ingress resource, and obtain information associated with the target Service resource based on the indication information in the target Service resource The external communication address of the service deployed on the physical machine or the container, and establish the correspondence between the URI included in the Ingress resource and the external communication address of the service associated with the target Service resource;

第六控制模块60,用于基于各所述对应关系,创建所述配置文件。Thesixth control module 60 is configured to create the configuration file based on each of the corresponding relationships.

可选地,所述指示信息包括自定义资源名,所述第五控制模块50具体用于:Optionally, the indication information includes a user-defined resource name, and thefifth control module 50 is specifically configured to:

基于所述自定义资源名查找目标自定义资源,所述目标自定义资源包括第一对外通信地址,所述第一对外通信地址为与所述目标Service资源相关联的部署于物理机中的服务的对外通信地址;Find a target custom resource based on the custom resource name, where the target custom resource includes a first external communication address, and the first external communication address is a service deployed in a physical machine associated with the target Service resource 's external correspondence address;

从所述目标自定义资源中获取所述第一对外通信地址。Obtain the first external communication address from the target custom resource.

可选地,所述目标Service资源包括注解字段,所述注解字段包括所述自定义资源名。Optionally, the target Service resource includes an annotation field, and the annotation field includes the user-defined resource name.

可选地,所述目标自定义资源包括spec字段,所述spec字段包括所述第一对外通信地址;Optionally, the target custom resource includes a spec field, and the spec field includes the first external communication address;

所述目标自定义资源还包括apiVersion字段、kind字段、metadata字段以及健康检查字段中的至少一个,其中,所述apiVersion字段包括所述目标自定义资源的版本信息,所述kind字段包括所述目标自定义资源的类型信息,所述metadata字段包括所述目标自定义资源的名称以及所述目标自定义资源的命名空间信息,所述健康检查字段包括健康检查地址,所述健康检查地址用于供所述服务器对与所述目标Service资源相关联的部署于物理机中的服务进行健康检查。The target custom resource also includes at least one of an apiVersion field, a kind field, a metadata field, and a health check field, wherein the apiVersion field includes version information of the target custom resource, and the kind field includes the target Type information of the custom resource, the metadata field includes the name of the target custom resource and the namespace information of the target custom resource, the health check field includes a health check address, and the health check address is used for The server performs a health check on the service deployed in the physical machine associated with the target Service resource.

可选地,在所述目标自定义资源包括所述健康检查字段的情况下,所述装置还包括:Optionally, when the target custom resource includes the health check field, the apparatus further includes:

地址生成模块,用于基于所述健康检查地址和所述第一对外通信地址,生成目标地址;An address generation module, configured to generate a target address based on the health check address and the first external communication address;

健康检查模块,用于向所述目标地址发送健康检查指令,得到返回结果,所述返回结果用于表征所述第一对外通信地址对应的部署于物理机中的服务存活或者不存活;a health check module, configured to send a health check instruction to the target address, and obtain a return result, where the return result is used to indicate that the service deployed in the physical machine corresponding to the first external communication address is alive or not;

结果确认模块,用于若根据所述返回结果确定所述第一对外通信地址对应的部署于物理机中的服务不存活,则将所述配置文件中的所述第一对外通信地址删除。A result confirmation module, configured to delete the first external communication address in the configuration file if it is determined according to the returned result that the service deployed in the physical machine corresponding to the first external communication address does not survive.

可选地,所述指示信息包括Pod资源标签以及第二对外通信地址的第一部分,所述第二对外通信地址为与所述目标Service资源相关联的部署于容器中的服务的对外通信地址,所述第五控制模块50具体用于:Optionally, the indication information includes a Pod resource label and the first part of a second external communication address, and the second external communication address is the external communication address of the service deployed in the container associated with the target Service resource, Thefifth control module 50 is specifically used for:

基于所述Pod资源标签查找目标Pod资源,所述目标Pod资源包括所述第二对外通信地址的第二部分;Find the target Pod resource based on the Pod resource label, and the target Pod resource includes the second part of the second external communication address;

从所述目标Pod资源中获取所述第二部分,并基于所述第一部分和所述第二部分生成所述第二对外通信地址。The second part is obtained from the target Pod resource, and the second external communication address is generated based on the first part and the second part.

可选地,所述第二对外通信地址包括IP地址和端口号,所述第一部分为端口号,所述第二部分为IP地址。Optionally, the second external communication address includes an IP address and a port number, the first part is the port number, and the second part is the IP address.

关于请求处理装置的具体限定可以参见上文中对于请求处理方法的限定,在此不再赘述。上述请求处理装置中的各个模块可全部或部分通过软件、硬件及其组合来实现。上述各模块可以硬件形式内嵌于或独立于服务器中的处理器中,也可以以软件形式存储于服务器中的存储器中,以便于处理器调用执行以上各个模块对应的操作。For the specific limitation of the request processing apparatus, please refer to the limitation on the request processing method above, which will not be repeated here. Each module in the above-mentioned request processing apparatus may be implemented in whole or in part by software, hardware and combinations thereof. The above modules may be embedded in or independent of the processor in the server in the form of hardware, or may be stored in the memory in the server in the form of software, so that the processor can call and execute operations corresponding to the above modules.

在一个实施例中,提供了一种服务器,其内部结构图可以如图8所示。该服务器包括通过系统总线连接的处理器、存储器和网络接口。其中,该服务器的处理器用于提供计算和控制能力。该服务器的存储器包括非易失性存储介质、内存储器。该非易失性存储介质存储有操作系统、计算机程序和数据库。该内存储器为非易失性存储介质中的操作系统和计算机程序的运行提供环境。该服务器的数据库用于存储请求处理数据。该服务器的网络接口用于与外部的终端通过网络连接通信。该计算机程序被处理器执行时以实现一种请求处理方法。In one embodiment, a server is provided, and its internal structure diagram may be as shown in FIG. 8 . The server includes a processor, memory, and a network interface connected through a system bus. Among them, the processor of the server is used to provide computing and control capabilities. The memory of the server includes a non-volatile storage medium and an internal memory. The nonvolatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the execution of the operating system and computer programs in the non-volatile storage medium. The server's database is used to store request processing data. The network interface of the server is used to communicate with external terminals through a network connection. The computer program, when executed by the processor, implements a request processing method.

本领域技术人员可以理解,图8中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的服务器的限定,具体的服务器可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。Those skilled in the art can understand that the structure shown in FIG. 8 is only a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the server to which the solution of the present application is applied. More or fewer components are shown in the figures, either in combination or with different arrangements of components.

在一个实施例中,提供了一种服务器,包括存储器和处理器,存储器中存储有计算机程序,该处理器执行计算机程序时实现以下步骤:In one embodiment, a server is provided, including a memory and a processor, a computer program is stored in the memory, and the processor implements the following steps when executing the computer program:

接收客户端发送的服务请求,所述服务请求携带有目标URI;Receive a service request sent by the client, where the service request carries a target URI;

基于所述目标URI查询配置文件,得到能够响应所述服务请求的多个目标服务的对外通信地址,其中,各所述目标服务部署于容器或者物理机中,所述配置文件包括URI与部署于容器或者物理机的服务的对外通信地址的对应关系;Querying a configuration file based on the target URI to obtain the external communication addresses of multiple target services that can respond to the service request, wherein each target service is deployed in a container or a physical machine, and the configuration file includes a URI and a configuration file deployed in a The correspondence between the external communication addresses of the services of the container or physical machine;

基于预设的负载均衡策略,从所述多个目标服务中确定标的服务,基于所述标的服务的对外通信地址将所述服务请求定向至所述标的服务。Based on a preset load balancing policy, a target service is determined from the plurality of target services, and the service request is directed to the target service based on an external communication address of the target service.

在一个实施例中,处理器执行计算机程序时还实现以下步骤:In one embodiment, the processor further implements the following steps when executing the computer program:

获取至少一个Ingress资源,各所述Ingress资源包括URI和Service资源名;Obtain at least one Ingress resource, each described Ingress resource includes a URI and a Service resource name;

对于各所述Ingress资源,基于所述Ingress资源包括的Service资源名查找目标Service资源,基于所述目标Service资源中的指示信息,获取与所述目标Service资源相关联的部署于物理机或者容器的服务的对外通信地址,并建立所述Ingress资源包括的URI和与所述目标Service资源相关联的服务的对外通信地址的对应关系;For each of the Ingress resources, the target Service resource is searched based on the Service resource name included in the Ingress resource, and based on the indication information in the target Service resource, the information associated with the target Service resource and deployed on the physical machine or container is obtained. the external communication address of the service, and establish a correspondence between the URI included in the Ingress resource and the external communication address of the service associated with the target Service resource;

基于各所述对应关系,创建所述配置文件。Based on each of the corresponding relationships, the configuration file is created.

在一个实施例中,所述指示信息包括自定义资源名,处理器执行计算机程序时具体实现以下步骤:In one embodiment, the indication information includes a user-defined resource name, and the processor specifically implements the following steps when executing the computer program:

基于所述自定义资源名查找目标自定义资源,所述目标自定义资源包括第一对外通信地址,所述第一对外通信地址为与所述目标Service资源相关联的部署于物理机中的服务的对外通信地址;Find a target custom resource based on the custom resource name, where the target custom resource includes a first external communication address, and the first external communication address is a service deployed in a physical machine associated with the target Service resource 's external correspondence address;

从所述目标自定义资源中获取所述第一对外通信地址。Obtain the first external communication address from the target custom resource.

在一个实施例中,所述目标Service资源包括注解字段,所述注解字段包括所述自定义资源名。In one embodiment, the target Service resource includes an annotation field, and the annotation field includes the user-defined resource name.

在一个实施例中,所述目标自定义资源包括spec字段,所述spec字段包括所述第一对外通信地址;In one embodiment, the target custom resource includes a spec field, and the spec field includes the first external communication address;

所述目标自定义资源还包括apiVersion字段、kind字段、metadata字段以及健康检查字段中的至少一个,其中,所述apiVersion字段包括所述目标自定义资源的版本信息,所述kind字段包括所述目标自定义资源的类型信息,所述metadata字段包括所述目标自定义资源的名称以及所述目标自定义资源的命名空间信息,所述健康检查字段包括健康检查地址,所述健康检查地址用于供所述服务器对与所述目标Service资源相关联的部署于物理机中的服务进行健康检查。The target custom resource also includes at least one of an apiVersion field, a kind field, a metadata field, and a health check field, wherein the apiVersion field includes version information of the target custom resource, and the kind field includes the target Type information of the custom resource, the metadata field includes the name of the target custom resource and the namespace information of the target custom resource, the health check field includes a health check address, and the health check address is used for The server performs a health check on the service deployed in the physical machine associated with the target Service resource.

在一个实施例中,在所述目标自定义资源包括所述健康检查字段的情况下,处理器执行计算机程序时还实现以下步骤:In one embodiment, when the target custom resource includes the health check field, the processor further implements the following steps when executing the computer program:

基于所述健康检查地址和所述第一对外通信地址,生成目标地址;generating a target address based on the health check address and the first external communication address;

向所述目标地址发送健康检查指令,得到返回结果,所述返回结果用于表征所述第一对外通信地址对应的部署于物理机中的服务存活或者不存活;Send a health check instruction to the target address, and obtain a return result, where the return result is used to indicate that the service deployed in the physical machine corresponding to the first external communication address is alive or not;

若根据所述返回结果确定所述第一对外通信地址对应的部署于物理机中的服务不存活,则将所述配置文件中的所述第一对外通信地址删除。If it is determined according to the returned result that the service deployed in the physical machine corresponding to the first external communication address does not survive, the first external communication address in the configuration file is deleted.

在一个实施例中,所述指示信息包括Pod资源标签以及第二对外通信地址的第一部分,所述第二对外通信地址为与所述目标Service资源相关联的部署于容器中的服务的对外通信地址,处理器执行计算机程序时具体实现以下步骤:In one embodiment, the indication information includes a Pod resource label and a first part of a second external communication address, where the second external communication address is an external communication of a service deployed in a container associated with the target Service resource Address, the processor specifically implements the following steps when executing the computer program:

基于所述Pod资源标签查找目标Pod资源,所述目标Pod资源包括所述第二对外通信地址的第二部分;Find the target Pod resource based on the Pod resource label, and the target Pod resource includes the second part of the second external communication address;

从所述目标Pod资源中获取所述第二部分,并基于所述第一部分和所述第二部分生成所述第二对外通信地址。The second part is obtained from the target Pod resource, and the second external communication address is generated based on the first part and the second part.

在一个实施例中,所述第二对外通信地址包括IP地址和端口号,所述第一部分为端口号,所述第二部分为IP地址。In one embodiment, the second external communication address includes an IP address and a port number, the first part is the port number, and the second part is the IP address.

在一个实施例中,提供了一种计算机可读存储介质,其上存储有计算机程序,计算机程序被处理器执行时实现以下步骤:In one embodiment, a computer-readable storage medium is provided on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:

接收客户端发送的服务请求,所述服务请求携带有目标URI;Receive a service request sent by the client, where the service request carries a target URI;

基于所述目标URI查询配置文件,得到能够响应所述服务请求的多个目标服务的对外通信地址,其中,各所述目标服务部署于容器或者物理机中,所述配置文件包括URI与部署于容器或者物理机的服务的对外通信地址的对应关系;Querying a configuration file based on the target URI to obtain the external communication addresses of multiple target services that can respond to the service request, wherein each target service is deployed in a container or a physical machine, and the configuration file includes a URI and a configuration file deployed in a The correspondence between the external communication addresses of the services of the container or physical machine;

基于预设的负载均衡策略,从所述多个目标服务中确定标的服务,基于所述标的服务的对外通信地址将所述服务请求定向至所述标的服务。Based on a preset load balancing policy, a target service is determined from the plurality of target services, and the service request is directed to the target service based on an external communication address of the target service.

在一个实施例中,计算机程序被处理器执行时还实现以下步骤:In one embodiment, the computer program further implements the following steps when executed by the processor:

获取至少一个Ingress资源,各所述Ingress资源包括URI和Service资源名;Obtain at least one Ingress resource, each described Ingress resource includes a URI and a Service resource name;

对于各所述Ingress资源,基于所述Ingress资源包括的Service资源名查找目标Service资源,基于所述目标Service资源中的指示信息,获取与所述目标Service资源相关联的部署于物理机或者容器的服务的对外通信地址,并建立所述Ingress资源包括的URI和与所述目标Service资源相关联的服务的对外通信地址的对应关系;For each of the Ingress resources, the target Service resource is searched based on the Service resource name included in the Ingress resource, and based on the indication information in the target Service resource, the information associated with the target Service resource and deployed on the physical machine or container is obtained. the external communication address of the service, and establish a correspondence between the URI included in the Ingress resource and the external communication address of the service associated with the target Service resource;

基于各所述对应关系,创建所述配置文件。Based on each of the corresponding relationships, the configuration file is created.

在一个实施例中,所述指示信息包括自定义资源名,计算机程序被处理器执行时具体实现以下步骤:In one embodiment, the indication information includes a user-defined resource name, and when the computer program is executed by the processor, the following steps are specifically implemented:

基于所述自定义资源名查找目标自定义资源,所述目标自定义资源包括第一对外通信地址,所述第一对外通信地址为与所述目标Service资源相关联的部署于物理机中的服务的对外通信地址;Find a target custom resource based on the custom resource name, where the target custom resource includes a first external communication address, and the first external communication address is a service deployed in a physical machine associated with the target Service resource 's external correspondence address;

从所述目标自定义资源中获取所述第一对外通信地址。Obtain the first external communication address from the target custom resource.

在一个实施例中,所述目标Service资源包括注解字段,所述注解字段包括所述自定义资源名。In one embodiment, the target Service resource includes an annotation field, and the annotation field includes the user-defined resource name.

在一个实施例中,所述目标自定义资源包括spec字段,所述spec字段包括所述第一对外通信地址;In one embodiment, the target custom resource includes a spec field, and the spec field includes the first external communication address;

所述目标自定义资源还包括apiVersion字段、kind字段、metadata字段以及健康检查字段中的至少一个,其中,所述apiVersion字段包括所述目标自定义资源的版本信息,所述kind字段包括所述目标自定义资源的类型信息,所述metadata字段包括所述目标自定义资源的名称以及所述目标自定义资源的命名空间信息,所述健康检查字段包括健康检查地址,所述健康检查地址用于供所述服务器对与所述目标Service资源相关联的部署于物理机中的服务进行健康检查。The target custom resource also includes at least one of an apiVersion field, a kind field, a metadata field, and a health check field, wherein the apiVersion field includes version information of the target custom resource, and the kind field includes the target Type information of the custom resource, the metadata field includes the name of the target custom resource and the namespace information of the target custom resource, the health check field includes a health check address, and the health check address is used for The server performs a health check on the service deployed in the physical machine associated with the target Service resource.

在一个实施例中,在所述目标自定义资源包括所述健康检查字段的情况下,计算机程序被处理器执行时还实现以下步骤:In one embodiment, when the target custom resource includes the health check field, the computer program further implements the following steps when executed by the processor:

基于所述健康检查地址和所述第一对外通信地址,生成目标地址;generating a target address based on the health check address and the first external communication address;

向所述目标地址发送健康检查指令,得到返回结果,所述返回结果用于表征所述第一对外通信地址对应的部署于物理机中的服务存活或者不存活;Send a health check instruction to the target address, and obtain a return result, where the return result is used to indicate that the service deployed in the physical machine corresponding to the first external communication address is alive or not;

若根据所述返回结果确定所述第一对外通信地址对应的部署于物理机中的服务不存活,则将所述配置文件中的所述第一对外通信地址删除。If it is determined according to the returned result that the service deployed in the physical machine corresponding to the first external communication address does not survive, the first external communication address in the configuration file is deleted.

在一个实施例中,所述指示信息包括Pod资源标签以及第二对外通信地址的第一部分,所述第二对外通信地址为与所述目标Service资源相关联的部署于容器中的服务的对外通信地址,计算机程序被处理器执行时具体实现以下步骤:In one embodiment, the indication information includes a Pod resource label and a first part of a second external communication address, where the second external communication address is an external communication of a service deployed in a container associated with the target Service resource address, the computer program specifically implements the following steps when executed by the processor:

基于所述Pod资源标签查找目标Pod资源,所述目标Pod资源包括所述第二对外通信地址的第二部分;Find the target Pod resource based on the Pod resource label, and the target Pod resource includes the second part of the second external communication address;

从所述目标Pod资源中获取所述第二部分,并基于所述第一部分和所述第二部分生成所述第二对外通信地址。The second part is obtained from the target Pod resource, and the second external communication address is generated based on the first part and the second part.

在一个实施例中,所述第二对外通信地址包括IP地址和端口号,所述第一部分为端口号,所述第二部分为IP地址。In one embodiment, the second external communication address includes an IP address and a port number, the first part is the port number, and the second part is the IP address.

本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,所述的计算机程序可存储于一非易失性计算机可读取存储介质中,该计算机程序在执行时,可包括如上述各方法的实施例的流程。其中,本申请所提供的各实施例中所使用的对存储器、存储、数据库或其它介质的任何引用,均可包括非易失性和易失性存储器中的至少一种。非易失性存储器可包括只读存储器(Read-Only Memory,ROM)、磁带、软盘、闪存或光存储器等。易失性存储器可包括随机存取存储器(Random Access Memory,RAM)或外部高速缓冲存储器。作为说明而非局限,RAM可以是多种形式,比如静态随机存取存储器(Static Random Access Memory,SRAM)或动态随机存取存储器(Dynamic Random Access Memory,DRAM)等。Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be implemented by instructing relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage In the medium, when the computer program is executed, it may include the processes of the above-mentioned method embodiments. Wherein, any reference to memory, storage, database or other media used in the various embodiments provided in this application may include at least one of non-volatile and volatile memory. The non-volatile memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, and the like. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, the RAM may be in various forms, such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM).

以上实施例的各技术特征可以进行任意的组合,为使描述简洁,未对上述实施例中的各个技术特征所有可能的组合都进行描述,然而,只要这些技术特征的组合不存在矛盾,都应当认为是本说明书记载的范围。The technical features of the above embodiments can be combined arbitrarily. In order to make the description simple, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features It is considered to be the range described in this specification.

以上所述实施例仅表达了本申请的几种实施方式,其描述较为具体和详细,但并不能因此而理解为对发明专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本申请构思的前提下,还可以做出若干变形和改进,这些都属于本申请的保护范围。因此,本申请专利的保护范围应以所附权利要求为准。The above-mentioned embodiments only represent several embodiments of the present application, and the descriptions thereof are specific and detailed, but should not be construed as a limitation on the scope of the invention patent. It should be pointed out that for those skilled in the art, without departing from the concept of the present application, several modifications and improvements can be made, which all belong to the protection scope of the present application. Therefore, the scope of protection of the patent of the present application shall be subject to the appended claims.

Claims (10)

CN202010601316.1A2020-06-292020-06-29Request processing method, device, server and computer readable storage mediumActiveCN111752681B (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN202010601316.1ACN111752681B (en)2020-06-292020-06-29Request processing method, device, server and computer readable storage medium

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN202010601316.1ACN111752681B (en)2020-06-292020-06-29Request processing method, device, server and computer readable storage medium

Publications (2)

Publication NumberPublication Date
CN111752681Atrue CN111752681A (en)2020-10-09
CN111752681B CN111752681B (en)2024-12-17

Family

ID=72677751

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN202010601316.1AActiveCN111752681B (en)2020-06-292020-06-29Request processing method, device, server and computer readable storage medium

Country Status (1)

CountryLink
CN (1)CN111752681B (en)

Cited By (8)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN112468580A (en)*2020-11-252021-03-09政采云有限公司Method, device, equipment and storage medium for calling business service
CN113448594A (en)*2021-06-292021-09-28京东科技控股股份有限公司Service processing method and device, computer equipment and storage medium
CN113608865A (en)*2021-07-132021-11-05北京奇艺世纪科技有限公司Flow control method, device, system, electronic equipment and storage medium
CN113783922A (en)*2021-03-262021-12-10北京沃东天骏信息技术有限公司 Method, system and device for load balancing
CN114048028A (en)*2021-11-012022-02-15北京金山云网络技术有限公司Service calling method and device, storage medium and electronic equipment
CN114490024A (en)*2021-12-202022-05-13新浪网技术(中国)有限公司Load distribution method, configuration method and hardware of Kubernetes back-end service
US20230108778A1 (en)*2021-09-282023-04-06Citrix Systems, Inc.Automated Generation of Objects for Kubernetes Services
CN119743530A (en)*2024-12-162025-04-01苏州元脑智能科技有限公司Service access method, device, communication equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN101610222A (en)*2009-07-202009-12-23中兴通讯股份有限公司Client-based server selection method and device
US20180167453A1 (en)*2016-12-142018-06-14Huawei Technologies Co., Ltd.Distributed load balancing system, health check method, and service node
CN108965381A (en)*2018-05-312018-12-07康键信息技术(深圳)有限公司Implementation of load balancing, device, computer equipment and medium based on Nginx
CN110730250A (en)*2019-09-062020-01-24北京小米移动软件有限公司 Information processing method and device, service system, storage medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN101610222A (en)*2009-07-202009-12-23中兴通讯股份有限公司Client-based server selection method and device
US20180167453A1 (en)*2016-12-142018-06-14Huawei Technologies Co., Ltd.Distributed load balancing system, health check method, and service node
CN108965381A (en)*2018-05-312018-12-07康键信息技术(深圳)有限公司Implementation of load balancing, device, computer equipment and medium based on Nginx
CN110730250A (en)*2019-09-062020-01-24北京小米移动软件有限公司 Information processing method and device, service system, storage medium

Cited By (9)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN112468580A (en)*2020-11-252021-03-09政采云有限公司Method, device, equipment and storage medium for calling business service
CN113783922A (en)*2021-03-262021-12-10北京沃东天骏信息技术有限公司 Method, system and device for load balancing
CN113783922B (en)*2021-03-262024-11-26北京沃东天骏信息技术有限公司 Load balancing method, system and device
CN113448594A (en)*2021-06-292021-09-28京东科技控股股份有限公司Service processing method and device, computer equipment and storage medium
CN113608865A (en)*2021-07-132021-11-05北京奇艺世纪科技有限公司Flow control method, device, system, electronic equipment and storage medium
US20230108778A1 (en)*2021-09-282023-04-06Citrix Systems, Inc.Automated Generation of Objects for Kubernetes Services
CN114048028A (en)*2021-11-012022-02-15北京金山云网络技术有限公司Service calling method and device, storage medium and electronic equipment
CN114490024A (en)*2021-12-202022-05-13新浪网技术(中国)有限公司Load distribution method, configuration method and hardware of Kubernetes back-end service
CN119743530A (en)*2024-12-162025-04-01苏州元脑智能科技有限公司Service access method, device, communication equipment and storage medium

Also Published As

Publication numberPublication date
CN111752681B (en)2024-12-17

Similar Documents

PublicationPublication DateTitle
CN111752681A (en) Request processing method, apparatus, server, and computer-readable storage medium
TWI752939B (en) Method and device for processing user request
CN113268308B (en)Information processing method, device and storage medium
US8321503B2 (en)Context-specific network resource addressing model for distributed services
CN106982236B (en) An information processing method, device and system
CN108243079B (en)Method and equipment for network access based on VPC
CN113301116A (en)Cross-network communication method, device, system and equipment for microservice application
CN113691575B (en) Communication method, device and system
CN111786984B (en)Pod communication connection method and device, electronic equipment and storage medium
US7818752B2 (en)Interface for application components
CN113810230A (en)Method, device and system for carrying out network configuration on containers in container cluster
CN112600931B (en) A kind of API gateway deployment method and device
CN111274004B (en)Process instance management method and device and computer storage medium
US10545667B1 (en)Dynamic data partitioning for stateless request routing
CN119557055A (en) Cross-Kubernetes cluster service access method, device, computer equipment and storage medium
US10541864B1 (en)System and method for connection efficiency
US10452295B1 (en)Data routing in information processing system utilizing persistent memory
US11140183B2 (en)Determining criticality of identified enterprise assets using network session information
CN108733805B (en) File interaction method, system, computer device and storage medium
CN116915770A (en) Service deployment methods, devices, electronic equipment and storage media
CN115941801A (en)Method, equipment and storage medium for client to access multi-system server
CN118827700A (en) Distributed system data processing method, device, system, equipment and storage medium
CN116192952A (en)Domain name routing-based access method, device, computer equipment and storage medium
CN116032995A (en)Data communication method and device, electronic equipment and computer readable storage medium
HK40024058B (en)Process instance management method and device and computer storage medium

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination
EE01Entry into force of recordation of patent licensing contract

Application publication date:20201009

Assignee:GUANGZHOU CUBESILI INFORMATION TECHNOLOGY Co.,Ltd.

Assignor:GUANGZHOU HUADUO NETWORK TECHNOLOGY Co.,Ltd.

Contract record no.:X2021440000031

Denomination of invention:Request processing method, apparatus, server and computer readable storage medium

License type:Common License

Record date:20210125

EE01Entry into force of recordation of patent licensing contract
GR01Patent grant
GR01Patent grant

[8]ページ先頭

©2009-2025 Movatter.jp