CN111327647B - Method and device for providing service to outside by container and electronic equipment - Google Patents

Method and device for providing service to outside by container and electronic equipment Download PDF

Info

Publication number
CN111327647B
CN111327647B CN201811526345.5A CN201811526345A CN111327647B CN 111327647 B CN111327647 B CN 111327647B CN 201811526345 A CN201811526345 A CN 201811526345A CN 111327647 B CN111327647 B CN 111327647B
Authority
CN
China
Prior art keywords
container
server
access request
target
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.)
Active
Application number
CN201811526345.5A
Other languages
Chinese (zh)
Other versions
CN111327647A (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.)
Beijing Kingsoft Cloud Network Technology Co Ltd
Beijing Kingsoft Cloud Technology Co Ltd
Original Assignee
Beijing Kingsoft Cloud Network Technology Co Ltd
Beijing Kingsoft Cloud 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 Beijing Kingsoft Cloud Network Technology Co Ltd, Beijing Kingsoft Cloud Technology Co Ltd filed Critical Beijing Kingsoft Cloud Network Technology Co Ltd
Priority to CN201811526345.5A priority Critical patent/CN111327647B/en
Publication of CN111327647A publication Critical patent/CN111327647A/en
Application granted granted Critical
Publication of CN111327647B publication Critical patent/CN111327647B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1001Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1001Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers
    • H04L67/1004Server selection for load balancing
    • H04L67/1017Server selection for load balancing based on a round robin mechanism
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1001Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers
    • H04L67/1004Server selection for load balancing
    • H04L67/1023Server selection for load balancing based on a hash applied to IP addresses or costs

Abstract

The embodiment of the invention provides a method and a device for providing services to the outside by a container and electronic equipment, wherein the method comprises the following steps: acquiring an access request of a client, wherein the access request comprises a source IP address; searching a container corresponding to the source IP address in a pre-stored access request distribution path table to serve as a target container; if the target container corresponding to the source IP address is found, acquiring address information of the target container from a pre-stored container information list; based on the address information, an access request is sent to the target container. According to the embodiment of the invention, the target container corresponding to the source IP address can be determined directly through the pre-stored access request distribution path table, and the access request is directly sent to the target container based on the address information of the target container in the pre-stored container information list, so that the data forwarding path is shortened, and the data forwarding efficiency is improved.

Description

