CN114827115A - Access method and device of Web service in container, electronic equipment and storage medium - Google Patents

Access method and device of Web service in container, electronic equipment and storage medium Download PDF

Info

Publication number
CN114827115A
CN114827115A CN202210618567.XA CN202210618567A CN114827115A CN 114827115 A CN114827115 A CN 114827115A CN 202210618567 A CN202210618567 A CN 202210618567A CN 114827115 A CN114827115 A CN 114827115A
Authority
CN
China
Prior art keywords
port
target
container
web service
task
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.)
Pending
Application number
CN202210618567.XA
Other languages
Chinese (zh)
Inventor
余彬
南亚
张晋锋
吕灼恒
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhongke Shuguang International Information Industry Co ltd
Qingdao Zhongke Shuguang Technology Service Co ltd
Original Assignee
Zhongke Shuguang International Information Industry Co ltd
Qingdao Zhongke Shuguang Technology Service 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 Zhongke Shuguang International Information Industry Co ltd, Qingdao Zhongke Shuguang Technology Service Co ltd filed Critical Zhongke Shuguang International Information Industry Co ltd
Priority to CN202210618567.XA priority Critical patent/CN114827115A/en
Publication of CN114827115A publication Critical patent/CN114827115A/en
Pending legal-status Critical Current

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/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • 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
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/146Markers for unambiguous identification of a particular session, e.g. session cookie or URL-encoding
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/148Migration or transfer of sessions

Abstract

The embodiment of the application discloses a method and a device for accessing Web services in a container, electronic equipment and a storage medium. The method comprises the following steps: under the condition that task information of a target task needs to be acquired through a management node, acquiring a target port associated with the target task from an association relation between a pre-stored task and a container open port, wherein the task information is stored in a target container where the target port is located; then acquiring a forwarding port of the management node in an idle state at present, and establishing a link channel between the forwarding port and a target port; and finally, accessing the Web service in the target container based on the link channel so as to acquire the task information of the target task stored in the target container through the Web service. When task information needs to be acquired every time, a link channel is temporarily established between the idle forwarding port and the target port, cyclic utilization can be achieved for the idle forwarding port, and the problem that the management node port is occupied too much is effectively solved.

Description

