Container mirror image distribution method and device, equipment and storage medium
By intercepting image download requests in the P2P image distribution network, updating the image index and using Gossip and DHT protocols, the decentralized storage of image files is realized, the problem of single point failure of the central server is solved, and the image transmission efficiency and network stability are improved.
Patent Information
- Application Number
- CN202311254751.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-26
- Publication Date
- 2024-10-18
AI Technical Summary
The existing P2P image distribution network relies on a central server and has the risk of a single point of failure, which affects the availability of the image distribution network.
By intercepting the image metadata file download request when the container is running, downloading and updating the image metadata file index, using the P2P image download method, the download and dissemination of the image layer file data is transferred to the nodes, and is implemented using the Gossip protocol and the DHT protocol. Decentralized storage and update of image file index.
It improves the efficiency and speed of large-scale image data transmission, avoids potential performance problems and network bottlenecks, realizes the decentralization of the image distribution network, avoids the risk of single point failure, and solves the problem that nodes cannot be pulled after the cluster image warehouse is offline. Mirroring problem.
Smart Images

Figure CN118802947A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of container image distribution, and in particular to a container image distribution method, device, equipment and storage medium. Background Art
[0002] At present, the mainstream open source image rapid distribution solutions are all implemented in a metadata-centralized P2P (Peer-to-Peer) network that relies on a Tracker server (central server) in terms of technical principles. The Tracker server is mainly used to record the image file index information in the P2P image distribution network, that is, the corresponding relationship information between the image file and the node where the image file is located. A daemon process is deployed on each node in the P2P network to proxy the image data download. Each time a request for image data download is received, the daemon process will request the Tracker server to obtain the download location of the current image file. The Tracker server will return the optimal parent node for the current node to download the image file based on the image file index information stored in itself. When a node needs to download an image, the scheduling of the image file data download task in the P2P image distribution network depends on the image file index information stored in the Tracker service. Once the Tracker server in the image distribution network fails or the line is blocked and interrupted, the node cannot obtain the image file index information from the Tracker server, which will inevitably affect the availability of the entire P2P image distribution network.
[0003] The above contents are only used to assist in understanding the technical solution of the present invention and do not constitute an admission that the above contents are prior art. Summary of the invention
[0004] The main purpose of the present invention is to provide a container image distribution method, device, equipment and storage medium, aiming to solve the technical problem of potential single point failure of P2P image distribution network due to dependence on central server in the prior art.
[0005] To achieve the above object, the present invention provides a container image distribution method, which comprises the following steps:
[0006] Intercept image metadata file download requests issued by container runtime;
[0007] Based on the image metadata file download request, download the target image metadata file and update the image metadata file index, wherein the image metadata file index is stored in a node of the image distribution network;
[0008] Returning the target image metadata file to the container runtime, and intercepting the image layer file download request issued by the container runtime after parsing the target image metadata file;
[0009] Based on the image layer file download request, the target image layer file is downloaded, and an image layer file index is updated, where the image layer file index is stored in the node.
[0010] Optionally, updating the image metadata file index includes:
[0011] Based on the Gossip protocol, the image distribution network is notified of the current download location of the target image metadata file to update the image metadata file index stored in the node.
[0012] Optionally, downloading a target image metadata file based on the image metadata file download request includes:
[0013] Determining the target image metadata file according to the image metadata file download request;
[0014] Based on the metadata file query priority of a preset download range, query the target image metadata file within the preset download range, the preset download range includes an image repository, a local storage, and an image distribution network, the metadata file query priority of the image repository is higher than the metadata file query priority of the local storage, and the metadata file query priority of the local storage is higher than the metadata file query priority of the image distribution network;
[0015] When the target image metadata file is found within the preset download range, the target image metadata file is downloaded according to the download routing information of the target image metadata file.
[0016] Optionally, the query priority of the metadata file based on a preset download range, querying the target image metadata file within the preset download range, includes:
[0017] When the target image metadata file is not found in the image repository and the local storage, querying the target image metadata file in the image layer file index;
[0018] When the target image metadata file is found in the image layer file index, it is determined that the target image metadata file is found in the image distribution network.
[0019] Optionally, updating the image layer file index includes:
[0020] Obtaining a hash value of the target image layer file, and determining a similar node identification code corresponding to the hash value of the target image layer file;
[0021] Based on the similar node identification code, determining a notification node among the nodes of the mirror distribution network;
[0022] Based on the DHT protocol, the notification node is notified of the current download location of the target image layer file to update the image layer file index stored in the notification node.
[0023] Optionally, downloading a target image layer file based on the image layer file download request includes:
[0024] Determine the target image layer file according to the image layer file download request;
[0025] Based on the image layer file query priority of a preset download range, query the target image metadata file in the preset query range, the preset download range includes an image warehouse, a local storage, and an image distribution network, the image layer file query priority of the local storage is higher than the image layer file query priority of the image distribution network, and the image layer file query priority of the image distribution network is higher than the image layer file query priority of the image warehouse;
[0026] When the target image layer file is found in the preset query range, the target image layer file is downloaded.
[0027] Optionally, the query priority of the image layer file based on a preset download range, and querying the target image metadata file in the preset query range, includes:
[0028] When the target image layer file is not found in the local storage, querying the target image layer file in the image metadata file index of the image distribution network based on the DHT protocol;
[0029] When the target image layer file is found in the image metadata file index, it is determined that the target image layer file is found in the image distribution network.
[0030] In addition, to achieve the above-mentioned purpose, the present invention further proposes a container image distribution device, the container image distribution device comprising:
[0031] The request interception module is used to intercept the image metadata file download request issued by the container runtime;
[0032] A file download module, configured to download a target image metadata file based on the image metadata file download request, and update an image metadata file index, wherein the image metadata file index is stored in a node of the image distribution network;
[0033] The request interception module is further used to return the target image metadata file to the container runtime, and intercept the image layer file download request issued by the container runtime after parsing the target image metadata file;
[0034] The file download module is further used to download the target image layer file based on the image layer file download request, and update the image layer file index, where the image layer file index is stored in the node.
[0035] In addition, to achieve the above-mentioned purpose, the present invention also proposes a container image distribution device, which includes: a memory, a processor, and a container image distribution program stored in the memory and executable on the processor, and the container image distribution program is configured to implement the steps of the container image distribution method described above.
[0036] In addition, to achieve the above-mentioned purpose, the present invention further proposes a storage medium, on which a container image distribution program is stored, and when the container image distribution program is executed by a processor, the steps of the container image distribution method described above are implemented.
[0037] In the present invention, by intercepting the image metadata file download request issued by the container runtime, based on the image metadata file download request, the target image metadata file is downloaded, the image metadata file index stored in the node in the image distribution network is updated, and the target image metadata file is returned to the container runtime, and the image layer file download request issued by the container runtime after parsing the target image metadata file is intercepted, based on the image layer file download request, the target image layer file is downloaded, and the image layer file index stored in the node is updated. The present invention adopts a P2P image download method to transfer the download and propagation of a part of the image layer file data between nodes, which can improve the efficiency and rate of large-scale image data transmission, maximize the use of network bandwidth, thereby avoiding potential performance problems and network bottleneck problems. On this basis, compared with the traditional P2P image distribution network that usually relies on a central server, the present invention can realize the decentralization of the image distribution network, not relying on the central server, all image file index information and image files are scattered and stored on each node of the image distribution network, and a fully distributed storage mode is adopted to avoid the single point failure risk caused by relying on the central server, and the nodes can be coordinated as a distributed container image warehouse to solve the problem that the node cannot pull the image after the cluster image warehouse is offline. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 It is a structural diagram of a container image distribution device in a hardware operating environment involved in an embodiment of the present invention;
[0039] Figure 2This is a flow chart of a first embodiment of a container image distribution method according to the present invention;
[0040] Figure 3 This is a schematic diagram of the container image composition principle of an embodiment of the container image distribution method of the present invention;
[0041] Figure 4 A schematic diagram of an image distribution network according to an embodiment of a container image distribution method of the present invention;
[0042] Figure 5 This is a schematic diagram of the overall architecture of an embodiment of a container image distribution method of the present invention;
[0043] Figure 6 This is a flow chart of a second embodiment of the container image distribution method of the present invention;
[0044] Figure 7 This is a flow chart of a third embodiment of the container image distribution method of the present invention;
[0045] Figure 8 This is a schematic diagram of the overall process of an embodiment of a container image distribution method of the present invention;
[0046] Fig. 9 This is a structural block diagram of the first embodiment of the container image distribution device of the present invention.
[0047] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0048] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0049] Reference Figure 1 , Figure 1 The present invention is a schematic diagram of the structure of a container image distribution device in a hardware operating environment according to an embodiment of the present invention.
[0050] like Figure 1As shown, the container image distribution device may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a wireless fidelity (Wireless-Fidelity, Wi-Fi) interface). The memory 1005 may be a high-speed random access memory (Random Access Memory, RAM) memory, or a stable non-volatile memory (Non-Volatile Memory, NVM), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0051] Those skilled in the art will understand that Figure 1 The structure shown in the figure does not constitute a limitation on the container image distribution device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0052] like Figure 1 As shown, the memory 1005 as a storage medium may include an operating system, a network communication module, a user interface module, and a container image distribution program.
[0053] exist Figure 1 In the container image distribution device shown, the network interface 1004 is mainly used for data communication with the network server; the user interface 1003 is mainly used for data interaction with the user; the processor 1001 and the memory 1005 in the container image distribution device of the present invention can be set in the container image distribution device, and the container image distribution device calls the container image distribution program stored in the memory 1005 through the processor 1001, and executes the container image distribution method provided by the embodiment of the present invention.
[0054] The embodiment of the present invention provides a container image distribution method, referring to Figure 2 , Figure 2 The figure is a flowchart of a first embodiment of a container image distribution method according to the present invention.
[0055] In this embodiment, the container image distribution method includes the following steps:
[0056] Step S10: intercepting the image metadata file download request sent by the container runtime.
[0057] It should be noted that the execution subject of this embodiment can be a container image distribution device, and a container image distribution program (image distribution daemon) is run on the container image distribution device. The image distribution is realized by running the container image distribution program. It can also be other terminal devices with computing capabilities. This embodiment does not limit this. The container image distribution device is used as an example for explanation. Generally speaking, each container image distribution device can be used as a node in the image distribution network.
[0058] It is understandable that if Figure 3 As shown, the container image is mainly composed of a stack of image layer files (blobs). The image metadata file (manifest) stores the image information and the information of each layer of the image layer files that make up the image. Therefore, before downloading the image layer files, you need to download the image metadata file first to determine the relevant information of the image layer files that need to be downloaded.
[0059] It should be understood that the image metadata file download request, i.e., the request to download the image metadata file, is issued by the container runtime. Since this embodiment adopts the P2P image download method, the download and propagation of a portion of the image layer file data (the image layer file that has been downloaded by the node) is transferred between nodes, which greatly alleviates the pressure on the container image warehouse in the large-scale container cluster. At this time, the node agent downloads the image file.
[0060] In the specific implementation, if the container runtime issues a request to download the image metadata file, it will be intercepted by the nodes in the image distribution network.
[0061] Step S20: based on the image metadata file download request, download the target image metadata file and update the image metadata file index, wherein the image metadata file index is stored in a node of the image distribution network.
[0062] It should be noted that the image metadata file download request usually contains relevant information of the image metadata file requested to be downloaded, and the image metadata file requested to be downloaded by the container, that is, the target image metadata file, can be queried and downloaded according to the relevant information in the image metadata file download request. In this embodiment, the image warehouse, local storage, and image distribution network can all be used to query / download image metadata files.
[0063] It can be understood that the nodes are connected through the Gossip protocol and the DHT (Distributed Hash Table) protocol to form a mirror distribution network in this embodiment, which is a P2P mirror distribution network.
[0064] In this embodiment, in addition to storing the downloaded image layer files, each node should also store the image metadata file index, that is, the corresponding relationship between the image metadata file and the node where the image metadata file is located.
[0065] It can be seen that when the image warehouse is offline, this embodiment can query and download the image metadata file through the image metadata file index stored in the image distribution network node.
[0066] Step S30: returning the target image metadata file to the container runtime, and intercepting the image layer file download request issued by the container runtime after parsing the target image metadata file.
[0067] It should be understood that after downloading the target image metadata file, the node will return the target image metadata file to the container runtime, and the container runtime will parse the image layer file information in the target image metadata file and issue an image layer file download request. The image layer file download request is a request to download the image layer file.
[0068] Step S40: based on the image layer file download request, download the target image layer file and update the image layer file index, wherein the image layer file index is stored in the node.
[0069] In this embodiment, when a node joins the image distribution network, a node identification code is generated for it, for example: node ID, which is mainly used for addressing when downloading image layer files (the DHT protocol stipulates that if the hash value of a file is consistent with or very close to the node ID, N nodes are responsible for knowing the storage location of the file in the network, even if these nodes do not save the file). In addition to saving the downloaded image layer files and image metadata file indexes, each node should also save the image layer file index. The image layer file index in this embodiment is the image layer file index corresponding to the node identification code, that is, the image layer file index of the image layer file whose file hash value is close to / consistent with the node identification code, wherein the image layer file index is the corresponding relationship between the image layer file and the node where the image layer file is located, and is used to address the image layer file in the image distribution network.
[0070] Therefore, if Figure 4 As shown in the figure, the nodes form a self-organizing, self-managing decentralized P2P image distribution network. The nodes are connected through the Gossip protocol and the DHT protocol. Each node stores the node ID, the image metadata file index (the full image metadata file index), the image layer file index (partial image layer data index) whose file hash value is close to / consistent with the node ID, and the downloaded image layer file.
[0071] It should be noted that the image layer file download request usually contains relevant information of the image layer file requested for download. According to the relevant information in the image layer file download request, the image layer file requested for download by the container, i.e., the target image layer file, can be queried and downloaded. The image warehouse, local storage, and image distribution network can all be used to query / download image layer files.
[0072] like Figure 5 As shown in the overall architecture diagram, since all image file index information and image files are stored in various nodes of the image distribution network, the entire image distribution network does not rely on the central server when downloading images. At this time, the nodes in the image distribution network can be coordinated into a distributed container image repository. After the cluster container image repository is offline, the nodes can still pull the image.
[0073] In this embodiment, by intercepting the image metadata file download request issued by the container runtime, based on the image metadata file download request, downloading the target image metadata file, updating the image metadata file index stored in the node in the image distribution network, returning the target image metadata file to the container runtime, and intercepting the image layer file download request issued by the container runtime after parsing the target image metadata file, based on the image layer file download request, downloading the target image layer file, and updating the image layer file index stored in the node. This embodiment adopts a P2P image download method to transfer the download and propagation of a part of the image layer file data between nodes, which can improve the efficiency and rate of large-scale image data transmission, maximize the use of network bandwidth, thereby avoiding potential performance problems and network bottleneck problems. On this basis, compared with the traditional P2P image distribution network that usually relies on a central server, this embodiment can realize the decentralization of the image distribution network, not relying on the central server, all image file index information and image files are scattered and stored on each node of the image distribution network, adopting a fully distributed storage mode, avoiding the single point failure risk caused by relying on the central server, and can coordinate the nodes into a distributed container image warehouse, solving the problem that the node cannot pull the image after the cluster image warehouse is offline.
[0074] Reference Figure 6 , Figure 6 The figure is a flow chart of a second embodiment of a container image distribution method according to the present invention.
[0075] Based on the above embodiment, step S20 includes:
[0076] Step S201: determining the target image metadata file according to the image metadata file download request.
[0077] It should be noted that the image metadata file download request usually includes relevant information of the target image metadata file, such as name and label. According to the name and label of the target image metadata file in the request, the target image metadata file to be downloaded can be determined.
[0078] Step S202: Based on the metadata file query priority of the preset download range, query the target image metadata file within the preset download range.
[0079] It can be understood that the preset download range is the range that can be queried and downloaded in this embodiment, including the image warehouse, local storage, and image distribution network. The metadata file query priority refers to the priority when querying the image metadata file. When querying the target image metadata file, the image warehouse, local storage, and image distribution network can set priorities, and queries are performed in sequence according to the priorities. First, the preset download range of the first priority is queried. If the target image metadata file is not found, the preset download range of the second priority is queried. If the target image metadata file is still not found, continue to query within the preset download range of the third priority until the target image metadata file is found, and then download the target image metadata file.
[0080] In this embodiment, the query priority of the metadata file of the image warehouse is higher than the query priority of the metadata file of the local storage, and the query priority of the metadata file of the local storage is higher than the query priority of the metadata file of the image distribution network. At this time, the priority when querying the image metadata file is the image warehouse, the local storage and the image distribution network in turn. When querying the target image metadata file, the query is performed in the order of the image warehouse, the local storage and the image distribution network.
[0081] It should be understood that when querying the target image metadata file, the name and label of the target image metadata file may be used, or other information that is convenient for querying may be used, and this embodiment does not limit this.
[0082] Further, the step S202 includes: when the target image metadata file is not found in the image repository and the local storage, querying the target image metadata file in the image metadata file index; when the target image metadata file is found in the image metadata file index, determining that the target image metadata file is found in the image distribution network.
[0083] It should be noted that according to the metadata file query priority, the image repository will be queried first, followed by the local storage. If the target image metadata file is not found in the image repository and the local storage, the image distribution network will be queried.
[0084] It is understandable that if the image warehouse cannot be connected, that is, the image warehouse is offline, it will be considered that the target image metadata file has not been queried. It can be seen that when the image warehouse is offline, the required target image metadata file can be downloaded through the image distribution network.
[0085] It should be understood that the target image metadata file is queried in the image distribution network through the image metadata file index stored in the nodes of the image distribution network. According to the image metadata file index, it can be determined whether the target image metadata file is stored in each node of the image distribution network. If the target image metadata file can be queried in the image metadata file index, it means that the target image metadata file has been queried in the image distribution network.
[0086] Step S203: when the target image metadata file is found within the preset download range, the target image metadata file is downloaded according to the download routing information of the target image metadata file.
[0087] It should be noted that as long as the target image metadata file is queried in any range of the image repository, local storage, and image distribution network, the download routing information of the target image metadata file will be obtained. The download routing information can be downloaded to the relevant location of the file. For example: if the target image metadata file is queried in the image distribution network, the node will obtain the optimal parent node for file download.
[0088] It is understandable that if the target image metadata file is queried in the local storage, it means that the current node has downloaded the target image metadata file, and downloading the target image metadata file can be considered as obtaining the target image metadata file in the local storage.
[0089] In a specific implementation, first obtain the target image metadata file from the image warehouse (query the target image metadata file in the image warehouse). If the connection to the image warehouse fails or the target image metadata file is not found in the image warehouse, query the target image metadata file in the local storage. If the target image metadata file is not found in the local storage, query the target image metadata file in the image distribution network through the image metadata file index. After the target image metadata file is found, obtain the download routing information of the target image metadata file, and download the target image metadata file according to the obtained download routing information.
[0090] Furthermore, after step S203, the method further includes:
[0091] Step S204: Based on the Gossip protocol, the image distribution network is notified of the current download location of the target image metadata file to update the image metadata file index stored in the node.
[0092] It should be understood that since the nodes in the mirror distribution network are connected via the Gossip protocol, the nodes can communicate / transmit data via the Gossip protocol.
[0093] It should be noted that the current download location of the target image metadata file is the relevant information of the node that currently downloads the target image metadata file, such as a node identification code.
[0094] It is understandable that after the target image metadata file is downloaded by the current node, the locally stored image metadata file index needs to be updated. Therefore, the relevant information of the node that has currently downloaded the target image metadata file will be notified to the image distribution network, that is, the other nodes will be notified that the current node has downloaded the target image metadata file. After receiving the information, the other nodes will update the locally stored image metadata file index, and the current node will also update the locally stored image metadata file index.
[0095] In a specific implementation, after the target image metadata file is downloaded successfully, the image distribution network will be notified of relevant information of the node that has currently downloaded the target image metadata file to update the image metadata file index.
[0096] It should be understood that the image metadata file index in this embodiment is maintained through the Gossip protocol. Every time a node downloads the image metadata file required by the container, the image metadata file index will be updated in time to ensure the accuracy of the image metadata file index. When these image metadata files need to be downloaded, they can be found quickly to ensure the efficiency of the query.
[0097] In this embodiment, according to the image metadata file download request, the target image metadata file is determined, based on the metadata file query priority of the preset download range, the target image metadata file is queried within the preset download range, and when the target image metadata file is queried within the preset download range, the target image metadata file is downloaded according to the download routing information of the target image metadata file, and based on the Gossip protocol, the current download location of the target image metadata file is notified to the image distribution network to update the image metadata file index stored in the node. In this embodiment, the image metadata file index information is dispersedly stored on each node of the image distribution network, a fully distributed storage mode is adopted, and the index is maintained through the Gossip protocol, which can avoid the single point failure risk caused by relying on the central server, coordinate the nodes into a distributed container image warehouse, and solve the problem that the node cannot pull the image after the cluster image warehouse is offline.
[0098] Reference Figure 7 , Figure 7The figure is a flow chart of a third embodiment of a container image distribution method according to the present invention.
[0099] Based on the first embodiment above, step S40 includes:
[0100] Step S401: determining the target image layer file according to the image layer file download request.
[0101] It should be noted that the image layer file download request usually includes relevant information of the target image layer file, such as an identification code, which may be in the form of an ID. According to the identification code of the target image layer file in the request, the target image layer file to be downloaded may be determined.
[0102] Step S402: Based on the image layer file query priority of a preset download range, query the target image metadata file in the preset query range.
[0103] It can be understood that the preset download range is the range that can be queried and downloaded in this embodiment, including the image warehouse, local storage, and image distribution network. The image layer file query priority refers to the priority when querying the image layer file. When querying the target image layer file, the image warehouse, local storage, and image distribution network can set priorities, and query in sequence according to the priority. First, query the preset download range of the first priority. If the target image layer file is not found, query within the preset download range of the second priority. If the target image layer file is still not found, continue to query within the preset download range of the third priority until the target image layer file is found, and then download the target image layer file.
[0104] It should be understood that the priority when querying the image layer file and the priority when querying the image metadata file may be different, that is, the image layer file query priority and the metadata file query priority may be set to different priorities.
[0105] In this embodiment, the query priority of the image layer file of the local storage is higher than the query priority of the image layer file of the image distribution network, and the query priority of the image layer file of the image distribution network is higher than the query priority of the image layer file of the image warehouse. At this time, the priority when querying the image layer file is local storage, image distribution network and image warehouse in order. When querying the target image layer file, the query is performed in the order of local storage, image distribution network and image warehouse.
[0106] It should be noted that when querying the target image layer file, the name identification code of the target image layer file may be used, or other information that is convenient for querying may be used, which is not limited in this embodiment.
[0107] Further, the step S402 includes: when the target image layer file is not found in the local storage, based on the DHT protocol, searching the target image layer file in the image layer file index; when the target image layer file is found in the image layer file index, determining that the target image layer file is found in the image distribution network.
[0108] It is understandable that according to the image layer file query priority, the local storage will be queried first, followed by the image distribution network. If the target image layer file is not found in the local storage and the image distribution network, the image warehouse will be queried.
[0109] It should be understood that the target image layer file is queried in the image distribution network through the image layer file index stored in the node of the image distribution network. Since the image layer file index in each node can only query the image layer file whose file hash value is close to / consistent with the node identification code, it is necessary to communicate with other nodes in the image distribution network to query the image layer file index in other nodes. Since the nodes are connected through the DHT protocol, the nodes can communicate / transmit data through the DHT protocol. Therefore, by connecting through the DHT protocol, the image layer file index in the entire image distribution network is queried to find out whether the node in the image distribution network stores the target image layer file. If the target image layer file can be queried in the image layer file index, it means that the target image layer file has been queried in the image distribution network.
[0110] Step S403: when the target image layer file is found in the preset query range, the target image layer file is downloaded.
[0111] It should be noted that as long as the target image layer file is queried in any range of the image warehouse, local storage and image distribution network, the download routing information of the target image layer file will also be obtained to facilitate file download.
[0112] It is understandable that if the target image layer file is queried in the local storage, it means that the current node has downloaded the target image layer file, and downloading the target image layer file can be considered as obtaining the target image layer file in the local storage.
[0113] In the specific implementation, the target image layer file is first queried in the local storage. If the target image layer file is not found in the local storage, the target image layer file is queried in the image distribution network through the image layer file index. If the target image layer file is not found in the image distribution network, the target image layer file is obtained from the image warehouse (the target image layer file is queried in the image warehouse). After the target image layer file is queried, the download routing information of the target image layer file is obtained, and the target image layer file is downloaded according to the obtained target image layer file.
[0114] Furthermore, after step S403, the following steps are further included:
[0115] Step S404: Obtain the hash value of the target image layer file, and determine the similar node identification code corresponding to the hash value of the target image layer file.
[0116] It should be understood that the similar node identification code refers to a node identification code that is similar to / consistent with the hash value of the target image layer file.
[0117] Step S405: Based on the similar node identification code, determine a notification node among the nodes of the mirror distribution network.
[0118] It should be noted that the notification node is the node corresponding to the similar node identification code, and the number of the notification nodes needs to be determined according to the actual situation, which is not limited in this embodiment.
[0119] Step S406: Based on the DHT protocol, the notification node is notified of the current download location of the target image layer file to update the image layer file index stored in the notification node.
[0120] It is understandable that the current download location of the target image layer file is the relevant information of the node that currently downloads the target image layer file, such as the node identification code. Based on the provisions of the DHT protocol, the notification node needs to know the storage location of the target image layer file in the network. Therefore, the relevant information of the node that currently downloads the target image layer file is sent to the notification node through the DHT protocol. After receiving the information, the notification node will update the locally stored image layer file index.
[0121] In a specific implementation, after the target image layer file is downloaded successfully, the notification node corresponding to the hash value of the target image layer file is notified of the current download location of the target image layer file to update the image layer file index.
[0122] It should be understood that the image layer file index in this embodiment is maintained through the DHT protocol. Every time a node downloads the image layer file required by the container, the image layer file index will be updated in time to ensure the accuracy of the image layer file index. When these image layer files need to be downloaded, they can be found quickly to ensure the efficiency of the query.
[0123] It should be noted that, since a container image may be composed of multiple image layer files, the image download is considered complete after all image layer files are downloaded according to the container image distribution method of this embodiment.
[0124] like Figure 8The overall process diagram shown is as follows: first, intercept the image metadata file download request of the container runtime (docker, containerd, etc.), obtain the name and label of the image metadata file according to the image metadata file download request, query the image metadata information in the image warehouse, local and distribution network according to the name and label (the query priority is image warehouse, local and distribution network), and download it if it is found: obtain it from the image warehouse, if the image warehouse cannot be connected or the image warehouse does not exist, query whether it already exists locally, if it exists locally, end this download, if it does not exist locally, address and download the image metadata file in the image distribution network through the image metadata file index, and after the download is successful, inform other nodes in the image distribution network through the Gossip protocol that the metadata file of the image already exists on the current node, and other nodes update the image metadata file index saved locally after receiving the information. Then return the image metadata to the container runtime, the container runtime will parse the image layer file information in the metadata and issue an image layer file download request, and the image layer file download request will be intercepted at this time. Then extract the image layer file ID in the image layer file download request, query it locally, in the image distribution network, and in the image warehouse, and download it after querying: if the image layer file of the current ID already exists locally, end this download; if it does not exist locally, address and download the image layer file in the image distribution network through the DHT protocol; if the image layer file is not found in the image distribution network, download it directly from the image warehouse; after the download is successful, obtain the hash value of the downloaded image layer file according to the DHT protocol, and notify the node whose node ID is consistent with or close to the hash value of the image layer file to record the index information of the image layer file and update the image layer file index. Download the image layer files in all container images according to the above process, and finally get a complete image.
[0125] In this embodiment, according to the image layer file download request, the target image layer file is determined, based on the image layer file query priority of the preset download range, the target image metadata file is queried in the preset query range, and when the target image layer file is queried in the preset query range, the target image layer file is downloaded, the hash value of the target image layer file is obtained, and the similar node identification code corresponding to the hash value of the target image layer file is determined. Based on the similar node identification code, the notification node is determined in the node of the image distribution network, and based on the DHT protocol, the current download location of the target image layer file is notified to the notification node to update the image layer file index stored by the notification node. In this embodiment, all image file index information and image files are dispersedly stored on each node of the image distribution network, a fully distributed storage mode is adopted, and the index is maintained through the Gossip protocol and the DHT protocol, which can avoid the single point failure risk caused by relying on the central server, coordinate the nodes into a distributed container image warehouse, and solve the problem that the node cannot pull the image after the cluster image warehouse is offline.
[0126] In addition, an embodiment of the present invention further provides a storage medium, on which a container image distribution program is stored. When the container image distribution program is executed by a processor, the steps of the container image distribution method described above are implemented.
[0127] Reference Fig. 9 , Fig. 9 This is a structural block diagram of the first embodiment of the container image distribution device of the present invention.
[0128] like Fig. 9 As shown, the container image distribution device proposed in the embodiment of the present invention includes:
[0129] The request interception module 10 is used to intercept the image metadata file download request issued by the container runtime.
[0130] The file download module 20 is used to download the target image metadata file based on the image metadata file download request and update the image metadata file index, where the image metadata file index is stored in a node of the image distribution network.
[0131] The request interception module 10 is further used to return the target image metadata file to the container runtime, and intercept the image layer file download request issued by the container runtime after parsing the target image metadata file.
[0132] The file download module 20 is further configured to download the target image layer file based on the image layer file download request, and update the image layer file index, where the image layer file index is stored in the node.
[0133] In this embodiment, by intercepting the image metadata file download request issued by the container runtime, based on the image metadata file download request, downloading the target image metadata file, updating the image metadata file index stored in the node in the image distribution network, returning the target image metadata file to the container runtime, and intercepting the image layer file download request issued by the container runtime after parsing the target image metadata file, based on the image layer file download request, downloading the target image layer file, and updating the image layer file index stored in the node. This embodiment adopts a P2P image download method to transfer the download and propagation of a part of the image layer file data between nodes, which can improve the efficiency and rate of large-scale image data transmission, maximize the use of network bandwidth, thereby avoiding potential performance problems and network bottleneck problems. On this basis, compared with the traditional P2P image distribution network that usually relies on a central server, this embodiment can realize the decentralization of the image distribution network, not relying on the central server, all image file index information and image files are scattered and stored on each node of the image distribution network, adopting a fully distributed storage mode, avoiding the single point failure risk caused by relying on the central server, and can coordinate the nodes into a distributed container image warehouse, solving the problem that the node cannot pull the image after the cluster image warehouse is offline.
[0134] In one embodiment, the file download module 20 is further used to notify the image distribution network of the current download location of the target image metadata file based on the Gossip protocol, so as to update the image metadata file index stored in the node.
[0135] In one embodiment, the file download module 20 is further used to determine the target image metadata file according to the image metadata file download request;
[0136] Based on the metadata file query priority of the preset download range, query the target image metadata file within the preset download range, the preset download range includes an image repository, a local storage, and an image distribution network, the metadata file query priority of the image repository is higher than the metadata file query priority of the local storage, and the metadata file query priority of the local storage is higher than the metadata file query priority of the image distribution network;
[0137] When the target image metadata file is found within the preset download range, the target image metadata file is downloaded according to the download routing information of the target image metadata file.
[0138] In one embodiment, the file download module 20 is further configured to query the target image metadata file in the image layer file index when the target image metadata file is not found in the image repository and the local storage;
[0139] When the target image metadata file is found in the image layer file index, it is determined that the target image metadata file is found in the image distribution network.
[0140] In one embodiment, the file download module 20 is further used to obtain a hash value of the target image layer file and determine a similar node identification code corresponding to the hash value of the target image layer file;
[0141] Based on the similar node identification code, determining a notification node among the nodes of the mirror distribution network;
[0142] Based on the DHT protocol, the notification node is notified of the current download location of the target image layer file to update the image layer file index stored in the notification node.
[0143] In one embodiment, the file download module 20 is further used to determine the target image layer file according to the image layer file download request;
[0144] Based on the image layer file query priority of the preset download range, query the target image metadata file in the preset query range, the preset download range includes the image warehouse, local storage and image distribution network, the image layer file query priority of the local storage is higher than the image layer file query priority of the image distribution network, and the image layer file query priority of the image distribution network is higher than the image layer file query priority of the image warehouse;
[0145] When the target image layer file is found in the preset query range, the target image layer file is downloaded.
[0146] In one embodiment, the file download module 20 is further configured to query the target image layer file in the image metadata file index of the image distribution network based on the DHT protocol when the target image layer file is not found in the local storage;
[0147] When the target image layer file is found in the image metadata file index, it is determined that the target image layer file is found in the image distribution network.
[0148] It should be understood that the above is only an example and does not constitute any limitation on the technical solution of the present invention. In specific applications, technicians in this field can make settings as needed, and the present invention does not limit this.
[0149] It should be noted that the workflow described above is merely illustrative and does not limit the scope of protection of the present invention. In practical applications, technicians in this field can select part or all of them according to actual needs to achieve the purpose of the present embodiment, and no limitation is made here.
[0150] In addition, for technical details not fully described in this embodiment, reference may be made to the container image distribution method provided in any embodiment of the present invention, and will not be repeated here.
[0151] In addition, it should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0152] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0153] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory (ROM) / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0154] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A container image distribution method, characterized in that: The container image distribution method comprises: Intercept image metadata file download requests issued by container runtime; Based on the image metadata file download request, download the target image metadata file and update the image metadata file index, wherein the image metadata file index is stored in a node of the image distribution network; Returning the target image metadata file to the container runtime, and intercepting the image layer file download request issued by the container runtime after parsing the target image metadata file; Based on the image layer file download request, the target image layer file is downloaded, and an image layer file index is updated, where the image layer file index is stored in the node.
2. The method according to claim 1, characterized in that The updating of the image metadata file index includes: Based on the Gossip protocol, the image distribution network is notified of the current download location of the target image metadata file to update the image metadata file index stored in the node.
3. The method according to claim 1, characterized in that The downloading of the target image metadata file based on the image metadata file download request includes: Determining the target image metadata file according to the image metadata file download request; Based on the metadata file query priority of a preset download range, query the target image metadata file within the preset download range, the preset download range includes an image repository, a local storage, and an image distribution network, the metadata file query priority of the image repository is higher than the metadata file query priority of the local storage, and the metadata file query priority of the local storage is higher than the metadata file query priority of the image distribution network; When the target image metadata file is found within the preset download range, the target image metadata file is downloaded according to the download routing information of the target image metadata file.
4. The method according to claim 3, characterized in that The metadata file query priority based on the preset download range, querying the target image metadata file within the preset download range, includes: When the target image metadata file is not found in the image repository and the local storage, querying the target image metadata file in the image layer file index; When the target image metadata file is found in the image layer file index, it is determined that the target image metadata file is found in the image distribution network.
5. The method according to claim 1, characterized in that The updating of the image layer file index includes: Obtaining a hash value of the target image layer file, and determining a similar node identification code corresponding to the hash value of the target image layer file; Based on the similar node identification code, determining a notification node among the nodes of the mirror distribution network; Based on the DHT protocol, the notification node is notified of the current download location of the target image layer file to update the image layer file index stored in the notification node.
6. The method according to claim 1, characterized in that The downloading of the target image layer file based on the image layer file download request includes: Determine the target image layer file according to the image layer file download request; Based on the image layer file query priority of a preset download range, query the target image metadata file in the preset query range, the preset download range includes an image warehouse, a local storage, and an image distribution network, the image layer file query priority of the local storage is higher than the image layer file query priority of the image distribution network, and the image layer file query priority of the image distribution network is higher than the image layer file query priority of the image warehouse; When the target image layer file is found in the preset query range, the target image layer file is downloaded.
7. The method according to claim 6, characterized in that The image layer file query priority based on the preset download range, and querying the target image metadata file in the preset query range, includes: When the target image layer file is not found in the local storage, querying the target image layer file in the image metadata file index of the image distribution network based on the DHT protocol; When the target image layer file is found in the image metadata file index, it is determined that the target image layer file is found in the image distribution network.
8. A container image distribution device, characterized in that: The container image distribution device comprises: The request interception module is used to intercept the image metadata file download request issued by the container runtime; A file download module, configured to download a target image metadata file based on the image metadata file download request, and update an image metadata file index, wherein the image metadata file index is stored in a node of the image distribution network; The request interception module is further used to return the target image metadata file to the container runtime, and intercept the image layer file download request issued by the container runtime after parsing the target image metadata file; The file download module is further used to download the target image layer file based on the image layer file download request, and update the image layer file index, where the image layer file index is stored in the node.
9. A container image distribution device, characterized in that: The device comprises: a memory, a processor, and a container image distribution program stored in the memory and executable on the processor, wherein the container image distribution program is configured to implement the steps of the container image distribution method according to any one of claims 1 to 7.
10. A storage medium, characterized in that: The storage medium stores a container image distribution program, and when the container image distribution program is executed by the processor, the steps of the container image distribution method according to any one of claims 1 to 7 are implemented.