Method and device for providing service to outside by container and electronic equipment
Technical Field
The invention relates to the technical field of cloud computing, in particular to a method and a device for providing services to the outside by a container and electronic equipment.
Background
With the development of container technology, the cloud system can provide network services outside by using container pairs. Specifically, as shown in fig. 1, the present cloud system may include a Load balancer Load Balance and a cloud host Node, where the cloud system is in communication connection with a client through the Load balancer Load Balance, and the cloud host Node is used as a background server of the Load balancer and is in communication connection with the Load balancer, where the Load balancer Load Balance is configured with a port number of a cloud host port of the cloud host Node; the cloud host Node runs with a Container and is configured with a kube-proxy module, and a plurality of Container containers form a Container group Pod; the kube-proxy module is configured with a mapping relation between a cloud host port of the cloud host Node and a container port of the container, and the cloud system is deployed through kubernets. Kubernetes is a container arrangement engine of Google open source, and supports automatic deployment, large-scale scalability and application containerization management.
Based on the architecture of the current cloud system shown in fig. 1, the process of providing external network services by the application container of the current cloud system generally includes: the method comprises the steps that a client sends an access request to a load balancer of a cloud system, the load balancer distributes a target cloud host to the access request based on a configured port number of a cloud host port of the cloud host, and the access request is sent to the target cloud host; the method comprises the steps that a kube-proxy module of a target cloud host obtains an access request, a target container corresponding to the target cloud host is determined through a configured mapping relation between a cloud host port of the cloud host and a container port of the container, the access request is sent to the target container, then the target container processes the access request, a processing result is obtained, the processing result is fed back to a client through the kube-proxy module and a load balancer, and the cloud system application container provides network service for the outside.
When the current cloud system application container provides external network service, an access request of a client needs to be forwarded for multiple times through a load balancer and a kube-proxy module of a cloud host to be sent to the container for processing, and a forwarding path is long.
Disclosure of Invention
The embodiment of the invention aims to provide a method, a device and electronic equipment for providing a service to the outside by a container, so as to shorten a data forwarding path and improve data forwarding performance. The specific technical scheme is as follows:
in one aspect, an embodiment of the present invention provides a method for providing a service to outside a container, where the method includes:
acquiring an access request of a client, wherein the access request comprises a source IP address;
searching a container corresponding to the source IP address in a pre-stored access request distribution path table to serve as a target container;
if the target container corresponding to the source IP address is found, acquiring address information of the target container from a prestored container information list;
and sending the access request to the target container based on the address information.
Optionally, before the step of obtaining the access request of the client, the method further includes:
acquiring address information of containers included in a container cluster;
and establishing the container information list based on the acquired address information of the container.
Optionally, the address information of the container includes: the IP address of the container, the port number, and the ID of the server where the container is located.
Optionally, the method further comprises:
if the target container corresponding to the source IP address is not found in the pre-stored access request distribution path table, executing the following steps:
selecting a server to receive the access request from a server cluster as a target server;
selecting a container to receive the access request from the containers running on the target server as a target container;
acquiring address information of the target container from a pre-stored container information list;
sending the access request to the target container based on the address information;
and establishing the access request distribution path table based on the source IP address and the container identification of the target container.
Optionally, the step of selecting, as a target server, a server to receive the access request from the server cluster includes:
selecting a server to receive the access request from a server cluster as a target server based on a preset load balancing scheduling rule, wherein the preset load balancing scheduling rule comprises: a polling rule and/or a minimum number of connections rule.
Optionally, the polling rule includes: according to the preset weight of the server, selecting the server with the minimum weight from the server cluster as a target server;
the minimum connection number rule comprises: and acquiring the connection number of each server in the server cluster, and selecting the server with the minimum connection number from the server cluster as a target server.
Optionally, the container runs on kubernets, the method further comprising:
subscribing to update events of containers in the container information list through an interface provided by the kubernets;
monitoring whether the container is changed based on an update event;
and if the address information of the changed container is changed, updating the address information of the changed container into the container information list.
In another aspect, an embodiment of the present invention provides an apparatus for providing a service to outside a container, where the apparatus includes:
the system comprises a first acquisition module, a second acquisition module and a third acquisition module, wherein the first acquisition module is used for acquiring an access request of a client, and the access request comprises a source IP address;
the searching module is used for searching a container corresponding to the source IP address in a prestored access request distribution path table to serve as a target container;
the second acquisition module is used for acquiring the address information of the target container from a prestored container information list if the target container corresponding to the source IP address is found;
a first sending module, configured to send the access request to the target container based on the address information.
Optionally, the apparatus further comprises:
a third obtaining module, configured to obtain address information of a container included in the container cluster before obtaining the access request of the client;
and the first establishing module is used for establishing the container information list based on the acquired address information of the container.
Optionally, the address information of the container includes: the IP address of the container, the port number, and the ID of the server where the container is located.
Optionally, the apparatus further comprises:
the first selection module is used for selecting a server to receive the access request from a server cluster as a target server if the target container corresponding to the source IP address is not found in a prestored access request distribution path table;
the second selection module is used for selecting a container to receive the access request from the containers running on the target server as a target container;
the fourth acquisition module is used for acquiring the address information of the target container from a prestored container information list;
a second sending module, configured to send the access request to the target container based on the address information;
and the second establishing module is used for establishing the access request distribution path table based on the source IP address and the container identifier of the target container.
Optionally, the first selection module is specifically configured to
Selecting a server to receive the access request from a server cluster as a target server based on a preset load balancing scheduling rule, wherein the preset load balancing scheduling rule comprises: a polling rule and/or a minimum number of connections rule.
Optionally, the polling rule includes: according to the preset weight of the server, selecting the server with the minimum weight from the server cluster as a target server;
the minimum connection number rule includes: and acquiring the connection number of each server in the server cluster, and selecting the server with the minimum connection number from the server cluster as a target server.
Optionally, the container is run on kubernets, the apparatus further comprising:
a subscription module, configured to subscribe to an update event of a container in the container information list through an interface provided by the kubernets;
a detection module for monitoring whether the container is changed based on an update event;
and the updating module is used for updating the address information of the changed container into the container information list if the address information changes.
On the other hand, an embodiment of the present invention provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete mutual communication through the communication bus;
a memory for storing a computer program;
the processor is configured to implement the method steps of providing the service to the outside by any one of the containers provided in the embodiments of the present invention when executing the computer program stored in the memory.
In another aspect, the embodiment of the present invention provides a computer-readable storage medium, in which a computer program is stored, and the computer program, when executed by a processor, implements the method steps of providing the service outside the container according to any of the above-mentioned embodiments of the present invention.
In the technical scheme provided by the embodiment of the invention, an access request of a client is obtained, wherein the access request comprises a source IP address; searching a container corresponding to the source IP address in a pre-stored access request distribution path table to serve as a target container; if the target container corresponding to the source IP address is found, acquiring the address information of the target container from a prestored container information list; based on the address information, an access request is sent to the target container. According to the embodiment of the invention, the target container corresponding to the source IP address can be determined directly through the pre-stored access request distribution path table, the access request is directly sent to the target container based on the address information of the target container in the pre-stored container information list, and the access request is processed through the target container, so that the address information of the container is directly exposed to the client, the data forwarding path is shortened, and the data forwarding performance is improved. Of course, it is not necessary for any product or method of practicing the invention to achieve all of the above-described advantages at the same time.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
FIG. 1 is a schematic diagram of a current cloud system architecture;
fig. 2 is a schematic flow chart of a method for providing a service to outside of a container according to an embodiment of the present invention;
fig. 3 is another schematic flow chart of a method for providing a service to outside of a container according to an embodiment of the present invention;
fig. 4 is a schematic diagram of an architecture of a cloud system according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of an apparatus for providing a service to outside of a container according to an embodiment of the present invention;
fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The embodiment of the invention provides a method and a device for providing services to the outside by a container and electronic equipment, which are used for shortening a data forwarding path and improving data forwarding performance.
As shown in fig. 2, an embodiment of the present invention provides a method for providing a service outside a container, which may include the following steps:
s201: acquiring an access request of a client;
wherein, the access request includes a source IP Address (Internet Protocol Address, which is translated into an Internet Protocol Address);
it is understood that the method for providing the service outside the container provided by the embodiment of the present invention may be applied to any type of electronic device, for example: computers, mobile phones, all-in-one machines and the like. In one implementation, the electronic device may be disposed in a cloud system, the cloud system may provide a service to the outside using a container, and the cloud system may further include a server cluster, at least one container running on each server in the server cluster. In one case, the electronic device may be built as a load balancer for the cloud system. Wherein, the cloud system can be a public cloud system.
When the user has an access requirement, an access request can be sent to the electronic device through the client, and then the electronic device obtains the access request of the client. In one case, the electronic device may simultaneously obtain access requests of at least one client. When an access request of a client is obtained, the electronic device executes a subsequent container-to-outside service process for the access request of the client. When the access requests of the multiple clients are obtained simultaneously, each access request includes a source IP address, and subsequently, the electronic device may execute a subsequent process of providing a service to the outside by the container with respect to the access request of each client.
In one implementation, the access request includes a source IP address: the IP address of the client sending the access request.
S202: searching a container corresponding to the source IP address in a pre-stored access request distribution path table to serve as a target container;
wherein the access request distribution path table stores: the correspondence between the IP address and the container identification of the container. The container identification of the container may be: container name and/or serial number of the container in the container cluster, etc. may uniquely identify the container.
In this step, after acquiring the access request of the client, the electronic device traverses the pre-stored access request distribution path table, searches whether the source IP address is stored in the pre-stored access request distribution path table, and continues to search for the container identifier corresponding to the source IP address if the source IP address is found from the pre-stored access request distribution path table; if the container identifier corresponding to the source IP address is found, the container corresponding to the container identifier corresponding to the source IP address is used as a target container, and the subsequent process of providing the service to the outside by the container provided by the embodiment of the invention is executed.
If the source IP address is not found from the pre-stored access request distribution path table, it may be determined that the container identifier of the container corresponding to the source IP address is not stored in the pre-stored access request distribution path table. In one case, in order to ensure a valid reply of the access request of the client, the electronic device may continue to execute the corresponding process. For determining the pre-stored access request distribution path table, the corresponding flow after the container identifier of the container corresponding to the source IP address is not stored is introduced later for clarity of layout.
S203: if the target container corresponding to the source IP address is found, acquiring the address information of the target container from a prestored container information list;
the container information list stores address information of a plurality of containers. In one case, the storage manner in which the address information of the plurality of containers is stored in the container information list may be: the correspondence between the identification of the container and the address information.
And if the target container corresponding to the source IP address is searched in a pre-stored access request distribution path table, acquiring the address information of the target container from a pre-stored container information list. In an implementation manner, the process of obtaining the address information of the target container from the pre-stored container information list may be: and searching a target container identifier corresponding to the source IP address from a pre-stored access request distribution path table, traversing a pre-stored container information list, searching and obtaining address information corresponding to the target container identifier from the pre-stored container information list, and taking the address information corresponding to the target container identifier as the address information of the target container.
In one implementation, the address information of the container includes: the IP address of the container, the port number, and the ID of the server where the container is located. The container can be uniquely identified and located by its address information.
Where the container runs on a server, the server running the container may be referred to as: the server where the container is located. The ID of the server where the container is located may refer to: the ID of the server running the container. In one case, the ID of the server running the container may be: the IP address and/or port number of the server running the container. In one implementation, when the electronic device is disposed in a cloud system, the server where the container is located may be a cloud host in the cloud system.
S204: based on the address information, an access request is sent to the target container.
In this step, the access request is sent to the determined address information, so as to send the access request to the target container. In an implementation manner, after receiving the access request, the target container may process the access request to obtain a processing result, and then feed back the processing result to the electronic device, where the electronic device feeds back the processing result to the client.
In the technical scheme provided by the embodiment of the invention, an access request of a client is obtained, wherein the access request comprises a source IP address; searching a container corresponding to the source IP address in a prestored access request distribution path table to serve as a target container; if the target container corresponding to the source IP address is found, acquiring address information of the target container from a pre-stored container information list; based on the address information, an access request is sent to the target container. According to the embodiment of the invention, the target container corresponding to the source IP address can be determined directly through the pre-stored access request distribution path table, the access request is directly sent to the target container based on the address information of the target container in the pre-stored container information list, and the access request is processed through the target container, so that the address information of the container is directly exposed to the client, the data forwarding path is shortened, and the data forwarding performance is improved.
In one implementation, before the step of obtaining the access request of the client, the method may further include:
acquiring address information of containers included in a container cluster;
and establishing a container information list based on the acquired address information of the container.
The containers included in the container cluster are all containers associated with the electronic device, where the association may refer to: the storage device local to the electronic device or connected to the electronic device stores address information of the containers included in the container cluster, and can schedule a load of each container. In one case, when the electronic device is installed in a cloud system, all the containers included in the container cluster are containers operating in a cloud host of the cloud system.
For the process of obtaining address information of containers included in the container cluster, an implementation manner may be: the staff inputs the address information of the container associated with the electronic device into the electronic device, so that the electronic device obtains the address information of the container included in the container cluster. Another implementation may be: the electronic device reads the address information of the container from the associated container, so that the electronic device obtains the address information of the container included in the container cluster.
After the electronic device acquires the address information of the containers included in the container cluster, a container information list is established based on the acquired address information of the containers. In one implementation, the electronic device stores the acquired address information of the container in a container information list. Specifically, the method may comprise the following steps: and acquiring the container identifier of each container, and storing the acquired address information of each container and the corresponding relation between the container identifiers of the containers into a container information list.
In one implementation, as shown in fig. 3, the method may include the steps of:
s301: acquiring an access request of a client;
wherein the access request includes a source IP address;
s302: searching a container corresponding to the source IP address in a prestored access request distribution path table to serve as a target container, if the target container corresponding to the source IP address is searched, executing S303, and if the target container corresponding to the source IP address is not searched, executing S305;
s303: acquiring address information of a target container from a pre-stored container information list;
s304: based on the address information, sending an access request to the target container;
wherein S301 is the same as S201 shown in fig. 2, S302 is the same as S202 shown in fig. 2, S303 is the same as S203 shown in fig. 2, and S304 is the same as S204 shown in fig. 2.
S305: selecting a server to receive an access request from a server cluster as a target server;
s306: selecting a container to receive an access request from containers running on a target server as a target container;
s307: acquiring address information of a target container from a pre-stored container information list;
s308: based on the address information, sending an access request to the target container;
s309: an access request distribution path table is established based on the source IP address and the container identification of the target container.
The implementation manner of S307 may refer to the implementation manner of S303, and the implementation manner of S308 may refer to the implementation manner of S304, which is not described herein again.
In one case, the servers included in the server cluster may be: a virtual server or a physical server. The virtual server may refer to: and the server is built by the virtual machines operated in the entity equipment. The physical server may refer to: and the server is built by the entity equipment.
The servers included in the server cluster are associated with the electronic device, where the association may refer to: the storage device local to the electronic device or connected thereto stores an ID of each server included in the server cluster, and can schedule a load of each server. In an implementation manner, when the electronic device is disposed in a cloud system, the server cluster may be a cloud host cluster of the cloud system.
At least one container may be run on each server included in the server cluster.
If the target container corresponding to the source IP address is not found, namely the target container corresponding to the source IP address is not found in a prestored access request distribution path table, the electronic equipment can select a server to receive the access request from a server cluster in a random mode to serve as a target server; furthermore, a random mode can be adopted, a container to receive an access request is selected from containers running on a target server and is used as a target container, and address information of the target container is obtained from a pre-stored container information list; based on the address information, an access request is sent to the target container.
In another implementation manner, the step of selecting a server to receive an access request from a server cluster as a target server may include:
selecting a server to receive an access request from a server cluster as a target server based on a preset load balancing scheduling rule, wherein the preset load balancing scheduling rule comprises: a polling rule and/or a minimum number of connections rule.
In one implementation, the preset load balancing scheduling rule includes a polling rule, and the polling rule may include: and selecting the server with the minimum weight from the server cluster as a target server according to the preset weight of the server.
The storage device local to the electronic device or connected to the electronic device may have a preset weight for each server included in the server cluster. If the target container corresponding to the source IP address is not found in the pre-stored access request distribution path table, the electronic device may obtain a pre-stored preset weight of each server included in the server cluster, and select a server with a minimum preset weight from the server cluster as the target server according to the preset weight of each server.
In one case, the preset weight of each server included in the server cluster corresponds to an initial value. In order to ensure the load balance among the servers in the server cluster, one implementation may set the initial values of the preset weights of each server to be equal. If the electronic device obtains the access request of the client and does not find the target container corresponding to the source IP address in the pre-stored access request distribution path table, the electronic device may select the server with the smallest weight from the server cluster as the target server according to the preset weight of the server. The electronic equipment updates the preset weight of the target server, namely the sum of the initial value and the preset value is used as the preset weight of the target server; if the electronic device obtains the access request of another client and does not find the target container corresponding to the source IP address of another client in the pre-stored access request distribution path table, the electronic device may select, according to the current preset weight of the server, the server with the smallest weight from the server cluster as the target server, so as to select the server in the server cluster as the target server in a polling manner. The initial value may be a non-negative number, and the predetermined value is a positive number.
In another implementation, the performance of each server included in the server cluster is inevitably different, for a server with better performance, the speed of processing the access request by the container running on the server with better performance is relatively higher, in order to better guarantee the use experience of the user and improve the response speed of the access request, the electronic device may set an initial value of the preset weight of the server according to the performance of the server, wherein the better the performance of the server is, the smaller the initial value of the preset weight is. Therefore, the electronic equipment can preferentially select the server with better performance as the target server, and further process the access request of the client by using the container running on the server with better performance.
In another implementation manner, the preset load balancing scheduling rule includes a minimum connection number rule, where the minimum connection number rule may include: and acquiring the connection number of each server in the server cluster, and selecting the server with the minimum connection number from the server cluster as a target server.
Wherein, the number of connections can be characterized as: the total number of access requests currently processed by the container running on the corresponding server. In one case, in order to better balance the load among the servers in the server cluster, the server with the minimum connection number may be selected from the server cluster as the target server according to the connection number of each server, so as to select the target container from the containers running on the target server. The "current" may refer to a time when the electronic device does not find the target container corresponding to the source IP address in the pre-stored access request distribution path table after acquiring the access request of the client.
In another implementation manner, the preset load balancing scheduling rule includes a polling rule and a minimum connection number rule. In one case, a server with the smallest weight may be selected from the server cluster according to a preset weight of the server, if a plurality of servers with the smallest weight are selected, the number of connections of the selected server with the smallest weight may be obtained, and the server with the smallest number of connections may be selected from the selected servers with the smallest weight as the target server. In another case, the connection number of the servers included in the server cluster may be first obtained, and the server with the smallest connection number is selected from the servers included in the server cluster; if a plurality of selected servers with the smallest number of connections are available, selecting the server with the smallest weight from the selected servers with the smallest number of connections according to the preset weight of the selected servers with the smallest number of connections, and assembling the selected servers with the smallest weight as the target server.
In another implementation manner, the electronic device may further obtain, in real time or at regular time, the total amount of available resources and the current amount of used resources of each server included in the server cluster; and calculating the residual available resource amount of each server according to the total available resource amount of each server and the current used resource amount of each server in the server cluster, and selecting the server to receive the access request from the server cluster as a target server according to the residual available resource amount of each server. The above process of selecting a server to receive an access request from a server cluster according to the remaining available resource amount of each server as a target server may be: and selecting the server with the most residual available resource amount from the server cluster as a server to receive the access request as a target server.
In one implementation manner, the step of selecting, from the containers running on the target server, a container to receive the access request as the target container may be: the number of connections of the containers running on the target server is obtained, and the container with the smallest number of connections is selected as the target container from the containers running on the target server. Alternatively, it may be: and selecting a container to receive the access request from the containers running on the target server as the target container in a polling mode. For example: the containers running on the target server include container 1, container 2 and container 3, and container 1, container 2 and container 3 may be selected as the target container in sequence.
It can be understood that, after the target server is determined from the server cluster and the target container is determined from the containers running on the target server, in order to better improve the efficiency of replying to the access request of the client, the electronic device may record the correspondence between the client and the target container. After receiving the access request of the client again, the target container can be directly utilized to process the access request of the client. In one implementation, the access request distribution path table may be established based on a source IP address and a container identifier of a target container, where the process of establishing the access request distribution path table may be: and establishing a corresponding relation between the source IP address of the client and the container identifier of the target container, and recording the corresponding relation in an access request distribution path table.
In one implementation, the container runs on kubernets, the method may further comprise:
subscribing the update event of the container in the container information list through an interface provided by kubernets;
monitoring whether the container is changed or not based on the updating event;
and if the address information of the changed container is changed, updating the address information of the changed container into a container information list.
In one aspect, the container is run on kubernets and may be referred to as: the container runs on a cloud host in a cloud system which is deployed through kubernets, wherein the cloud host is a server mentioned in the embodiment of the invention.
In this implementation, kubernets provides an interface for subscribe to update events for containers, which may be a watch interface. Through the watch interface, the electronic device can monitor the containers recorded in the container information list, namely the associated containers, namely when the associated containers have the update events, the electronic device obtains the occurring update events through the watch interface, and determines whether the containers are changed and what the containers are changed according to the obtained occurring update events. For example: based on the update event, it is monitored whether the container is migrated, whether the container is condensed, and/or whether the container is expanded, etc. When the container is monitored to be migrated, the container is contracted and/or the container is expanded, the change of the container is determined.
In one aspect, the monitoring whether the container is migrated may be: and monitoring whether the address information of the container changes, wherein when the address information of the container changes, the container can be determined to be migrated. The monitoring whether the container is shrunk or not may be: monitoring whether a container is set as unavailable, wherein when the container is set as unavailable, it may be determined that the container is being scaled. Whether the container is expanded may be: and monitoring whether a new container appears, wherein when the new container appears, the container is determined to be expanded.
And after monitoring that the container is changed, the electronic equipment updates the address information of the changed container into a container information list. The process of updating the address information of the container to be changed into the container information list may be: when the situation that the address information of the container changes is monitored, the address information of the container with the changed address information stored in the container information list is modified into the changed address information. When it is detected that the existing container is set as unavailable, deleting the address information of the container set as unavailable stored in the container information list, or adding an unavailable identifier corresponding to the address information of the container set as unavailable. And when the appearance of a new container is monitored, storing the address information of the appearance of the new container into a container information list.
When the address information of the storage container in the container information list is added with the unavailable identification, the electronic equipment does not determine the container as the target container any more, namely, does not distribute the access request for the container any more.
The real-time updating of the container information list can ensure that the electronic equipment can obtain the latest container information, ensure that an available container can be determined in time, and ensure the reply efficiency of the access request to the client.
When the electronic device is installed in the cloud system, corresponding to the process of providing the service to the outside by the container, as shown in fig. 4, it is a schematic diagram of a cloud system architecture provided by an embodiment of the present invention. The cloud system is deployed through kubernets, the electronic device provided by the embodiment of the invention is built into a Load Balancer of the cloud system, and the container runs on a cloud host Node in the cloud system, namely the cloud host Node in the cloud system is used as a server where the container is located. The cloud system is provided with a plurality of cloud hosts Node, each cloud host runs with a plurality of Container groups Pod, and each Container group Pod comprises a plurality of Container containers. In one case, the containers in each Container group Pod correspond to the same IP address, and the Container can be managed more conveniently by the Container group Pod.
Based on the framework of the cloud system shown in fig. 4, the Client sends an access request including a source IP address to the electronic device, that is, a load balancer of the cloud system, the load balancer obtains the access request, searches a container corresponding to the source IP address in a pre-stored access request distribution path table, and uses the container as a target container, and if the target container corresponding to the source IP address is found, obtains address information of the target container from a pre-stored container information list; the load balancer sends the access request directly to the target container based on the address information. The forwarding path of the access request is shortened, and the forwarding performance of the access request is improved.
As shown in fig. 4, the cloud system may further include a cloudvovider module, where the cloudvovider module is in communication connection with the load balancer, and is configured to monitor an update event of the container, and send the monitored update event to the load balancer, where the load balancer monitors whether the container changes based on the obtained update event, and if so, updates address information of the container that has changed to the container information list.
Corresponding to the above method embodiment, an embodiment of the present invention provides an apparatus for providing a service outside a container, where as shown in fig. 5, the apparatus includes:
a first obtaining module 510, configured to obtain an access request of a client, where the access request includes a source IP address;
a searching module 520, configured to search, in a pre-stored access request distribution path table, a container corresponding to the source IP address as a target container;
a second obtaining module 530, configured to, if the target container corresponding to the source IP address is found, obtain address information of the target container from a pre-stored container information list;
a first sending module 540, configured to send the access request to the target container based on the address information.
In the technical scheme provided by the embodiment of the invention, an access request of a client is obtained, wherein the access request comprises a source IP address; searching a container corresponding to the source IP address in a pre-stored access request distribution path table to serve as a target container; if the target container corresponding to the source IP address is found, acquiring the address information of the target container from a prestored container information list; based on the address information, an access request is sent to the target container. According to the embodiment of the invention, the target container corresponding to the source IP address can be determined directly through the pre-stored access request distribution path table, the access request is directly sent to the target container based on the address information of the target container in the pre-stored container information list, and the access request is processed through the target container, so that the address information of the container is directly exposed to the client, the data forwarding path is shortened, and the data forwarding performance is improved.
In one implementation, the apparatus further comprises:
a third obtaining module, configured to obtain address information of a container included in the container cluster before obtaining the access request of the client;
and the first establishing module is used for establishing the container information list based on the acquired address information of the container.
In one implementation, the address information of the container includes: the IP address of the container, the port number, and the ID of the server where the container is located.
In one implementation, the apparatus further comprises:
the first selection module is used for selecting a server to receive the access request from a server cluster as a target server if the target container corresponding to the source IP address is not found in a prestored access request distribution path table;
the second selection module is used for selecting a container to receive the access request from the containers running on the target server as a target container;
the fourth acquisition module is used for acquiring the address information of the target container from a prestored container information list;
a second sending module, configured to send the access request to the target container based on the address information;
and the second establishing module is used for establishing the access request distribution path table based on the source IP address and the container identifier of the target container.
In one implementation, the first selection module is specifically configured to
Selecting a server to receive the access request from a server cluster as a target server based on a preset load balancing scheduling rule, wherein the preset load balancing scheduling rule comprises: a polling rule and/or a minimum number of connections rule.
In one implementation, the polling rule includes: according to the preset weight of the server, selecting the server with the minimum weight from the server cluster as a target server;
the minimum connection number rule comprises: and acquiring the connection number of each server in the server cluster, and selecting the server with the minimum connection number from the server cluster as a target server.
In one implementation, the container runs on kubernets, the apparatus further comprising:
a subscription module, configured to subscribe to an update event of a container in the container information list through an interface provided by the kubernets;
a detection module for monitoring whether the container has changed based on an update event;
and the updating module is used for updating the address information of the changed container into the container information list if the address information changes.
Corresponding to the above method embodiment, an electronic device according to an embodiment of the present invention is further provided, as shown in fig. 6, and includes a processor 610, a communication interface 620, a memory 630, and a communication bus 640, where the processor 610, the communication interface 620, and the memory 630 complete communication with each other through the communication bus 640,
a memory 630 for storing computer programs;
the processor 610 is configured to, when executing the computer program stored in the memory 630, implement the method steps of providing the service to the outside by using any of the containers according to the embodiments of the present invention.
In the technical scheme provided by the embodiment of the invention, an access request of a client is obtained, wherein the access request comprises a source IP address; searching a container corresponding to the source IP address in a pre-stored access request distribution path table to serve as a target container; if the target container corresponding to the source IP address is found, acquiring address information of the target container from a pre-stored container information list; based on the address information, an access request is sent to the target container. According to the embodiment of the invention, the target container corresponding to the source IP address can be determined directly through the pre-stored access request distribution path table, the access request is directly sent to the target container based on the address information of the target container in the pre-stored container information list, and the access request is processed through the target container, so that the address information of the container is directly exposed to the client, the data forwarding path is shortened, and the data forwarding performance is improved.
The communication bus mentioned in the electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this is not intended to represent only one bus or type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
The Memory may include a Random Access Memory (RAM) or a Non-Volatile Memory (NVM), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but also Digital Signal Processors (DSPs), application Specific Integrated Circuits (ASICs), field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components.
Corresponding to the above method embodiment, an embodiment of the present invention further provides a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the computer program implements any of the above method steps for providing a service outside a container, provided by the embodiment of the present invention.
In the technical scheme provided by the embodiment of the invention, an access request of a client is obtained, wherein the access request comprises a source IP address; searching a container corresponding to the source IP address in a pre-stored access request distribution path table to serve as a target container; if the target container corresponding to the source IP address is found, acquiring address information of the target container from a pre-stored container information list; based on the address information, an access request is sent to the target container. According to the embodiment of the invention, the target container corresponding to the source IP address can be determined directly through the pre-stored access request distribution path table, the access request is directly sent to the target container based on the address information of the target container in the pre-stored container information list, and the access request is processed through the target container, so that the address information of the container is directly exposed to the client, the data forwarding path is shortened, and the data forwarding performance is improved.
It should be noted that, in this document, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrases "comprising a," "8230," "8230," or "comprising" does not exclude the presence of additional like elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, as for the system embodiment, since it is substantially similar to the method embodiment, the description is relatively simple, and reference may be made to the partial description of the method embodiment for relevant points.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.