Access method and device of Web service in container, electronic equipment and storage medium
Technical Field
The embodiment of the application relates to the technical field of container port forwarding, in particular to a method and a device for accessing Web services in a container, electronic equipment and a storage medium.
Background
With the development of container technology, there are many scenarios in which a container provides external Web services, for example, in a supercomputing cluster, a computing node does not open an external network generally, a specified port is opened inside a container of the computing node, the port points to a Web service in the container, and the external can access the Web service in the container through the port opened to the outside by a management node and the port specified in the container of the computing node.
Because the number of containers in the cluster is large, the Web service in each container needs to establish a connection with the port of the management node through the port of the corresponding container, and each Web service needs to independently correspond to one port of the management node, so that how many Web services in the cluster occupy how many ports of the management node.
However, the number of ports of the management node is limited, and when the Web service in the cluster is too much, the management node occupies too many ports, and the problem of insufficient ports of the management node is likely to occur.
Disclosure of Invention
The embodiment of the application provides a method and a device for accessing Web services in a container, electronic equipment and a storage medium, so that excessive occupation of a management node port is avoided.
In a first aspect, an embodiment of the present application provides a method for accessing a Web service in a container, where the method includes:
under the condition that task information of a target task needs to be acquired through a management node, acquiring a target port associated with the target task from a pre-stored association relation between the task and a container open port, wherein the task information is stored in a target container where the target port is located;
acquiring a forwarding port of a management node in an idle state at present, and establishing a link channel between the forwarding port and the target port;
and accessing the Web service in the target container based on the link channel so as to acquire the task information of the target task stored in the target container through the Web service.
Optionally, the obtaining of the forwarding port of the management node currently in the idle state includes:
judging whether a target open port in an idle state exists in the current open ports of the management nodes;
and if the target open port in the idle state exists, taking the target open port as the current forwarding port in the idle state.
According to the technical scheme, the open ports which are opened by the management node at present can be recycled, and the port pressure of the management node is further reduced.
Optionally, the determining whether a target open port in an idle state exists in the current open ports of the management node includes:
acquiring mapping data stored in a Lua shared memory, wherein the mapping data comprises a plurality of mapping relations, and each mapping relation comprises any open port currently opened by a management node and a container port corresponding to the any open port;
and judging whether a target mapping relation with a use state as a first state exists in the mapping data, and determining an open port in the target mapping relation as a target open port in an idle state.
According to the technical scheme, all the currently existing open ports of the management node can be reflected through the mapping data stored in the Lua memory, and whether the open ports can be determined to be the target open ports in the idle state or not is determined through introducing the concept of the use state into the mapping relation in the mapping data.
Optionally, after obtaining the forwarding port of the management node currently in the idle state and before establishing the link channel between the forwarding port and the target port, the method further includes:
deleting the mapping relation containing the forwarding port in the current Lua shared memory;
and mapping the forwarding port and the target port, storing a mapping relation generated by mapping into the Lua shared memory, and setting the generated use state of the mapping relation as a second state.
In the above scheme, the mapping data in the Lua shared memory and the use state of the mapping relation corresponding to the forwarding port are updated, so that the mapping data in the Lua shared memory conforms to the actual link state between the ports, and the required forwarding port is conveniently and accurately determined.
Optionally, the establishing a link channel between the forwarding port and the target port includes:
acquiring a user request resource locator of a management node where the forwarding port is located, and binding the user request resource locator with the generated mapping relation to obtain a binding relation;
splicing the user request resource locator with the target port to obtain a Web service access resource locator;
and determining the Web service access resource locator and the binding relationship as a link channel.
In the above scheme, the web service access resource locator is utilized, so that the access mode becomes more flexible, a user can access the target port through the web service access resource locator, and the management node can determine the forwarding port forwarded to the target port through the binding relationship.
Optionally, the accessing, based on the link channel, the Web service in the target container to obtain, through the Web service, task information of a target task stored in the target container includes:
extracting the user request resource locator from the Web service access resource locator, and determining a mapping relation corresponding to the user request resource locator based on the binding relation;
and accessing the Web service through the forwarding port and the target port in the mapping relation so as to acquire the task information of the target task stored in the target container through the Web service.
In the scheme, the user can access the resource locator and the binding relation through the Web service, correctly forward the resource locator to the target port through the forwarding port and access the corresponding Web service.
Optionally, the obtaining of the forwarding port of the management node currently in the idle state further includes:
and if the target open port in the idle state does not exist, newly building an open port in the management node, and taking the newly built open port as a forwarding port in the idle state at present.
In the above scheme, an open port can be newly established as a forwarding port in an idle state under the condition that a target open port in the idle state does not exist, so that normal access can be ensured.
In a second aspect, an embodiment of the present application further provides an apparatus for accessing a Web service in a container, where the apparatus for accessing a Web service in a container includes:
the system comprises an acquisition module, a processing module and a processing module, wherein the acquisition module is used for acquiring a target port associated with a target task from a pre-stored association relation between the task and a container open port under the condition that task information of the target task needs to be acquired through a management node, and the task information is stored in a target container where the target port is located;
the establishing module is used for acquiring a forwarding port of a management node in an idle state at present and establishing a link channel between the forwarding port and the target port;
and the access module is used for accessing the Web service in the target container based on the link channel so as to acquire the task information of the target task stored in the target container through the Web service.
In a third aspect, an embodiment of the present application further provides an electronic device, where the electronic device includes:
one or more processors;
a storage device for storing one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors implement the method for accessing the Web service in the container as provided in any embodiment of the present application.
In a fourth aspect, this application further provides a computer-readable storage medium, on which a computer program is stored, where the computer program is executed by a processor to implement the method for accessing a Web service in a container as provided in any embodiment of this application.
In the technical scheme of the embodiment of the application, under the condition that task information of a target task needs to be acquired through a management node, a target port associated with the target task is acquired from a pre-stored association relation between the task and a container open port, wherein the task information is stored in a target container where the target port is located; then obtaining a forwarding port of a management node in an idle state at present, and establishing a link channel between the forwarding port and the target port; and finally, accessing the Web service in the target container based on the link channel so as to acquire the task information of the target task stored in the target container through the Web service. Compared with the prior art, the method and the device have the advantages that the mode that the forwarding port and the target port are fixedly corresponding is not adopted any more to ensure that the Web service is accessed through the forwarding port and the target port, but when the task information needs to be obtained every time, the link channel is temporarily established between the idle forwarding port and the target port by using the management node, so that the cyclic utilization can be realized for the idle forwarding port, the condition that the idle forwarding port is forcibly occupied by a certain service is avoided, and the problem that the management node port is occupied too much is effectively avoided.
Drawings
Fig. 1 is a schematic flowchart of an access method for a Web service in a container according to an embodiment of the present application;
FIG. 2 is a block diagram of a computing cluster according to an embodiment of the present application;
fig. 3 is a schematic flowchart of establishing a link channel according to an embodiment of the present application;
FIG. 4 is a schematic diagram of a user interaction interface provided in the first embodiment of the present application;
fig. 5 is a schematic view illustrating an access flow of a Web service in a container according to a second embodiment of the present application;
fig. 6 is a schematic structural diagram of an access apparatus for a Web service in a container according to a third embodiment of the present application;
fig. 7 is a schematic structural diagram of an electronic device according to a fourth embodiment of the present application.
Detailed Description
The present application will be described in further detail with reference to the following drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the application and are not limiting of the application. It should be further noted that, for the convenience of description, only some of the structures associated with the present application are shown in the drawings, not all of them.
Example one
Fig. 1 is a schematic flowchart of a method for accessing a Web service in a container according to an embodiment of the present application, where the present embodiment is applicable to a scenario of accessing a Web service in a container. The method can be executed by an access device of the Web service in the container, the device can be realized by adopting a hardware and/or software mode, and can be generally integrated in an electronic device such as a computer with data operation capability, and the method specifically comprises the following steps:
step 101, under the condition that task information of a target task needs to be acquired through a management node, a target port associated with the target task is acquired from a pre-stored association relation between the task and a container opening port, and the task information is stored in a target container where the target port is located.
It should be noted that the method of this embodiment may be applied to a computing cluster, where the computing cluster is provided with management nodes and computing nodes, and the number of the management nodes and the number of the computing nodes may be set according to the scale of the computing cluster, which is not limited herein.
For better illustration, the architecture of the computing cluster may be described in a specific example, and refer to fig. 2, where fig. 2 is a schematic diagram of the architecture of the computing cluster provided in this embodiment of the present application.
As shown in fig. 2, the computing cluster includes 1 management node and 5 computing nodes, a container is disposed in the computing node a, a Web service is disposed in the container, and external port forwarding may be performed through the management node, so as to access the Web service in the computing node a.
It should be noted that, at least, the target task needs to be executed according to a container set in the computing node a, where task information generated when the target task is executed is stored in the container, and the task information may be an execution progress, an execution result, and the like of the target task.
When the target task is newly created, in order to complete the target task, a container is created in at least one computing node, and the container is used for installing an application program required for completing the target task, and the application program can assist in completing the target task.
In order to implement correct port forwarding, that is, to ensure that an external device correctly obtains task information of the target task, in this embodiment, after a container is newly created, the target task and the port information of the newly created container are mapped and stored, and in a specific example, the mapping may be stored in a database of a computing cluster and stored in a form of a data table.
In addition, the port information may include an IP of the new container and a port corresponding to each service existing in the new container, and in a specific example, if a Web service exists in the new container, the port corresponding to the Web service may be an 8080 port of the new container.
Generally, if an external device wants to access task information stored in a container in a compute node, and a corresponding Web service needs to be installed in the container, a corresponding port is allocated to the Web service when the corresponding Web service is installed. It should be noted that, the Web service may perform installation and port configuration when task information of a target task needs to be acquired through a management node, or may install and configure the Web service in a corresponding container at the time of creating the target task.
Whenever a Web service is installed, the corresponding port identifier is stored in the data table for storing the target task and the container port information after the Web service is installed, and is mapped with the container IP for installing the Web service.
Therefore, in this step, the target port associated with the target task may be acquired from the pre-stored association relationship between the task and the container open port. The association relationship is mapping data stored in the data table, and in order to distinguish between tasks, the task may be identified by using a task identifier, for example, the task identifier of a target task is 1001, and then a target port of the Web service corresponding to the task identifier 1001 may be searched from the data table.
Step 102, obtaining a forwarding port of the management node in an idle state at present, and establishing a link channel between the forwarding port and a target port.
In this step, the management node has a plurality of ports, and the port identifiers of all the ports are stored in the resource pool, it should be noted that all unused unopened ports may be in the resource pool.
The open port of the management node is managed, the open port of the management node can depend on a Nginx + Lua environment built in the management node, the environment is provided with a Lua shared memory, and the Lua shared memory can store the mapping relation between the open port of the management node and the port corresponding to the Web service of the container.
When the forwarding port in the idle state is obtained in this step, it may be determined whether a target open port in the idle state exists in the current open ports of the management node; and if the target open port in the idle state exists, taking the target open port as the current forwarding port in the idle state.
Specifically, mapping data stored in the Lua shared memory may be obtained first, where the mapping data includes a plurality of mapping relationships, and each mapping relationship includes any open port currently opened by the management node and a container port corresponding to any open port; and then judging whether a target mapping relation with the use state as the first state exists in the mapping data, and determining an open port in the target mapping relation as a target open port in an idle state.
In a specific example, the mapping data stored in the Lua shared memory may be as shown in table 1.
TABLE 1
Managing node ports Container IP Container port State of use
Port a1 IP1 Port a2 True
Port b1 IP2 Port b2 False
Port c1 IP3 Port c2 True
Port d1 IP4 Port d2 True
First, it can be determined whether there is a target mapping relationship whose use state is the first state False in table 1, and as can be seen from table 1, the use state of the mapping relationship "port b1-IP 3-port b 2" is False.
Then, the mapping relationship may be determined as a target mapping relationship, and the management node port "port b 1" in the target mapping relationship may be determined as a target open port in an idle state. And finally, setting the target open port as a forwarding interface.
For subsequent access, after the forwarding port is determined, the mapping data in the Lua shared memory may be updated. Specifically, the mapping relationship including the forwarding port in the current Lua shared memory may be deleted first; and then mapping the forwarding port and the target port, storing the mapping relation generated by mapping into the Lua shared memory, and setting the use state of the generated mapping relation as a second state.
Still taking the above table 1 as an example, if the destination port is port e2 of the container IP5, the new mapping relationship is "port b1-IP 5-port e 2", at this time, the mapping relationship "port b1-IP 3-port b 2" may be deleted from table 1, then the mapping relationship "port b1-IP 5-port e 2" is added to table 1, and the use state of the mapping relationship "port b1-IP 5-port e 2" is set to the second state True. The new mapping data formed may be as shown in table 2.
TABLE 2
Managing node ports Container IP Container port State of use
Port a1 IP1 Port a2 True
Port b1 IP5 Port e2 True
Port c1 IP3 Port c2 True
Port d1 IP4 Port d2 True
Of course, in this embodiment, there may also be a case that there is no target open port in an idle state, and if there is no target open port in an idle state, an open port may be newly created in the management node, and the newly created open port may be used as a forwarding port currently in an idle state.
It should be noted that any unused port can be found from the resource pool of the management node as a newly-created open port, where the unused port refers to a port that is not included in the mapping data, and of course, if the used states of a certain mapping relationship in the mapping data are all in the first state (i.e., False) within a certain time period, the mapping relationship can be deleted, and then the port of the management node in the mapping relationship is placed back into the resource pool of the management node.
In addition, after the forwarding interface is determined, a link channel between the forwarding port and the target port can be established, and the user can access the corresponding Web service through the link channel. Specifically, reference may be made to fig. 3, and fig. 3 is a schematic flowchart of establishing a link channel according to an embodiment of the present application.
As shown in fig. 3, the process of establishing the link channel may include:
step 301, obtaining a user request resource locator of a management node where the forwarding port is located, and binding the user request resource locator with the generated mapping relationship to obtain a binding relationship.
In this step, the resource locator requested by the user refers to the URL carrying the user identifier and the management node identifier after the user logs in the management node. Generally, when a request for acquiring task information of a target task is generated according to a user operation, a resource locator requested by the user is generated, and of course, the request may further include a task identifier of the target task and an IP of a corresponding container.
It should be noted that a task may include multiple subtasks, each of which is facilitated by an application in a corresponding container, and when each subtask is completed, the task is considered to be completed.
For the user, if the user wants to obtain the task information of the task, the embodiment may provide an interactive interface for the user to operate. The interactive interface includes subtasks included in the task, a container corresponding to each subtask, and a task information query button of each subtask, which may specifically refer to fig. 4, where fig. 4 is a schematic view of a user interactive interface provided in an embodiment of the present application.
As shown in FIG. 4, the interactive interface displays the related content of task A, such as subtask a, subtask b, and subtask c included in task A; container 1 corresponding to subtask a, container 2 corresponding to subtask b, and container 3 corresponding to subtask c; the query button corresponding to the subtask a, the query button corresponding to the subtask b, and the query button corresponding to the subtask c. Typically, a user may trigger a query for task information for a certain subtask by clicking a query button.
After the user request resource locator is obtained, the user request resource locator and the mapping relation generated in the front can be bound to obtain the binding relation. The binding relationship may facilitate subsequent access to the Web service.
And step 302, splicing the resource locator requested by the user with the target port to obtain the Web service access resource locator.
In this step, the Web service access resource locator may be returned to the interactive interface as a query link of the corresponding query button. And after the user clicks the query button, acquiring corresponding task information according to the query link corresponding to the query button.
In one specific example, a user requesting a resource locator may be "http:// 10.0.35.187: 7090/sothiai/api/contacts-service? "wherein," 10.0.35.187:7090 "refers to the IP address of the management node in the computing cluster.
The target port can be identified by using id "aiforward 452480057772867584", and after the two are spliced, the final Web service access resource locator "http:// 10.0.35.187: 7090/sothiai/api/contacts-serviceid ═ aiforward 452480057772867584" can be obtained.
Step 303, determining the Web service access resource locator and the binding relationship as a link channel.
In this step, the binding relationship and the Web service access resource locator may be used as a link channel for a subsequent user to query and acquire task information through the link channel.
And 103, accessing the Web service in the target container based on the link channel to acquire the task information of the target task stored in the target container through the Web service.
In this step, after the user clicks a certain query button in the interactive interface, the task information is queried according to the query link corresponding to the query button. It should be noted that, in this embodiment, the interactive interface sends the query link to the corresponding management node according to the management node IP in the query link (i.e., the Web service access resource locator), and then the management node extracts the user request resource locator from the Web service access resource locator.
Determining a mapping relation corresponding to the user request resource locator based on the binding relation in the link channel; and finally, accessing the Web service through the forwarding port and the target port in the mapping relation so as to obtain the task information of the target task stored in the target container through the Web service.
In the technical scheme of the embodiment of the application, under the condition that task information of a target task needs to be acquired through a management node, a target port associated with the target task is acquired from an association relation between a pre-stored task and a container opening port, wherein the task information is stored in a target container where the target port is located; then acquiring a forwarding port of the management node in an idle state at present, and establishing a link channel of the forwarding port and a target port; and finally, accessing the Web service in the target container based on the link channel so as to acquire the task information of the target task stored in the target container through the Web service. Compared with the prior art, the method and the device have the advantages that the mode that the forwarding port and the target port are fixedly corresponding is not adopted any more to ensure that the Web service is accessed through the forwarding port and the target port, but when the task information needs to be obtained every time, the link channel is temporarily established between the idle forwarding port and the target port by using the management node, so that the cyclic utilization can be realized for the idle forwarding port, the condition that the idle forwarding port is forcibly occupied by a certain service is avoided, and the problem that the management node port is occupied too much is effectively avoided.
Example two
Fig. 5 is a schematic view of an access flow of a Web service in a container according to a second embodiment of the present application.
As shown in fig. 5, the access process of the Web service in the container provided by this embodiment may include:
step 501, a target port associated with a target task is obtained from a pre-stored association relationship between the task and a container open port.
And 502, acquiring mapping data stored in the Lua shared memory.
Step 503, judging whether a target mapping relation with the use state being the first state exists in the mapping data.
Step 504, if there is a target mapping relationship with the use state being the first state, determining the open port in the target mapping relationship as a target open port in an idle state, and taking the target open port as a forwarding port currently in the idle state.
And 505, deleting the mapping relation containing the forwarding port in the current Lua shared memory.
Step 506, mapping the forwarding port and the target port, and storing the mapping relation generated by mapping into the Lua shared memory.
Since the forwarding port needs to be reused subsequently, and the forwarding port no longer has a mapping relationship with the previous port, in order to ensure that the mapping relationship stored in the Lua shared memory conforms to the fact, step 505 may be executed to delete the currently stored mapping relationship of the forwarding port, and then execute the mapping and storing process in step 506.
And step 507, setting the generated using state of the mapping relation to be a second state.
Since the newly generated mapping relationship needs to be used, the use state of the mapping relationship corresponding to the newly generated mapping relationship needs to be set to the second state, so that when the embodiment is newly executed, the mapping relationship is prevented from being selected as the target mapping relationship.
Step 508, if there is no target mapping relationship whose usage state is the first state, newly creating an open port in the management node, and taking the newly created open port as the forwarding port currently in the idle state.
Step 509, obtaining the user request resource locator of the management node where the forwarding port is located, and binding the user request resource locator with the generated mapping relationship to obtain a binding relationship.
And step 510, splicing the resource locator requested by the user with the target port to obtain the Web service access resource locator.
And step 511, determining the Web service access resource locator and the binding relationship as a link channel.
Step 512, extracting the user request resource locator from the Web service access resource locator, and determining a mapping relation corresponding to the user request resource locator based on the binding relation.
And 513, accessing the Web service through the forwarding port and the target port in the mapping relationship to obtain the task information of the target task stored in the target container through the Web service.
Compared with the prior art, the scheme of the embodiment does not adopt a mode that the forwarding port and the target port are fixedly corresponding to each other to ensure that the Web service is accessed through the forwarding port and the target port, but when the task information needs to be acquired at each time, the link channel is temporarily established between the idle forwarding port and the target port by using the management node, so that the cyclic utilization can be realized for the idle forwarding port, the situation that the idle forwarding port is forcibly occupied by a certain service is avoided, and the problem that the management node port is occupied too much is effectively avoided.
EXAMPLE III
Fig. 6 is a schematic structural diagram of an access apparatus for a Web service in a container according to a third embodiment of the present application. The access device for the Web service in the container provided by the embodiment of the application can execute the access method for the Web service in the container provided by any embodiment of the application, and has corresponding functional modules and beneficial effects of the execution method. The apparatus may be implemented in a software and/or hardware manner, and as shown in fig. 6, the apparatus for accessing a Web service in a container specifically includes: an acquisition module 601, an establishment module 602, and an access module 603.
The system comprises an acquisition module, a processing module and a processing module, wherein the acquisition module is used for acquiring a target port associated with a target task from a pre-stored association relation between the task and a container open port under the condition that task information of the target task needs to be acquired through a management node, and the task information is stored in a target container where the target port is located;
the establishing module is used for acquiring a forwarding port of the management node in an idle state at present and establishing a link channel of the forwarding port and a target port;
and the access module is used for accessing the Web service in the target container based on the link channel so as to obtain the task information of the target task stored in the target container through the Web service.
In the technical scheme of the embodiment of the application, under the condition that task information of a target task needs to be acquired through a management node, a target port associated with the target task is acquired from an association relation between a pre-stored task and a container opening port, wherein the task information is stored in a target container where the target port is located; then acquiring a forwarding port of the management node in an idle state at present, and establishing a link channel of the forwarding port and a target port; and finally, accessing the Web service in the target container based on the link channel so as to acquire the task information of the target task stored in the target container through the Web service. Compared with the prior art, the method and the device have the advantages that the mode that the forwarding port and the target port are fixedly corresponding is not adopted any more to ensure that the Web service is accessed through the forwarding port and the target port, but when the task information needs to be obtained every time, the link channel is temporarily established between the idle forwarding port and the target port by using the management node, so that the cyclic utilization can be realized for the idle forwarding port, the condition that the idle forwarding port is forcibly occupied by a certain service is avoided, and the problem that the management node port is occupied too much is effectively avoided.
Further, the obtaining module includes:
the judging unit is used for judging whether a target open port in an idle state exists in the current open ports of the management nodes;
and the first forwarding port determining unit is used for taking the target open port as the current forwarding port in the idle state if the target open port in the idle state exists.
Further, the judging unit includes:
the obtaining subunit is configured to obtain mapping data stored in the Lua shared memory, where the mapping data includes multiple mapping relationships, and each mapping relationship includes any open port currently opened by the management node and a container port corresponding to any open port;
and the judging subunit is used for judging whether a target mapping relation with a use state as a first state exists in the mapping data or not, and determining an open port in the target mapping relation as a target open port in an idle state.
Further, the apparatus further comprises:
the deleting module is used for deleting the mapping relation containing the forwarding port in the current Lua shared memory;
and the storage module is used for mapping the forwarding port and the target port, storing the mapping relation generated by mapping into the Lua shared memory, and setting the use state of the generated mapping relation as a first state.
Further, the establishing module comprises:
the binding unit is used for acquiring a user request resource locator of a management node where the forwarding port is located, and binding the user request resource locator with the generated mapping relation to obtain a binding relation;
the splicing unit is used for splicing the resource locator requested by the user with the target port to obtain a Web service access resource locator;
and the link channel determining unit is used for determining the Web service access resource locator and the binding relationship as the link channel.
Further, the access module includes:
the extraction unit is used for extracting the user request resource locator from the Web service access resource locator and determining the mapping relation corresponding to the user request resource locator based on the binding relation;
and the access unit is used for accessing the Web service through the forwarding port and the target port in the mapping relation so as to acquire the task information of the target task stored in the target container through the Web service.
Further, the establishing module further comprises:
and the second forwarding port determining unit is used for newly building an open port in the management node if the target open port in the idle state does not exist, and taking the newly built open port as the forwarding port in the idle state currently.
Example four
Fig. 7 is a schematic structural diagram of an electronic device according to a fourth embodiment of the present disclosure, as shown in fig. 7, the electronic device includes a processor 710, a memory 720, an input device 730, and an output device 740; the number of the processors 710 in the electronic device may be one or more, and one processor 710 is taken as an example in fig. 7; the processor 710, the memory 720, the input device 730, and the output device 740 in the electronic apparatus may be connected by a bus or other means, and the connection by the bus is exemplified in fig. 7.
The memory 720 is used as a computer-readable storage medium for storing software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the method for accessing the Web service in the container in the embodiment of the present invention (for example, the obtaining module 601, the establishing module 602, and the accessing module 603 in the accessing apparatus for the Web service in the container). The processor 710 executes various functional applications and data processing of the electronic device by executing software programs, instructions and modules stored in the memory 720, that is, implements the above-described access method of the Web service in the container:
under the condition that task information of a target task needs to be acquired through a management node, acquiring a target port associated with the target task from an association relation between a pre-stored task and a container open port, wherein the task information is stored in a target container where the target port is located;
acquiring a forwarding port of a management node in an idle state at present, and establishing a link channel of the forwarding port and a target port;
and accessing the Web service in the target container based on the link channel so as to acquire the task information of the target task stored in the target container through the Web service.
The memory 720 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application program required for at least one function; the storage data area may store data created according to the use of the terminal, and the like. Further, the memory 720 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some examples, the memory 720 may further include memory located remotely from the processor 710, which may be connected to an electronic device through a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
EXAMPLE five
A fifth embodiment of the present application further provides a storage medium containing computer-executable instructions, which when executed by a computer processor, perform a method for accessing a Web service in a container, the method including:
under the condition that task information of a target task needs to be acquired through a management node, acquiring a target port associated with the target task from an association relation between a pre-stored task and a container open port, wherein the task information is stored in a target container where the target port is located;
acquiring a forwarding port of a management node in an idle state at present, and establishing a link channel of the forwarding port and a target port;
and accessing the Web service in the target container based on the link channel so as to acquire the task information of the target task stored in the target container through the Web service.
Of course, the storage medium provided in the embodiments of the present application contains computer-executable instructions, and the computer-executable instructions are not limited to the above method operations, and may also perform related operations in the access method for Web services in a container provided in any embodiment of the present application.
From the above description of the embodiments, it is obvious for those skilled in the art that the present application can be implemented by software and necessary general hardware, and certainly can be implemented by hardware, but the former is a better embodiment in many cases. Based on such understanding, the technical solutions of the present application may be embodied in the form of a software product, which may be stored in a computer-readable storage medium, such as a floppy disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a FLASH Memory (FLASH), a hard disk or an optical disk of a computer, and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device) to execute the methods of the embodiments of the present application.
It should be noted that, in the embodiment of the above search apparatus, each included unit and module are merely divided according to functional logic, but are not limited to the above division as long as the corresponding functions can be implemented; in addition, specific names of the functional units are only used for distinguishing one functional unit from another, and are not used for limiting the protection scope of the application.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present application and the technical principles employed. It will be understood by those skilled in the art that the present application is not limited to the particular embodiments illustrated herein, and that various obvious changes, rearrangements and substitutions may be made therein by those skilled in the art without departing from the scope of the application. Therefore, although the present application has been described in more detail with reference to the above embodiments, the present application is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present application, and the scope of the present application is determined by the scope of the appended claims.

