CN111966442A - Method, apparatus, medium, and device for container port management - Google Patents

Method, apparatus, medium, and device for container port management Download PDF

Info

Publication number
CN111966442A
CN111966442A CN201910417332.2A CN201910417332A CN111966442A CN 111966442 A CN111966442 A CN 111966442A CN 201910417332 A CN201910417332 A CN 201910417332A CN 111966442 A CN111966442 A CN 111966442A
Authority
CN
China
Prior art keywords
port
container
identifier
linked list
allocation
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
CN201910417332.2A
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.)
Beijing Baishanyun Technology Co ltd
Original Assignee
Beijing Baishanyun 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 Baishanyun Technology Co ltd filed Critical Beijing Baishanyun Technology Co ltd
Priority to CN201910417332.2A priority Critical patent/CN111966442A/en
Publication of CN111966442A publication Critical patent/CN111966442A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45579I/O management, e.g. providing access to device drivers or storage

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Small-Scale Networks (AREA)

Abstract

The invention discloses a container port management method, which comprises the steps of obtaining a port allocation request of a container, wherein the port allocation request carries allocation request parameters; selecting a port with an idle state according to the allocation request parameters, and allocating the selected port to the container; marking a status of the selected port as used; the ports are divided into different port sets according to the container types, the ports are allocated to the containers according to the container types, the mapping relation between the container identifications and the selected ports are stored in different data structures, when the ports are allocated to the containers, the idle ports can be quickly and accurately found, the ports are conveniently and quickly managed, and port conflicts when the ports are allocated to the containers are avoided.

Description