Claims (12)

1. A method for providing services to outside a container, the method comprising:
acquiring an access request of a client, wherein the access request comprises a source IP address;
searching a container corresponding to the source IP address in a pre-stored access request distribution path table to serve as a target container, wherein the access request distribution path table stores: the corresponding relation between the IP address and the container identifier of the container;
if the target container corresponding to the source IP address is found, acquiring the address information of the target container from a prestored container information list; the address information of the container includes: the IP address and port number of the container, and the ID of the server where the container is located;
sending the access request to the target container based on the address information;
if the target container corresponding to the source IP address is not found in the pre-stored access request distribution path table, executing the following steps:
selecting a server to receive the access request from a server cluster as a target server;
selecting a container to receive the access request from the containers running on the target server as a target container;
acquiring address information of the target container from a pre-stored container information list;
sending the access request to the target container based on the address information;
and establishing the access request distribution path table based on the source IP address and the container identification of the target container.
2. The method of claim 1, wherein prior to the step of obtaining the client's access request, the method further comprises:
acquiring address information of containers included in a container cluster;
and establishing the container information list based on the acquired address information of the container.
3. The method of claim 1, wherein the step of selecting the server from the server cluster to receive the access request as the target server comprises:
selecting a server to receive the access request from a server cluster as a target server based on a preset load balancing scheduling rule, wherein the preset load balancing scheduling rule comprises: a polling rule and/or a minimum number of connections rule.
4. The method of claim 3,
the polling rule includes: according to the preset weight of the server, selecting the server with the minimum weight from the server cluster as a target server;
the minimum connection number rule includes: and acquiring the connection number of each server in the server cluster, and selecting the server with the minimum connection number from the server cluster as a target server.
5. The method of any one of claims 1-2, wherein the container is operated on a kubernets, the method further comprising:
subscribing to update events of containers in the container information list through an interface provided by the kubernets;
monitoring whether the container is changed based on an update event;
and if the address information of the changed container is changed, updating the address information of the changed container into the container information list.
6. An apparatus for providing service to a container, the apparatus comprising:
the system comprises a first acquisition module, a first processing module and a first processing module, wherein the first acquisition module is used for acquiring an access request of a client, and the access request comprises a source IP address;
a searching module, configured to search, in a pre-stored access request distribution path table, a container corresponding to the source IP address as a target container, where the access request distribution path table stores: the corresponding relation between the IP address and the container identifier of the container;
the second acquisition module is used for acquiring the address information of the target container from a prestored container information list if the target container corresponding to the source IP address is found; the address information of the container includes: the IP address and port number of the container, and the ID of the server where the container is located;
a first sending module, configured to send the access request to the target container based on the address information;
the first selection module is used for selecting a server to receive the access request from a server cluster as a target server if the target container corresponding to the source IP address is not found in a prestored access request distribution path table;
the second selection module is used for selecting a container to receive the access request from the containers running on the target server as a target container;
the fourth acquisition module is used for acquiring the address information of the target container from a prestored container information list;
a second sending module, configured to send the access request to the target container based on the address information;
and the second establishing module is used for establishing the access request distribution path table based on the source IP address and the container identifier of the target container.
7. The apparatus of claim 6, further comprising:
a third obtaining module, configured to obtain address information of a container included in the container cluster before obtaining the access request of the client;
and the first establishing module is used for establishing the container information list based on the acquired address information of the container.
8. The device according to claim 6, characterized in that said first selection module is specifically configured for
Selecting a server to receive the access request from a server cluster as a target server based on a preset load balancing scheduling rule, wherein the preset load balancing scheduling rule comprises: a polling rule and/or a minimum number of connections rule.
9. The apparatus of claim 8,
the polling rule includes: according to the preset weight of the server, selecting the server with the minimum weight from the server cluster as a target server;
the minimum connection number rule includes: and acquiring the connection number of each server in the server cluster, and selecting the server with the minimum connection number from the server cluster as a target server.
10. The apparatus of any of claims 6-7, wherein the container is operable on kubernets, the apparatus further comprising:
a subscription module, configured to subscribe to an update event of a container in the container information list through an interface provided by the kubernets;
a detection module for monitoring whether the container has changed based on an update event;
and the updating module is used for updating the address information of the changed container into the container information list if the address information changes.
11. An electronic device is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor and the communication interface are used for realizing mutual communication by the memory through the communication bus;
a memory for storing a computer program;
a processor for implementing the method steps of providing services to the outside of a container according to any one of claims 1 to 5 when executing a computer program stored in a memory.
12. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the method steps of providing a service outside a container according to any one of claims 1 to 5.
CN201811526345.5A 2018-12-13 2018-12-13 Method and device for providing service to outside by container and electronic equipment Active CN111327647B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811526345.5A CN111327647B (en) 2018-12-13 2018-12-13 Method and device for providing service to outside by container and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811526345.5A CN111327647B (en) 2018-12-13 2018-12-13 Method and device for providing service to outside by container and electronic equipment