Claims (10)

1. A method for accessing a Web service in a container, the method comprising:
under the condition that task information of a target task needs to be acquired through a management node, acquiring a target port associated with the target task from a pre-stored association relation between the task and a container open port, wherein the task information is stored in a target container where the target port is located;
acquiring a forwarding port of a management node in an idle state at present, and establishing a link channel between the forwarding port and the target port;
and accessing the Web service in the target container based on the link channel so as to acquire the task information of the target task stored in the target container through the Web service.
2. The method of claim 1, wherein obtaining the forwarding port of which the management node is currently in an idle state comprises:
judging whether a target open port in an idle state exists in the current open ports of the management nodes;
and if the target open port in the idle state exists, taking the target open port as the current forwarding port in the idle state.
3. The method according to claim 2, wherein the determining whether there is a target open port in an idle state in the current open ports of the management node comprises:
acquiring mapping data stored in a Lua shared memory, wherein the mapping data comprises a plurality of mapping relations, and each mapping relation comprises any open port currently opened by a management node and a container port corresponding to the any open port;
and judging whether a target mapping relation with a use state as a first state exists in the mapping data, and determining an open port in the target mapping relation as a target open port in an idle state.
4. The method of claim 3, wherein after obtaining the forwarding port of which the management node is currently in an idle state and before the establishing the link channel between the forwarding port and the target port, the method further comprises:
deleting the mapping relation containing the forwarding port in the current Lua shared memory;
and mapping the forwarding port and the target port, storing a mapping relation generated by mapping into the Lua shared memory, and setting the generated use state of the mapping relation as a second state.
5. The method of claim 4, wherein establishing the link channel between the forwarding port and the destination port comprises:
acquiring a user request resource locator of a management node where the forwarding port is located, and binding the user request resource locator with the generated mapping relation to obtain a binding relation;
splicing the user request resource locator with the target port to obtain a Web service access resource locator;
and determining the Web service access resource locator and the binding relationship as a link channel.
6. The method of claim 5, wherein the accessing the Web service in the target container based on the link channel to obtain task information of the target task stored in the target container through the Web service comprises:
extracting the user request resource locator from the Web service access resource locator, and determining a mapping relation corresponding to the user request resource locator based on the binding relation;
and accessing the Web service through the forwarding port and the target port in the mapping relation so as to acquire the task information of the target task stored in the target container through the Web service.
7. The method of claim 2, wherein the obtaining of the forwarding port of which the management node is currently in an idle state further comprises:
and if the target open port in the idle state does not exist, newly building an open port in the management node, and taking the newly built open port as a forwarding port in the idle state at present.
8. An apparatus for accessing Web services in a container, the apparatus comprising:
the system comprises an acquisition module, a processing module and a processing module, wherein the acquisition module is used for acquiring a target port associated with a target task from a pre-stored association relation between the task and a container open port under the condition that task information of the target task needs to be acquired through a management node, and the task information is stored in a target container where the target port is located;
the establishing module is used for acquiring a forwarding port of a management node in an idle state at present and establishing a link channel between the forwarding port and the target port;
and the access module is used for accessing the Web service in the target container based on the link channel so as to acquire the task information of the target task stored in the target container through the Web service.
9. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement a method for accessing Web services in a container as recited in any of claims 1-7.
10. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out a method for accessing a Web service in a container according to any one of claims 1 to 7.
CN202210618567.XA 2022-06-01 2022-06-01 Access method and device of Web service in container, electronic equipment and storage medium Pending CN114827115A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210618567.XA CN114827115A (en) 2022-06-01 2022-06-01 Access method and device of Web service in container, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210618567.XA CN114827115A (en) 2022-06-01 2022-06-01 Access method and device of Web service in container, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114827115A true CN114827115A (en) 2022-07-29