Method, apparatus, medium, and device for container port management
Technical Field
The present invention relates to the field of computers, and more particularly to the management of computer ports.
Background
When a container is used, the access mode of the bridge of the existing container needs to map the ip of the container to a port corresponding to a host to allow an external network to access. In the prior art, a port mapped by a container ip needs to be specified by a user when the container is created, after the user creates a plurality of containers, the user does not know which ports in a host are mapped by the container ip, and when a mapping port is specified for a newly-created container, if the specified port is occupied, port collision is easily caused.
Disclosure of Invention
In order to solve the above technical problem, the present invention provides a method for managing a container port, including:
acquiring a port allocation request of a container, wherein the port allocation request carries allocation request parameters; selecting a port with an idle state according to the allocation request parameters, and allocating the selected port to the container; marking the status of the selected port as used;
the allocation request parameters include container type and/or pre-allocation port; selecting a port with an idle state according to the allocation request parameter comprises one of the following modes:
when the allocation request parameter comprises a container type, selecting a port with an idle state in a preset port set corresponding to the container type according to the container type;
when the allocation request parameter comprises a pre-allocation port, if the state of the pre-allocation port is idle, selecting the pre-allocation port; if the pre-allocated port is in a used state, selecting a port in an idle state from all ports;
when the allocation request parameters comprise the container type and the pre-allocation port, if the state of the pre-allocation port is idle, the pre-allocation port is selected; if the pre-allocated port state is used, a port with a state of idle is selected from a predetermined port set corresponding to the container type according to the container type.
The method further comprises the following steps:
determining a mapping relationship between an identity of a container and an identity of the selected port;
storing the mapping relationship between the container identification and the selected port identification in a preset data structure.
Storing the mapping relationship between the identifier of the container and the identifier of the selected port in a preset data structure comprises: the preset data structure comprises a tree structure and a linked list structure; storing the mapping relationship between the identifier of the container and the identifier of the selected port in a tree structure, and storing the identifier of the selected port in a linked list structure.
The linked list structure comprises more than one linked list, and different linked lists correspond to different container types; storing the identity of the selected port in a linked list structure includes: the container type of the container is determined, and the identity of the selected port is stored in a linked list corresponding to the container type of the container.
The method further comprises the following steps:
receiving a container destruction notification, wherein the container destruction notification comprises an identifier of a container;
searching a node where the identifier of the container is located in the tree structure, and determining the identifier of the port corresponding to the identifier of the container and the type of the container according to the node;
deleting the node where the identifier of the container in the tree structure is located;
determining a linked list corresponding to the container type, and deleting a node where the identifier of the port is located from the linked list;
the state of the port is marked as idle.
The method further comprises the following steps:
scanning the tree structure, and traversing the identifiers of the containers in the tree structure;
querying whether an identification of each container exists in the container engine;
if the identifier of a certain container does not exist in the container engine, determining that a port indicated by a node where the identifier of the container is located is a garbage port;
deleting the node where the identifier of the container in the tree structure is located;
determining a linked list corresponding to the container type of the container, and deleting a node where the identifier of the garbage port in the linked list is located; the status of the garbage port is marked as idle.
And setting single-thread access limit on the tree structure and the linked list structure during adding, deleting, inquiring and traversing operation of the tree structure and/or the linked list structure, and removing the single-thread access limit on the tree structure and the linked list structure after the operation is finished.
The present invention also provides a container port management apparatus, comprising:
a receiving module: a port allocation request for receiving a container;
a port selection module: based on the distribution request parameters carried by the port distribution request, selecting a port with an idle state, and distributing the selected port to the container;
a port state marking module: marking the status of the selected port as used;
the allocation request parameters include container type and/or pre-allocation port;
selecting a port with an idle state according to the allocation request parameter comprises one of the following modes:
when the allocation request parameter comprises a container type, selecting a port with an idle state in a preset port set corresponding to the container type according to the container type;
when the allocation request parameter comprises a pre-allocation port, if the state of the pre-allocation port is idle, selecting the pre-allocation port; if the pre-allocated port is in a used state, selecting a port in an idle state from all ports;
when the request information comprises a container type and a pre-allocation port, if the state of the pre-allocation port is idle, selecting the pre-allocation port; if the pre-allocated port state is used, a port with a state of idle is selected from a predetermined port set corresponding to the container type according to the container type.
The device also includes:
a mapping relationship establishing module: determining a mapping relationship between the identifier of the container and the identifier of the selected port;
a storage module: storing the mapping relationship between the container identification and the selected port identification in a preset data structure.
Storing the mapping relationship between the identifier of the container and the identifier of the selected port in a preset data structure comprises:
the preset data structure comprises a tree structure and a linked list structure; storing the mapping relationship between the identifier of the container and the identifier of the selected port in a tree structure, and storing the identifier of the selected port in a linked list structure.
The linked list structure comprises more than one linked list, and different linked lists correspond to different container types;
storing the identity of the selected port in a linked list structure includes: the container type of the container is determined, and the identity of the selected port is stored in a linked list corresponding to the container type of the container.
The device also includes:
the receiving module is also used for receiving a container destruction notice, and the container destruction notice comprises the identifier of the container;
a scanning module: searching a node where the identifier of the container is located in the tree structure, and determining the identifier of the port corresponding to the identifier of the container and the type of the container according to the node;
a storage module: deleting the node where the identifier of the container in the tree structure is located;
determining a linked list corresponding to the container type, and deleting a node where the identifier of the port is located from the linked list;
the port state marking module marks the state of the port as idle.
The device also includes:
a scanning module: scanning the tree structure, and traversing the identifiers of the containers in the tree structure;
the query module: querying whether an identification of each container exists in the container engine;
if the identifier of a certain container does not exist in the container engine, determining that a port indicated by a node where the identifier of the container is located is a garbage port;
deleting the node where the identifier of the container in the tree structure is located;
determining a linked list corresponding to the container type of the container, and deleting a node where the identifier of the garbage port in the linked list is located;
the status of the garbage port is marked as idle.
And setting single-thread access limit on the tree structure and the linked list structure during adding, deleting, inquiring and traversing operation of the tree structure and/or the linked list structure, and removing the single-thread access limit on the tree structure and the linked list structure after the operation is finished.
A computer readable medium having computer readable instructions stored thereon which are executable by a processor to implement the above method.
A computer device comprising a processor, a memory and a computer program stored on the memory, characterized in that the steps of the above-mentioned method are implemented when the processor executes the computer program.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate an embodiment of the invention and, together with the description, serve to explain the invention and not to limit the invention. In the drawings:
FIG. 1 is a flow chart of a method of container port management;
FIG. 2 is a schematic diagram of a binary tree;
FIG. 3 is a linked list structure diagram;
fig. 4 is a structural diagram of the container port management apparatus.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, 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 some, but not all, embodiments of the present invention. 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. It should be noted that the embodiments and features of the embodiments in the present application may be arbitrarily combined with each other without conflict.
As shown in fig. 1, the container port management method includes:
step 101, acquiring a port allocation request of a container, wherein the port allocation request carries allocation request parameters; receiving a port allocation request for a container, wherein the port allocation request includes a container identifier, the container identifier is generally a container id, and may also include the number of ports for which allocation is applied, for example, if some containers need to map multiple ports, the number of ports for which allocation is applied is carried in a port allocation request parameter, and a system allocates ports for the containers according to the number of ports in the port allocation application parameter;
102, selecting a port with an idle state according to the allocation request parameters, and allocating the selected port to a container; specifically, in the initial stage of system operation, all available ports may be initialized, and the states of all ports are marked as idle;
step 103, the state of the selected port is marked as used. After available ports are selected for the containers, the selected ports are allocated to the containers, and the states of the selected ports are marked as used states, so that the ports are prevented from being selected and allocated to other containers again to cause port collision.
The container port allocation request parameter may include a container type and/or a pre-allocation port, where the container type is a classification of the container according to the effect of the container, such as a load balancing class container and a web class container, although the container type may also be empty in this embodiment; in a specific implementation, the container ports may be planned in advance, a port of a certain number of segments is used as a port set, assignable ports are divided into a plurality of port sets containing different number of segments, and ports are assigned to containers in a designated port set according to types of the containers. For example, the available ports are divided into [ 3000-; if the container type is empty in the container port application, a port is allocated among all available ports. The above-mentioned manner of allocating ports may be designated or randomly selected.
The container port allocation request parameters further include a pre-allocation port, that is, when the container is established, in the port allocation request for applying for a port for the container, one or more ports are preferentially assigned to the container and included in the container port allocation request parameters.
Selecting a port with an idle state according to the allocation request parameter comprises one of the following modes:
when the allocation request parameter comprises a container type, selecting a port with an idle state in a preset port set corresponding to the container type according to the container type; if the allocation request parameter only contains the container type, the system will select a port with an idle state from the port set corresponding to the container type to allocate to the container according to the container type, for example, the container type web type, and then select a port with an idle state from the [6000- > 7000] port set to allocate to the container;
when the allocation request parameter comprises a pre-allocation port, if the state of the pre-allocation port is idle, selecting the pre-allocation port; if the pre-allocated port is in a used state, selecting a port in an idle state from all ports; if the allocation request parameter only includes a pre-allocated port, such as an 80 port, the system will first query the status of the 80 port, if the 80 port status is idle, the 80 port will be allocated to the container, if the 80 port status is used, it indicates that the port has been allocated to other containers, the system will query all ports for the port with idle status, and randomly select the port to be allocated to the container.
When the allocation request parameters comprise the container type and the pre-allocation port, if the state of the pre-allocation port is idle, the pre-allocation port is selected; if the pre-allocated port state is used, a port with a state of idle is selected from a predetermined port set corresponding to the container type according to the container type. If the allocation request parameter comprises a container type and a pre-allocated port, for example, the container type is a web type, and the pre-allocated port is an 8001 port, the system firstly queries whether the 8001 port state is idle, if the 8001 port state is idle, allocates the 8001 port to the container, and if the 8001 port state is used, selects a port with an idle state to allocate to the container in a [ 6000-plus-7000 ] port set according to the fact that the container type is the web type; the pre-allocated port may also be included in the port set corresponding to the port type.
The container port management method, after allocating ports to the container, further includes:
step 104, determining the mapping relation between the identifier of the container and the identifier of the selected port; storing the mapping relationship between the container identification and the selected port identification in a preset data structure. The identifier of the container is generally a container id, which is the unique identifier of the container, the identifier of the port and the port number; after allocating a port to a container, recording the relationship between the container id and the selected port number, and storing the mapping relationship between the container id and the selected port in a preset data structure, which may be any form of data structure, and is not limited herein.
Storing the mapping relationship between the identifier of the container and the identifier of the selected port in a preset data structure comprises: the preset data structure comprises a tree structure and a linked list structure; storing the mapping relationship between the identifier of the container and the identifier of the selected port in a tree structure, and storing the identifier of the selected port in a linked list structure. According to a feature of the present invention, the mapping between the identity of the container and the identity of the selected port is stored in a tree structure, for example, in this embodiment, a binary tree data structure is used, the binary tree being shown in fig. 2. The binary tree data structure is convenient for the system to query according to the container id, and the query speed is improved; in the binary tree, 201 is a first node of the binary tree, 202 is a second node, 203 is a third node, and so on; and each node of the binary tree corresponds to the identifier of one container, wherein the identifier comprises key and value, the key is a container id, the value is the container type of the container and the identifier of the port mapped by the container, and when the existing container id and the port mapped by the existing container id need to be listed, the result can be quickly obtained through traversal of the binary tree. Nodes in the binary tree are arranged according to the container id, and when the nodes are added or deleted, the binary tree is maintained by itself without human participation.
Storing the identifier of the selected port in a linked list structure, the linked list structure being as shown in fig. 3, the linked list structure 30 comprising more than one linked list, different linked lists corresponding to different container types; for example, in the illustration, the linked list structure 30 includes 3 linked lists, which are respectively the linked list 301, the linked list 302, and the linked list 303, according to the container type, and respectively correspond to different container types, for example, the linked list 301 corresponds to a load balancing type container, the linked list 302 corresponds to a web type container, and the linked list 303 corresponds to other types of containers. Each node in the linked list corresponds to a port identifier of the type, for example, the linked list 301 corresponds to a load balancing type container, the set of ports corresponding to the type container is [ 3000-. The linked list 302 corresponds to a web class container, the port set corresponding to the container type is [ 6000-.
Storing the identity of the selected port in a linked list structure includes: the container type of the container is determined, and the identity of the selected port is stored in a linked list corresponding to the container type of the container. For example, a web type container is newly created, the system allocates a port in the [6000- > 7000] port set according to the type of the container, after the mapping relationship is established, when the port number mapped by the container is stored in the linked list structure, the linked list corresponding to the container type is found according to the container type, and if the linked list 302 in fig. 3 corresponds to the web type container, the port number mapped by the container is stored in the linked list. The used port is listed in the linked list structure, the linked list data structure is convenient for inquiring the used port, if a certain port state is inquired, only the port is required to be inquired whether in the used port linked list, the port is explained as the used port, and in the no longer used port linked list, the port is explained as the idle port; and simultaneously, the adding and deleting operations of the used ports are convenient, and each node in the linked list is one used port number. In the method, the selected port is stored in the linked list data structure corresponding to the container type according to the container type, when the port state is inquired, the traversal of all the linked list data structures is not needed, only the inquiry is carried out in the linked list structure corresponding to the container type aiming at the container type, when the system has more containers and the number of the used ports is large, the inquiry speed can be increased in multiples, the time is saved, and the system overhead is reduced.
The method further comprises the following steps:
receiving a container destruction notification, wherein the container destruction notification comprises a container identifier;
searching a node where the identifier of the container is located in the tree structure, and determining the identifier of the port corresponding to the identifier of the container and the type of the container according to the node;
deleting the node where the identifier of the container in the tree structure is located;
determining a linked list structure corresponding to the container type, and deleting a node where the port identifier is located from the linked list structure;
the state of the port is marked as idle.
The container may not be used for any reason during the use process, and needs to be destroyed, and after the container is destroyed, the port occupied by the container needs to be released in time so as to distribute the port for other containers. When the container is destroyed, a container destruction notice is sent, after the system receives the container destruction notice, the system firstly queries in a binary tree according to the container id to find a node corresponding to the container id, determines a port number corresponding to the container id and the type of the container, then deletes the node corresponding to the container id in the binary tree, simultaneously finds a linked list corresponding to the type of the container according to the type of the container, and deletes the node corresponding to the port identifier corresponding to the container in the linked list.
The method further comprises the following steps:
scanning the tree structure, and traversing the identifiers of the containers in the tree structure;
querying whether an identification of each container exists in the container engine;
if the identifier of a certain container does not exist in the container engine, determining that a port indicated by a node where the identifier of the container is located is a garbage port;
deleting the node where the identifier of the container in the tree structure is located;
determining a linked list corresponding to the container type of the container, and deleting a node where the identifier of the garbage port in the linked list is located;
the status of the garbage port is marked as idle.
When the container is deleted, a notification is sent to the system to prompt that the container is deleted and the port occupied by the container needs to be released, but in the process of deleting the node corresponding to the container id in the binary tree and the node corresponding to the port number corresponding to the container id in the linked list structure, an interrupt occurs, such as a server is down or is powered off and restarted, so that the operation on the binary tree and the linked list structure is not completed, the node corresponding to the container id and the node in the linked list structure corresponding to the port identifier corresponding to the container id are not deleted in the data structure, so that the port is marked as a used state, and a junk port appears without actually having a mapping relationship with any container. The method comprises the steps of scanning a binary tree, traversing container ids stored in the binary tree, inquiring whether each container id exists in a container engine, if so, indicating that the container is in use, and if not, indicating that the container is deleted, wherein a port corresponding to the container id is a junk port, so that a node corresponding to the container id is deleted in the binary tree, meanwhile, a port corresponding to the container id is deleted in a linked list structure, and the port is marked to be in an idle state and can be mapped by other containers. In order to find the garbage ports in the system more timely and improve the use efficiency of the ports, the binary tree can be periodically scanned, and the garbage ports can be released timely.
In any of the above embodiments, during operations of adding, deleting, querying, and traversing the tree structure and/or the linked list structure, single-thread access restriction is set for the tree structure and the linked list structure, and the single-thread access restriction is removed from the tree structure and the linked list structure after the operations are completed. In the specific implementation, while operating the tree structure or the linked list structure, single thread access restriction is set for the tree structure and the linked list structure, for example, a code lock is added for the tree structure and the linked list structure, which aims to protect the binary tree or the linked list structure and ensure the consistency of the operations of the tree structure and the linked list structure.
Through the above embodiments, it can be seen that, the method divides ports into different port sets according to container types, allocates ports to containers according to container types, and stores the mapping relationship between the container id and the selected port, and the selected port in different data structures, when allocating ports to containers, can quickly and accurately find out the idle port, realizes convenient and quick management of ports, avoids port collision when allocating ports to containers, meanwhile, when destroying containers, searches the container id in a binary tree data structure, through the corresponding node of the container id, can quickly determine the type of the container and the mapped port, and then timely releases the port which is not used any more in the linked list corresponding to the container type, even if the port is down or powered off in the process of releasing, causing interruption of port releasing operation, when a garbage port appears, the system can also find the garbage port in time by traversing the id of the established container in the binary tree and inquiring whether the container id exists in the container engine or not, and release the garbage port, so that the use efficiency of the port is improved.
As shown in fig. 4, a container port management apparatus includes:
a receiving module: for receiving a container port allocation request;
a port selection module: based on the distribution request parameters carried by the container port distribution request, selecting a port with an idle state, and distributing the selected port to the container;
a port state marking module: the status of the selected port is marked as used.
The allocation request parameters include container type and/or pre-allocation port;
selecting a port with an idle state according to the allocation request parameter comprises one of the following modes:
when the allocation request parameter comprises a container type, selecting a port with an idle state in a preset port set corresponding to the container type according to the container type;
when the allocation request parameter comprises a pre-allocation port, if the state of the pre-allocation port is idle, selecting the pre-allocation port; if the pre-allocated port is in a used state, selecting a port in an idle state from all ports;
when the request information comprises a container type and a pre-allocation port, if the state of the pre-allocation port is idle, selecting the pre-allocation port; if the pre-allocated port state is used, a port with a state of idle is selected from a predetermined port set corresponding to the container type according to the container type.
The container port management apparatus further includes:
a mapping relationship establishing module: determining a mapping relationship between the identifier of the container and the identifier of the selected port;
a storage module: storing the mapping relationship between the container identification and the selected port identification in a preset data structure.
Storing the mapping relationship between the identifier of the container and the identifier of the selected port in a preset data structure comprises:
the preset data structure comprises a tree structure and a linked list structure; storing the mapping relationship between the identifier of the container and the identifier of the selected port in a tree structure, and storing the identifier of the selected port in a linked list structure.
The linked list structure comprises more than one linked list, and different linked lists correspond to different container types;
storing the identity of the selected port in a linked list structure includes: the container type of the container is determined, and the identity of the selected port is stored in a linked list corresponding to the container type of the container.
The container port management apparatus further includes:
a receiving module: the system is also used for receiving a container destruction notice, wherein the container destruction notice comprises the identifier of the container;
a scanning module: searching a node where the identifier of the container is located in the tree structure, and determining the identifier of the port corresponding to the identifier of the container and the type of the container according to the node;
the storage module deletes the node where the identifier of the container in the tree structure is located;
determining a linked list corresponding to the container type, and deleting a node where the identifier of the port is located from the linked list;
the port state marking module marks the state of the port as idle.
The container port management apparatus further includes:
a scanning module: scanning the tree structure, and traversing the identifiers of the containers in the tree structure;
the query module: querying whether an identification of each container exists in the container engine;
if the identifier of a container does not exist in the container engine, determining that a port indicated by a node where the identifier of the container is located is a garbage port;
deleting the node where the identifier of the container in the tree structure is located;
determining a linked list corresponding to the container type of the container, and deleting a node where the identifier of the garbage port in the linked list is located;
the status of the garbage port is marked as idle.
And setting single-thread access limit on the tree structure and the linked list structure during adding, deleting, inquiring and traversing operation of the tree structure and/or the linked list structure, and removing the single-thread access limit on the tree structure and the linked list structure after the operation is finished.
A computer readable medium having computer readable instructions stored thereon which are executable by a processor to implement the above method.
A computer device comprising a processor, a memory and a computer program stored on the memory, the steps of the above method being performed when the computer program is executed by the processor.
The above-described aspects may be implemented individually or in various combinations, and such variations are within the scope of the present invention.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, apparatus (device), or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media having computer-usable program code embodied in the medium. Computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data, including, but not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, Digital Versatile Disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can be accessed by the computer, and the like. In addition, communication media typically embodies computer readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transport mechanism and includes any information delivery media as known to those skilled in the art.
The present invention has been described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (devices) and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks. These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks. In this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that an 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 article or apparatus. Without further limitation, an element defined by the phrase "comprising … …" does not exclude the presence of additional like elements in the article or device comprising the element.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, it is intended that the present invention cover the modifications and variations of this invention provided they come within the scope of the appended claims and their equivalents.

Claims (16)

1. A method for managing a container port, characterized in that,
acquiring a port allocation request of a container, wherein the port allocation request carries allocation request parameters;
selecting a port with an idle state according to the allocation request parameters, and allocating the selected port to the container;
marking a status of the selected port as used;
the allocation request parameters include a container type and/or a pre-allocation port;
selecting a port with an idle state according to the allocation request parameter comprises one of the following modes:
when the allocation request parameter comprises a container type, selecting a port with an idle state in a preset port set corresponding to the container type according to the container type;
when the allocation request parameter comprises a pre-allocation port, if the state of the pre-allocation port is idle, selecting the pre-allocation port; if the pre-allocated port is in a used state, selecting a port in an idle state from all ports;
when the allocation request parameters comprise a container type and a pre-allocation port, if the state of the pre-allocation port is idle, selecting the pre-allocation port; and if the pre-allocated port state is used, selecting a port with a free state from a preset port set corresponding to the container type according to the container type.
2. The container port management method of claim 1, further comprising:
determining a mapping relationship between the identity of the container and the identity of the selected port;
storing the mapping relationship between the identifier of the container and the identifier of the selected port in a preset data structure.
3. The container port management method of claim 2, wherein storing the mapping between the identity of the container and the identity of the selected port in a preset data structure comprises:
the preset data structure comprises a tree structure and a linked list structure; storing the mapping relationship between the identifier of the container and the identifier of the selected port in a tree structure, and storing the identifier of the selected port in a linked list structure.
4. The container port management method of claim 3, wherein the linked list structure comprises more than one linked list, different linked lists corresponding to different container types;
storing the identity of the selected port in a linked list structure comprises: determining a container type of the container, and storing the identifier of the selected port in a linked list corresponding to the container type of the container.
5. The container port management method of claim 4, further comprising:
receiving a container destruction notification, wherein the container destruction notification comprises an identifier of a container;
searching a node where the identifier of the container is located in the tree structure, and determining the identifier of the port corresponding to the identifier of the container and the type of the container according to the node;
deleting the node where the identifier of the container in the tree structure is located;
determining a linked list corresponding to the container type, and deleting a node where the port identifier is located from the linked list;
the state of the port is marked as idle.
6. The container port management method of claim 4, further comprising:
scanning the tree structure and traversing the identifiers of the containers in the tree structure;
querying whether an identification of each container exists in the container engine;
if the identifier of a certain container does not exist in the container engine, determining that a port indicated by a node where the identifier of the container is located is a garbage port;
deleting the node where the identifier of the container in the tree structure is located;
determining a linked list corresponding to the container type of the container, and deleting a node where the identifier of the garbage port in the linked list is located;
the state of the garbage port is marked as idle.
7. The container port management method according to any one of claims 3 to 6, wherein a single-threaded access restriction is set for the tree structure and the linked list structure when the addition, deletion, query, and traversal operations are performed on the tree structure and/or the linked list structure, and the single-threaded access restriction is released for the tree structure and the linked list structure after the operations are completed.
8. A container port management apparatus comprising:
a receiving module: a port allocation request for receiving a container;
a port selection module: based on the distribution request parameters carried by the port distribution request, selecting a port with an idle state, and distributing the selected port to the container;
a port state marking module: marking a status of the selected port as used;
the allocation request parameters include a container type and/or a pre-allocation port;
selecting a port with an idle state according to the allocation request parameter comprises one of the following modes:
when the allocation request parameter comprises a container type, selecting a port with an idle state in a preset port set corresponding to the container type according to the container type;
when the allocation request parameter comprises a pre-allocation port, if the state of the pre-allocation port is idle, selecting the pre-allocation port; if the pre-allocated port is in a used state, selecting a port in an idle state from all ports;
when the request information comprises a container type and a pre-allocation port, if the state of the pre-allocation port is idle, selecting the pre-allocation port; and if the pre-allocated port state is used, selecting a port with a free state from a preset port set corresponding to the container type according to the container type.
9. The container port management device of claim 8, further comprising:
a mapping relationship establishing module: determining a mapping relationship between the identity of the container and the identity of the selected port;
a storage module: storing the mapping relationship between the identifier of the container and the identifier of the selected port in a preset data structure.
10. The container port management apparatus according to claim 9, wherein storing the mapping between the identification of the container and the identification of the selected port in a preset data structure comprises:
the preset data structure comprises a tree structure and a linked list structure; storing the mapping relationship between the identifier of the container and the identifier of the selected port in a tree structure, and storing the identifier of the selected port in a linked list structure.
11. The container port management apparatus of claim 10, wherein the linked list structure comprises more than one linked list, different linked lists corresponding to different container types;
storing the identity of the selected port in a linked list structure comprises: determining a container type of the container, and storing the identifier of the selected port in a linked list corresponding to the container type of the container.
12. The container port management device according to claim 11, further comprising:
a receiving module: the system is also used for receiving a container destruction notice, wherein the container destruction notice comprises an identifier of the container;
a scanning module: searching a node where the identifier of the container is located in the tree structure, and determining the identifier of the port corresponding to the identifier of the container and the type of the container according to the node;
a storage module: deleting the node where the identifier of the container in the tree structure is located;
determining a linked list corresponding to the container type, and deleting a node where the port identifier is located from the linked list;
a port state marking module: the state of the port is marked as idle.
13. The container port management device according to claim 11, further comprising:
a scanning module: scanning the tree structure and traversing the identifiers of the containers in the tree structure;
the query module: querying whether an identification of each container exists in the container engine;
if the identifier of a certain container does not exist in the container engine, determining that a port indicated by a node where the identifier of the container is located is a garbage port;
deleting the node where the identifier of the container in the tree structure is located;
determining a linked list corresponding to the container type of the container, and deleting a node where the identifier of the garbage port in the linked list is located;
the state of the garbage port is marked as idle.
14. The container port management apparatus according to any of claims 10 to 13, wherein a single-threaded access restriction is set for the tree structure and the linked list structure when an add, delete, query, traverse operation is performed on the tree structure and/or the linked list structure, and the single-threaded access restriction is released for the tree structure and the linked list structure after the operation is completed.
15. A computer readable medium having computer readable instructions stored thereon which are executable by a processor to implement the method of any one of claims 1 to 7.
16. A computer arrangement comprising a processor, a memory and a computer program stored on the memory, characterized in that the steps of the method according to any of claims 1-7 are implemented when the computer program is executed by the processor.
CN201910417332.2A 2019-05-20 2019-05-20 Method, apparatus, medium, and device for container port management Pending CN111966442A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910417332.2A CN111966442A (en) 2019-05-20 2019-05-20 Method, apparatus, medium, and device for container port management

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910417332.2A CN111966442A (en) 2019-05-20 2019-05-20 Method, apparatus, medium, and device for container port management

Publications (1)

Publication Number Publication Date
CN111966442A true CN111966442A (en) 2020-11-20

Family

ID=73357812

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910417332.2A Pending CN111966442A (en) 2019-05-20 2019-05-20 Method, apparatus, medium, and device for container port management

Country Status (1)

Country Link
CN (1) CN111966442A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112764885A (en) * 2021-01-28 2021-05-07 北京达佳互联信息技术有限公司 Object access method, device, electronic equipment, storage medium and program product
CN114138464A (en) * 2021-11-10 2022-03-04 浪潮卓数大数据产业发展有限公司 Container-based port allocation method and system
CN114827115A (en) * 2022-06-01 2022-07-29 青岛中科曙光科技服务有限公司 Access method and device of Web service in container, electronic equipment and storage medium

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112764885A (en) * 2021-01-28 2021-05-07 北京达佳互联信息技术有限公司 Object access method, device, electronic equipment, storage medium and program product
CN114138464A (en) * 2021-11-10 2022-03-04 浪潮卓数大数据产业发展有限公司 Container-based port allocation method and system
CN114138464B (en) * 2021-11-10 2023-10-31 浪潮卓数大数据产业发展有限公司 Port distribution method and system based on container
CN114827115A (en) * 2022-06-01 2022-07-29 青岛中科曙光科技服务有限公司 Access method and device of Web service in container, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN111966442A (en) Method, apparatus, medium, and device for container port management
CN109614226B (en) Kubernetes-based stateful application storage management method
US6714949B1 (en) Dynamic file system configurations
US10915365B2 (en) Determining a quantity of remote shared partitions based on mapper and reducer nodes
GB2406932A (en) Method for dynamic memory management within an object-oriented program
CN105637491A (en) File migration method and apparatus and storage device
JPH11203372A (en) Method for managing stock for automatic assigning stock and device therefor
CN110704214B (en) Inter-process communication method and device
US11811839B2 (en) Managed distribution of data stream contents
CN108932271B (en) File management method and device
CN108920105B (en) Community structure-based graph data distributed storage method and device
CN110765094B (en) File creation method, device, system and storage medium
CN113805816B (en) Disk space management method, device, equipment and storage medium
CN113377499B (en) Virtual machine management method, device, equipment and readable storage medium
CN113157600A (en) Space allocation method of shingled hard disk, file storage system and server
CN117271531A (en) Data storage method, system, equipment and medium
CN111177075B (en) Junk data identification method and system, electronic equipment and storage medium
JP2021535480A (en) Resource allocation method, equipment and storage media
CN115495432A (en) Method, device and equipment for supporting multiple instances
CN111491040B (en) IP distribution method and IP distribution device
CN110011832B (en) Configuration issuing method and device for planned tasks
CN115904211A (en) Storage system, data processing method and related equipment
CN114647663A (en) Resource processing method, device and system, electronic equipment and storage medium
CN108123924B (en) Resource management method and system
CN112783835B (en) Index management method and device and electronic equipment

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