Publications (2)

Publication Number Publication Date
CN111327647A CN111327647A (en) 2020-06-23
CN111327647B true CN111327647B (en) 2023-02-03

Family

ID=71168425

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811526345.5A Active CN111327647B (en) 2018-12-13 2018-12-13 Method and device for providing service to outside by container and electronic equipment

Country Status (1)

Country Link
CN (1) CN111327647B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111881470A (en) * 2020-07-20 2020-11-03 易通星云(北京)科技发展有限公司 Data access method and device and computer readable storage medium
CN113067803B (en) * 2021-03-12 2023-05-05 北京金山云网络技术有限公司 Resource isolation system, request processing method and request processing device
CN113342552A (en) * 2021-07-05 2021-09-03 湖南快乐阳光互动娱乐传媒有限公司 Data processing method and device, storage medium and electronic equipment
CN114039977B (en) * 2021-11-10 2024-03-26 北京奇艺世纪科技有限公司 Method, system and device for realizing application task based on edge calculation
CN114710498B (en) * 2022-03-18 2024-03-01 深圳极联信息技术开发有限公司 Load balancing method and system supporting high concurrency access
CN114928615B (en) * 2022-05-19 2023-10-24 网宿科技股份有限公司 Load balancing method, device, equipment and readable storage medium
CN116033030B (en) * 2023-01-06 2023-08-11 钛信(上海)信息科技有限公司 Container management method and device for hybrid cloud network deployment

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106130990A (en) * 2016-06-29 2016-11-16 中国联合网络通信集团有限公司 The control method of container access and device
CN106790726A (en) * 2017-03-30 2017-05-31 电子科技大学 A kind of priority query's dynamic feedback of load equilibrium resource regulating method based on Docker cloud platforms
CN107196982A (en) * 2016-03-14 2017-09-22 阿里巴巴集团控股有限公司 A kind for the treatment of method and apparatus of user's request
CN107547596A (en) * 2016-06-27 2018-01-05 中兴通讯股份有限公司 A kind of cloud platform control method and device based on Docker
CN108737224A (en) * 2017-09-28 2018-11-02 新华三技术有限公司 A kind of message processing method and device based on micro services framework

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2017133291A1 (en) * 2016-02-02 2017-08-10 华为技术有限公司 Server cluster-based message generation method and load balancer
CN106789667B (en) * 2016-11-21 2021-01-01 华为技术有限公司 Data forwarding method, related equipment and system
CN107070983A (en) * 2017-01-23 2017-08-18 天地融科技股份有限公司 A kind of load-balancing method, equipment and system forwarded based on address
CN108574705A (en) * 2017-03-09 2018-09-25 中国移动通信集团湖北有限公司 Communication means, apparatus and system between a kind of container
CN108737584A (en) * 2017-04-19 2018-11-02 中国移动通信集团山西有限公司 The access method of container service, the analytic method of network address, device and system
CN108418884A (en) * 2018-03-09 2018-08-17 北京奇艺世纪科技有限公司 A kind of method, apparatus and electronic equipment of transmission services data

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107196982A (en) * 2016-03-14 2017-09-22 阿里巴巴集团控股有限公司 A kind for the treatment of method and apparatus of user's request
CN107547596A (en) * 2016-06-27 2018-01-05 中兴通讯股份有限公司 A kind of cloud platform control method and device based on Docker
CN106130990A (en) * 2016-06-29 2016-11-16 中国联合网络通信集团有限公司 The control method of container access and device
CN106790726A (en) * 2017-03-30 2017-05-31 电子科技大学 A kind of priority query's dynamic feedback of load equilibrium resource regulating method based on Docker cloud platforms
CN108737224A (en) * 2017-09-28 2018-11-02 新华三技术有限公司 A kind of message processing method and device based on micro services framework