Family

ID=82518502

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210618567.XA Pending CN114827115A (en) 2022-06-01 2022-06-01 Access method and device of Web service in container, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114827115A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116389172A (en) * 2023-06-05 2023-07-04 国网四川省电力公司信息通信公司 Multi-tenant-based container cloud platform resource security management method

Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103747020A (en) * 2014-02-18 2014-04-23 成都致云科技有限公司 Safety controllable method for accessing virtual resources by public network
US20150074186A1 (en) * 2010-03-22 2015-03-12 Tso-Sung HUNG Server system connection process method preventing network congestion
US20160205518A1 (en) * 2015-01-14 2016-07-14 Kodiak Networks Inc. System and Method for Elastic Scaling using a Container-Based Platform
US20190306231A1 (en) * 2018-03-29 2019-10-03 Hewlett Packard Enterprise Development Lp Container cluster management
CN110427249A (en) * 2019-07-26 2019-11-08 重庆紫光华山智安科技有限公司 Method for allocating tasks, pod initial method and relevant apparatus
US20200137185A1 (en) * 2018-10-24 2020-04-30 Hewlett Packard Enterprise Development Lp Remote service access in a container management system
CN111726399A (en) * 2020-06-08 2020-09-29 中国工商银行股份有限公司 Docker container secure access method and device
CN111966442A (en) * 2019-05-20 2020-11-20 北京白山耘科技有限公司 Method, apparatus, medium, and device for container port management
CN112511611A (en) * 2020-11-19 2021-03-16 腾讯科技(深圳)有限公司 Communication method, device and system of node cluster and electronic equipment
CN112532666A (en) * 2019-09-18 2021-03-19 北京国双科技有限公司 Reverse proxy method, apparatus, storage medium, and device
CN113098868A (en) * 2021-04-01 2021-07-09 广州巨时信息科技股份有限公司 Container-based network security processing method and device
CN114374696A (en) * 2021-12-15 2022-04-19 深圳前海微众银行股份有限公司 Container load balancing method, device, equipment and storage medium