Also Published As

Publication number Publication date
CN111327647A (en) 2020-06-23

Similar Documents

Publication Publication Date Title
CN111327647B (en) Method and device for providing service to outside by container and electronic equipment
CN111913818B (en) Method for determining dependency relationship between services and related device
US8825750B2 (en) Application server management system, application server management method, management apparatus, application server and computer program
JP2019503537A (en) Method and apparatus for processing short link and short link server
CN103685583A (en) Method and system for resolving domain names
CN111970198A (en) Service routing method, device, electronic equipment and medium
CN111182089A (en) Container cluster system, method and device for accessing big data assembly and server
CN112954089B (en) Method, device, equipment and storage medium for analyzing data
CN107172214B (en) Service node discovery method and device with load balancing function
US20170289243A1 (en) Domain name resolution method and electronic device
CN111556135A (en) Request scheduling method, system and device and electronic equipment
CN113361913A (en) Communication service arranging method, device, computer equipment and storage medium
CN110515631B (en) Method for generating application installation data packet, server and computer storage medium
CN113254165B (en) Load flow distribution method and device for virtual machine and container, and computer equipment
CN111628878A (en) Fault positioning method, device and system based on multi-stage network nodes
CN110955460B (en) Service process starting method and device, electronic equipment and storage medium
CN110677683B (en) Video storage and video access method and distributed storage and video access system
CN109495319B (en) Method, device and equipment for determining fault information of CDN node
US10715608B2 (en) Automatic server cluster discovery
CN114356456A (en) Service processing method, device, storage medium and electronic equipment
CN112291343B (en) Information acquisition method and device and electronic equipment
CN111104376B (en) Resource file query method and device
CN111221847B (en) Monitoring data storage method, device and computer readable storage medium
CN112217852A (en) Platform-as-a-service system and method based on workflow engine
JP6734303B2 (en) Information processing method and device

Legal Events

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