Patent Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150074186A1 (en) * 2010-03-22 2015-03-12 Tso-Sung HUNG Server system connection process method preventing network congestion
CN103747020A (en) * 2014-02-18 2014-04-23 成都致云科技有限公司 Safety controllable method for accessing virtual resources by public network
US20160205518A1 (en) * 2015-01-14 2016-07-14 Kodiak Networks Inc. System and Method for Elastic Scaling using a Container-Based Platform
US20190306231A1 (en) * 2018-03-29 2019-10-03 Hewlett Packard Enterprise Development Lp Container cluster management
US20200137185A1 (en) * 2018-10-24 2020-04-30 Hewlett Packard Enterprise Development Lp Remote service access in a container management system
CN111966442A (en) * 2019-05-20 2020-11-20 北京白山耘科技有限公司 Method, apparatus, medium, and device for container port management
CN110427249A (en) * 2019-07-26 2019-11-08 重庆紫光华山智安科技有限公司 Method for allocating tasks, pod initial method and relevant apparatus
CN112532666A (en) * 2019-09-18 2021-03-19 北京国双科技有限公司 Reverse proxy method, apparatus, storage medium, and device
CN111726399A (en) * 2020-06-08 2020-09-29 中国工商银行股份有限公司 Docker container secure access method and device
CN112511611A (en) * 2020-11-19 2021-03-16 腾讯科技(深圳)有限公司 Communication method, device and system of node cluster and electronic equipment
CN113098868A (en) * 2021-04-01 2021-07-09 广州巨时信息科技股份有限公司 Container-based network security processing method and device
CN114374696A (en) * 2021-12-15 2022-04-19 深圳前海微众银行股份有限公司 Container load balancing method, device, equipment and storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116389172A (en) * 2023-06-05 2023-07-04 国网四川省电力公司信息通信公司 Multi-tenant-based container cloud platform resource security management method
CN116389172B (en) * 2023-06-05 2023-09-19 国网四川省电力公司信息通信公司 Multi-tenant-based container cloud platform resource security management method

Similar Documents

Publication Publication Date Title
CN109194617A (en) The automatically parsing of XML message, packaging method and device
CN110213391B (en) Method and device for configuring network protocol address
CN110717076A (en) Node management method, node management device, computer equipment and storage medium
CN111258565A (en) Method, system, server and storage medium for generating small program
CN114172966A (en) Service calling method and device and service processing method and device under unitized architecture
CN114116065A (en) Method and device for acquiring topological graph data object and electronic equipment
CN113961332A (en) Method and device for realizing workflow engine, electronic equipment and storage medium
CN114827115A (en) Access method and device of Web service in container, electronic equipment and storage medium
CN111865978B (en) Method, device, equipment and medium for updating request identifier of micro-service
CN111447273B (en) Cloud processing system and data processing method based on cloud processing system
CN112291212B (en) Static rule management method and device, electronic equipment and storage medium
CN115665231A (en) Service creation method, device and computer-readable storage medium
CN114979286A (en) Access control method, device and equipment for container service and computer storage medium
CN111752728B (en) Message transmission method and device
CN114219643A (en) Transaction calling method, device, equipment and storage medium
CN110928672B (en) Task arranging method, device and equipment and storage medium
CN113625998A (en) Request processing method and device
CN111669358B (en) Method and device for processing vrouter network isolation spaces in batch
CN109618016B (en) DNS request sending and processing method, related method and related device
CN109460296B (en) Resource allocation method and device of processor and storage medium
US10678562B2 (en) Systems and methods for facilitating real-time analytics
CN112860398A (en) Data processing method, device, equipment and medium based on rule engine
US20240028346A1 (en) Linking kubernetes resources with underlying cloud infrastructure
CN111124923B (en) Running state query method and device, server equipment and storage medium
CN111475226B (en) Electronic device, micro-service calling method, and computer-readable storage medium

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