Pod life cycle management method and apparatus, electronic device, and storage medium

WO2024244980A1PCT designated stage expired Publication Date: 2024-12-05ALIBABA CLOUD COMPUTING CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/093506
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-05-26
Filing Date
2024-05-15
Publication Date
2024-12-05

Smart Images

  • Figure CN2024093506_05122024_PF_FP_ABST
    Figure CN2024093506_05122024_PF_FP_ABST
Patent Text Reader

Abstract

The present application discloses a pod life cycle management method and apparatus, an electronic device, and a storage medium. The method comprises: by means of a hook manager, detecting instruction information used for instructing a target pod to transition from a current working state to a next working state, and acquiring a policy file corresponding to the current working state; and, on the basis of the policy file, calling a hook function to execute a corresponding target task, and returning the execution result of the target task. Embodiments of the present application can solve the technical problems in the related art that hook event points that can be defined by a native hook of a pod are limited and the operability and maintainability of the pod are poor.
Need to check novelty before this filing date? Find Prior Art

Description

Container group lifecycle management method, device, electronic device and storage medium

[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on May 26, 2023, with application number 202310617379.X and application name “Lifecycle management method, device, electronic device and storage medium for container group”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] The present application relates to the field of cloud computing technology, and in particular to a method, device, electronic device, and storage medium for lifecycle management of a container group. Background Art

[0003] Kubernetes, abbreviated as K8s, is a portable container orchestration and management tool for container services. A pod (container group) is the smallest deployable computing unit created and managed in K8s. A pod can run one or more containers. Hooks are pod lifecycle functions that monitor specific events in the container lifecycle and execute registered callback functions when these events occur.

[0004] Since the Hook events defined by the native Pod Hook provided by K8s are usually fixed operation tasks, they lack the ability to customize the Hook at the Pod granularity when facing complex scenarios. For example, when certain specific operations need to be performed during Pod operation or when relevant records need to be uploaded before Pod deletion, the Pod's maintainability is poor.

[0005] Summary of the Invention

[0006] In view of the above problems, the present application provides a lifecycle management method, device, electronic device and storage medium for a container group to at least solve the technical problems in the related art that the native Pod Hook can define limited Hook event points and the Pod maintainability is poor.

[0007] According to a first aspect of an embodiment of the present application, a method for lifecycle management of a container group is provided, comprising: detecting, through a hook manager, indication information for instructing a target container group to transition from a current working state to a next working state, and obtaining a policy file corresponding to the current working state; calling a hook function based on the policy file to execute a corresponding target task, and returning the execution result of the target task.

[0008] According to a second aspect of an embodiment of the present application, a lifecycle management device for a container group is provided, comprising: an acquisition unit, configured to detect, through a hook manager, indication information indicating that a target container group has transitioned from a current working state to a next working state, and acquire a policy file corresponding to the current working state; and an execution unit, configured to call a hook function based on the policy file to execute a corresponding target task and return an execution result of the target task.

[0009] According to a third aspect of an embodiment of the present application, an electronic device is further provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the container group lifecycle management method of the first aspect through the computer program.

[0010] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is further provided, in which a computer program is stored. The computer program is configured to execute the container group lifecycle management method of the first aspect described above at runtime.

[0011] In an embodiment of the present application, the hook manager detects the instruction information for instructing the target container group to transition from the current working state to the next working state, and obtains the policy file corresponding to the current working state; based on the above policy file, the hook function is called to execute the corresponding target task, and the execution result of the above target task is returned. Compared with the native Pod Hook, the present application can provide multiple customized Hook capabilities when facing complex scenarios, and can execute registered callback functions at all stages of the entire life cycle of the container group. It not only provides Hook capabilities for the entire Pod life cycle, but also improves the operability and maintainability of the Pod. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] Various other advantages and benefits will become apparent to those skilled in the art upon reading the detailed description of the preferred embodiment below. The accompanying drawings are for illustration purposes only and are not to be considered as limiting the present application. The same reference numerals are used throughout the drawings to represent the same components. In the drawings:

[0013] FIG1 is a schematic diagram of an application environment of an optional container group lifecycle management method according to an embodiment of the present application;

[0014] FIG2 is a flow chart of an optional method for lifecycle management of a container group according to an embodiment of the present application;

[0015] FIG3 is a flow chart of another optional method for lifecycle management of a container group according to an embodiment of the present application;

[0016] FIG4 is a flow chart of another optional method for lifecycle management of a container group according to an embodiment of the present application;

[0017] FIG5 is a flowchart of another optional method for lifecycle management of a container group according to an embodiment of the present application;

[0018] FIG6 is a flowchart of another optional method for lifecycle management of a container group according to an embodiment of the present application;

[0019] FIG7 is a flowchart of another optional method for lifecycle management of a container group according to an embodiment of the present application;

[0020] FIG8 is a flowchart of another optional method for lifecycle management of a container group according to an embodiment of the present application;

[0021] FIG9 is a flow chart of another optional method for lifecycle management of a container group according to an embodiment of the present application;

[0022] FIG10 is a schematic diagram of different working states of another optional container group life cycle according to an embodiment of the present application;

[0023] FIG11 is a schematic diagram of an optional lifecycle management process of a container group according to an embodiment of the present application;

[0024] FIG12 is a schematic diagram of data processing of an optional hook manager according to an embodiment of the present application;

[0025] FIG13 is a schematic structural diagram of a container group lifecycle management device provided in an embodiment of the present application;

[0026] FIG14 is a schematic structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0027] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.

[0028] It should be noted that the terms "first," "second," and the like in the specification and claims of the present invention and the accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus comprising a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units that are not explicitly listed or that are inherent to these processes, methods, products, or apparatus.

[0029] Optionally, according to one aspect of an embodiment of the present application, a method for lifecycle management of a container group is provided. As an optional implementation, the method for lifecycle management of a container group may be, but is not limited to, applied in the application environment shown in FIG1 . The application environment may include, but is not limited to, a management terminal 102 for user interaction, a network 110, and a server 112. A container group management client runs in the management terminal 102. The management terminal 102 includes a display 108, a processor 106, and a memory 104. The display 108 is used to present a management interface for the container group. The processor 106 is used to receive user operation instructions for each container in the container group. The memory 104 is used to store the operation instructions for each container in the container group. In addition, the cloud server 112 includes a database 114 and a processing engine 116. The database is used to store the operating status of the container group and the policy files corresponding to each operating status. The processing engine 116 is used to obtain the policy file corresponding to the current operating status based on the indication information detected by the hook manager indicating the target container group transitioning from the current operating status to the next operating status. Based on the policy file, the processing engine 116 calls a hook function to execute the corresponding target task and returns the execution result of the target task. The execution result is returned to the management terminal 102 .

[0030] Optionally, the management terminal 102 includes, but is not limited to, a mobile phone, laptop computer, tablet computer, PDA, MID (Mobile Internet Device), desktop computer, smart TV, etc. The network 110 may include, but is not limited to, a wired network and a wireless network. The wired network includes, but is not limited to, a local area network, a metropolitan area network, and a wide area network. The wireless network includes, but is not limited to, Bluetooth, Wi-Fi, and other wireless communication networks. The cloud server 112 may be a single server or a cloud server cluster consisting of multiple servers.

[0031] In K8s, native Pod Hooks include a Hook after container startup (PostStart) and a Hook before container termination (PreStop). These two Hooks are usually used to execute specific target tasks. Therefore, the native Pod Hooks provided by K8s have limited definable Hook event points and lack the ability to customize Hooks at the pod level in complex scenarios. For example, when certain specific operations need to be performed during pod operation or relevant records need to be uploaded before pod deletion, the pod's maintainability is poor.

[0032] To solve the above technical problems, as an optional implementation method, as shown in FIG2 , an embodiment of the present application provides a method for lifecycle management of a container group, including the following steps:

[0033] S202: Detecting, through the hook manager, instruction information for instructing the target container group to transition from a current working state to a next working state, and obtaining a policy file corresponding to the current working state.

[0034] Specifically, as shown in Figure 10, the entire life cycle of a Pod includes the following states: from the state in which the container group is created to the state in which at least one container of the container group is running, from the state in which at least one container is terminated to the state in which each container is terminated (all containers exit normally or at least one container exits abnormally), and from the state in which each container is terminated to the state in which the container group is destroyed. It should be noted that in an embodiment of the present application, the current working state and the next working state of the container group in the present application include but are not limited to the above-mentioned states, or the states between the above-mentioned states, and the working state of the target container group is monitored by the hook manager to see if a change has occurred. When the working state changes, the hook function is executed by obtaining the policy file corresponding to the current working state.

[0035] S204: Calling the hook function based on the policy file to execute the corresponding target task, and returning the execution result of the target task.

[0036] Specifically, in the embodiment of the present application, the policy file includes preset operation tasks for the target container group. The corresponding target task is determined by the policy file, and after the target task is completed, the execution result of the target task is returned; the execution result includes, for example, success, failure, and running.

[0037] In an embodiment of the present application, the hook manager detects the instruction information for instructing the target container group to transition from the current working state to the next working state, and obtains the policy file corresponding to the current working state; based on the above policy file, the hook function is called to execute the corresponding target task, and the execution result of the above target task is returned. Compared with the native Pod Hook, the present application can provide multiple customized Hook capabilities when facing complex scenarios, and can execute registered callback functions at all stages of the entire life cycle of the container group. It not only provides Hook capabilities for the entire Pod life cycle, but also improves the operability and maintainability of the Pod.

[0038] In one or more embodiments, as an optional implementation, as shown in FIG3 , an embodiment of the present application provides a method for lifecycle management of a container group, including the following steps:

[0039] S302: Create a policy file that matches each working state of the target container group life cycle, where the policy file includes an instruction set for performing a preset processing operation on the target container group.

[0040] Specifically, in an embodiment of the present application, to execute preset target tasks at each operating state in the target container group's lifecycle, a policy file is created that matches each operating state in the target container group's lifecycle. For example, when each container in the container group is in the terminated state and a database backup operation is required, the policy file contains the corresponding instruction set for performing database annotation operations on the target container group. In one embodiment, the policy file can also be a mirror file, an operation and maintenance script file, or an HTTP (Hypertext Transfer Protocol) configuration file, etc., used to provide operation and maintenance operations.

[0041] S304: Register the policy file to the hook manager.

[0042] Specifically, in an embodiment of the present application, the policy file is registered with the hook manager. The hook manager is used to store and manage the policy file, so that different container groups can reuse the same policy file, thereby improving the operability and maintainability of the container group.

[0043] S306: Detect, through the hook manager, instruction information for instructing the target container group to transition from the current working state to the next working state, and obtain a policy file corresponding to the current working state.

[0044] S308: Call the hook function based on the above policy file to execute the corresponding target task, and return the execution result of the above target task.

[0045] The above steps S306-S308 have been clearly explained in the previous text and will not be repeated here.

[0046] As an optional implementation, as shown in FIG4 , this embodiment of the present application further provides a method for lifecycle management of a container group, comprising the following steps:

[0047] S402: Receive a custom resource object corresponding to the working state of the target container group lifecycle, wherein the custom resource object includes a definition declaration of a hook function to be called in the working state;

[0048] S404: Based on the above definition statement, create a policy file that matches the above working status.

[0049] Specifically, the Hook in the related art is usually an intrusive hook function, and the status label in the workload usually needs to be synchronized to the hook function, that is, the workload and the hook function are highly coupled; when the status label in the workload changes, the status label in the hook function needs to be updated synchronously. However, this method is prone to abnormal execution of the target task due to untimely data synchronization. In an embodiment of the present application, a policy file that matches the working state is created by defining a definition declaration of the hook function that needs to be called in the above-mentioned working state; that is, by defining the Hook declaratively rather than the intrusive hook function, the Hook and the workload declaration can be decoupled.

[0050] S406: Register the policy file to the hook manager.

[0051] S408: Detect, through the hook manager, instruction information for instructing the target container group to transition from the current working state to the next working state, and obtain a policy file corresponding to the current working state.

[0052] S410: Call the hook function based on the above policy file to execute the corresponding target task and return the execution result of the above target task.

[0053] The above steps S406-S410 have been clearly explained in the previous text and will not be repeated here.

[0054] As an optional implementation, as shown in FIG5 , this embodiment of the present application further provides a method for lifecycle management of a container group, comprising the following steps:

[0055] S502: Receive a custom resource object corresponding to the working state of the target container group life cycle, where the custom resource object includes a definition statement of a hook function to be called in the working state.

[0056] S504: Based on the above definition statement, create a policy file that matches the above working status.

[0057] S506: Register the policy file to the hook manager.

[0058] S508: Detecting a start instruction of the target container group through the hook manager, and determining that instruction information for instructing the target container group to transition from an inactive state to an active state is detected.

[0059] S510: Obtain a policy file corresponding to the unstarted state from the initial container of the target container group.

[0060] S512: Call the hook function based on the policy file to execute the corresponding target task, and return the execution result of the target task.

[0061] Specifically, in an embodiment of the present application, as shown in FIG10 , from the start stage to the stage where at least one container is running, the current working state is the unstarted state (the PreStart stage in FIG10 ), and the next working state is the started state (the PostStart stage in FIG10 ). As shown in FIG11 , the current working state is that the container group is in a pending state, and the Pod resource object has been created, but it has not yet been scheduled to be completed. It should be noted that after the Pod resource object of the target container group is created, the first initial container (Initcontainer-0) of the target container group is also created; the present application writes the policy file corresponding to the unstarted state into the initial container in advance; when the start instruction of the target container group is detected by the hook manager, the policy file corresponding to the unstarted state is obtained from the initial container of the target container group, and the corresponding target task can be executed. The policy files here include operation and maintenance image files, operation and maintenance script files, and HTTP script files, etc.

[0062] The above steps S502-S506 have been clearly explained in the previous text and will not be repeated here.

[0063] As an optional implementation, as shown in FIG6 , this embodiment of the present application further provides a method for lifecycle management of a container group, comprising the following steps:

[0064] S602: Receive a custom resource object corresponding to the working state of the target container group life cycle, where the custom resource object includes a definition statement of a hook function to be called in the working state.

[0065] S604: Based on the above definition statement, create a policy file that matches the above working status.

[0066] S606: Register the policy file to the hook manager.

[0067] S608: The hook manager detects that the target container group is in the startup state, and determines that an indication indicating a transition of the target container group from the startup state to the termination state is detected; wherein the termination state indicates that at least one container of the target container group is in the running state.

[0068] S610: Obtain a policy file corresponding to the above startup state.

[0069] S612: Call the hook function based on the policy file to execute the corresponding target task, and return the execution result of the target task.

[0070] Specifically, in an embodiment of the present application, as shown in FIG10 , from the stage where at least one container is running to the stage where the container is started successfully or failed, the current working state is the startup state (PostStart stage in FIG10 ). When a deletion event is triggered, the WebHook (network hook) intercepts the deletion event, and the next working state is the termination state (PreDelete stage in FIG10 ). As shown in FIG11 , the current working state is that the container group is in a state where it has been scheduled to a node in the server cluster, and all containers have been created. It should be noted that when the present application detects the status identifier that the target container group is in the startup state through the hook manager, the policy file corresponding to the above startup state is obtained from the hook manager, and the corresponding target task can be executed. The policy files here include operation and maintenance image files, operation and maintenance script files, and HTTP script files, etc.

[0071] The above steps S602-S606 have been clearly explained in the previous text and will not be repeated here.

[0072] As an optional implementation, as shown in FIG7 , this embodiment of the present application further provides a method for lifecycle management of a container group, comprising the following steps:

[0073] S702: Receive a custom resource object corresponding to the working state of the target container group lifecycle, where the custom resource object includes a definition declaration of a hook function to be called in the working state;

[0074] S704: Based on the above definition statement, create a policy file that matches the above working status.

[0075] S706: Register the policy file to the hook manager.

[0076] S708: Detecting, through the hook manager, a delete instruction for the target container group, and determining that instruction information for instructing the target container group to transition from a terminated state to a deleted state has been detected; wherein the terminated state represents a state in which the delete instruction has been received but not executed;

[0077] S710, obtaining a policy file corresponding to the above-mentioned termination state;

[0078] S712: Call the hook function based on the policy file to execute the corresponding target task, and return the execution result of the target task.

[0079] Specifically, in an embodiment of the present application, as shown in FIG10 , from the at least one container running stage to the stage where all containers are started successfully or failed (at least one container exits abnormally), the current working state is the termination state (PreDelete stage in FIG10 ), and the next working state is the deletion state (PostDelete stage in FIG10 ). As shown in FIG11 , the current working state is that all containers of the container group have been successfully terminated and will not be restarted, or all containers have been terminated, but at least one container has failed to terminate, that is, the container returns a non-zero exit status. When the delete instruction of the target container group (for deleting all containers of the target container group) is detected by the hook manager, the policy file corresponding to the above-mentioned termination state is obtained, and the hook function is called based on the above-mentioned policy file to execute the corresponding target task. After the target task is executed, the above-mentioned delete instruction is executed.

[0080] The above steps S702-S706 have been clearly explained in the previous text and will not be repeated here.

[0081] As an optional implementation, as shown in FIG8 , this embodiment of the present application further provides a method for lifecycle management of a container group, comprising the following steps:

[0082] S802: Receive a custom resource object corresponding to the working state of the target container group life cycle, where the custom resource object includes a definition statement of a hook function to be called in the working state.

[0083] S804: Based on the above definition statement, create a policy file that matches the above working status.

[0084] S806: Register the policy file to the hook manager.

[0085] S808: Detecting a delete instruction for the target container group through the hook manager, and determining that instruction information for instructing the target container group to transition from a terminated state to a deleted state is detected; wherein the terminated state represents a state in which the delete instruction has been received but not executed.

[0086] S810: Obtain a policy file corresponding to the above-mentioned termination state.

[0087] S812: intercept the above-mentioned deletion instruction.

[0088] S814: Call the hook function based on the above policy file to execute the corresponding target task, and return the execution result of the above target task.

[0089] S816: When the target task corresponding to the termination state is completed, execute the above-mentioned deletion instruction.

[0090] Specifically, in this embodiment of the present application, a first annotation tag is generated indicating that the target container group is to be deleted; based on the first annotation tag, a hook function is called to execute the target task corresponding to the policy file; upon completion of the task, the first annotation tag is replaced with a second annotation tag, and the target container group deletion instruction is executed; wherein the second annotation tag is used to indicate that the target container group is to be deleted, and the instruction to delete the target container group is used to destroy each container in the target container group. The policy file here includes operation and maintenance image files, operation and maintenance script files, HTTP script files, etc.

[0091] The above steps S802-S806 have been clearly explained in the previous text and will not be repeated here.

[0092] As an optional implementation, as shown in FIG9 , this embodiment of the present application further provides a method for lifecycle management of a container group, comprising the following steps:

[0093] S902: Receive a custom resource object corresponding to the working state of the target container group life cycle, where the custom resource object includes a definition statement of a hook function to be called in the working state.

[0094] S904: Based on the above definition statement, create a policy file that matches the above working status.

[0095] S906: Register the policy file to the hook manager.

[0096] S908: The hook manager detects that all containers in the target container group are deleted, and determines that an indication that the target container group has transitioned from a deleted state to a deregistered state is detected; wherein the deregistered state indicates that all data in the target container group is deleted.

[0097] S910: Obtain a policy file corresponding to the deletion state from the terminator of the target container group.

[0098] S912: Call the hook function based on the above policy file to execute the corresponding target task, and return the execution result of the above target task.

[0099] Specifically, in an embodiment of the present application, as shown in FIG10 , from the stage where all containers are started successfully or failed (at least one container exits abnormally) to the stage where at least one container is running to the end stage of the container group, the current working state is the deletion state (the PostDelete stage in FIG10 ). As shown in FIG11 , the current working state is that all containers of the container group have been successfully deregistered, and all data of the container group have been deleted. It should be noted that after all containers of the target container group have exited, the target container group still has a terminator (finalizer) remaining. The present application writes the policy file corresponding to the deletion state into the terminator in advance; when the start instruction of the target container group is detected by the hook manager, the policy file corresponding to the deletion state is obtained from the terminator of the target container group, and the corresponding target task can be executed. After the target task is executed, the terminator is deregistered. The policy files here include operation and maintenance image files, operation and maintenance script files, and HTTP script files.

[0100] In one or more embodiments, the container group lifecycle management method further includes:

[0101] When a change is detected in the policy file, the changed policy file is re-registered with the hook manager.

[0102] As shown in FIG12 , in the hook manager, when the hook controller detects that the policy file (P1, P2 or P3) is changed, the changed policy file is re-registered in the change rule of the hook manager.

[0103] In one or more embodiments, creating a policy file that matches each state of the target container group lifecycle includes:

[0104] Create a policy file that matches each working state of the target container group lifecycle; or

[0105] A plurality of policy files matching the respective working states of the target container group lifecycle are created, wherein each policy file in the plurality of policy files corresponds to at least one of the working states.

[0106] As shown in FIG12 , a policy file (one of P1 to P3) is created that matches each working state of the target container group lifecycle. That is, a policy file can include each target task corresponding to each working state of the target container group lifecycle.

[0107] In one example, a policy file only contains the target task corresponding to one working state of the target container group life cycle, for example, the P1 policy file corresponds to the PreStart state, the P2 policy file corresponds to the PostStart state, the P3 policy file corresponds to the PreDelete state, and the P4 (not shown) policy file corresponds to the PostDelete state.

[0108] In one example, a policy file contains target tasks corresponding to one or more working states of the target container group lifecycle, for example, a P1 policy file corresponds to the PreStart state and the PostStart state, a P2 policy file corresponds to the PreDelete state, and a P3 policy file corresponds to the PostDelete state.

[0109] Based on the above embodiment, in an application embodiment, as shown in FIG12 , the lifecycle management method of the container group includes the following steps:

[0110] 1. First, the HookAssembler submits the user-defined resource object (CR object) to the cloud service environment. Here, the action of submitting the CR object can be processed in parallel, and there is no dependency between multiple CRs.

[0111] 2. The PodHookLifecycleController detects the status changes of each CR object in the cloud service.

[0112] 3. When the container group hook lifecycle controller detects that there is a change in the CR object, the coordination control logic is triggered. The coordination controller assembles and submits the change rules to the mutation policy (MutatingPolicy) based on the CR content in the CR object.

[0113] 4. The WebHook (network hook) monitoring corresponding rule object extended within the hook manager.

[0114] 5. WebHook performs corresponding actions on the specified Pod during the creation and deletion stages according to preset rules.

[0115] 6. Specifically, when a specified Pod is created, the WebHook is injected into the InitContainer; when a Pod is deleted, the WebHook intercepts the Pod deletion action and adds a specified declaration (annotation) label. After the hook manager completes the Hook task, the hook manager resets the declaration label and executes the deletion action.

[0116] 7. The PodWatcher starts calling the TaskExecuter.

[0117] 8. The task executor executes the corresponding Hook task.

[0118] 9. Regularly query the results of Hook task execution;

[0119] 10. Update the Hook task execution result to the CR object. The task execution result here includes three states: successful execution result (Succeeded), failed execution result (Failed), and running result (Running). Users can view the execution results of the executed task through the corresponding information.

[0120] In the embodiment of the present application, there is no need to make additional changes to the native workload. The definition of the Pod lifecycle is expanded based on the native workload, and by defining multiple refined lifecycle Hooks, the Hook capability in complex scenarios can be achieved. Moreover, in the actual operation of the Pod, there is no need for the user to be aware of the Hook execution process, the execution process is automated, and the results of the Hook execution can be fed back in real time. For abnormal Hooks, re-execution is attempted to improve self-healing. In addition, by defining the definition declaration of the hook function that needs to be called in the working state to create a policy file that matches the working state, that is, by defining the Hook declaratively rather than the hook function for intrusive access, the Hook and workload declaration can be decoupled.

[0121] It should be noted that for the aforementioned method embodiments, for simplicity of description, they are all expressed as a series of action combinations. However, those skilled in the art should be aware that the present invention is not limited by the order of the actions described, because according to the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in this specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.

[0122] According to another aspect of the embodiments of the present application, a container group lifecycle management device for implementing the above container group lifecycle management method is also provided. As shown in FIG13 , the device includes:

[0123] An acquiring unit 1302 is configured to detect, through the hook manager, indication information indicating that the target container group has transitioned from a current working state to a next working state, and acquire a policy file corresponding to the current working state;

[0124] The execution unit 1304 is used to call the hook function based on the above policy file to execute the corresponding target task and return the execution result of the above target task.

[0125] In an embodiment of the present application, the hook manager detects the instruction information for instructing the target container group to transition from the current working state to the next working state, and obtains the policy file corresponding to the current working state; based on the above policy file, the hook function is called to execute the corresponding target task, and the execution result of the above target task is returned. Compared with the native Pod Hook, the present application can provide multiple customized Hook capabilities when facing complex scenarios, that is, the registered callback function can be executed at each stage of the entire life cycle of the container group, which not only provides the Hook capability of the entire Pod life cycle, but also improves the operability and maintainability of the Pod.

[0126] In one or more embodiments, the lifecycle management device for the container group further includes:

[0127] A creation unit, configured to create a policy file matching each working state of the target container group lifecycle, wherein the policy file includes a set of instructions for performing a preset processing operation on the target container group;

[0128] A registration unit is used to register the above policy file with the above hook manager.

[0129] In one or more embodiments, the creation unit includes:

[0130] A receiving module, configured to receive a custom resource object corresponding to a working state of the target container group lifecycle, wherein the custom resource object includes a definition statement of a hook function to be called in the working state;

[0131] A creation module is used to create a policy file matching the above working status based on the above definition declaration.

[0132] In one or more embodiments, the obtaining unit 1302 includes:

[0133] A first detection and determination module is configured to detect, through the hook manager, a startup instruction of a target container group, and determine that instruction information for instructing the target container group to transition from an inactive state to an active state is detected;

[0134] The first acquisition module is configured to acquire a policy file corresponding to the unstarted state from the initial container of the target container group.

[0135] In one or more embodiments, the obtaining unit 1302 includes:

[0136] A second detection and determination module is configured to detect, through the hook manager, that the target container group is in a startup state, and determine an indication that the target container group has transitioned from the startup state to the termination state; wherein the startup state indicates that at least one container of the target container group is in a running state;

[0137] The second acquisition module is used to obtain the policy file corresponding to the above startup state.

[0138] In one or more embodiments, the obtaining unit 1302 includes:

[0139] a third detection and determination module, configured to detect, through the hook manager, a delete instruction for the target container group, and determine that instruction information indicating a transition of the target container group from a terminated state to a deleted state has been detected; wherein the terminated state represents a state in which the delete instruction has been received but not executed;

[0140] The third acquisition module is used to obtain the policy file corresponding to the above termination state.

[0141] In one or more embodiments, the lifecycle management device for the container group further includes:

[0142] The interception and execution unit is used to intercept the above-mentioned deletion instruction and execute the above-mentioned deletion instruction when the target task corresponding to the above-mentioned termination state is completed.

[0143] In one or more embodiments, the obtaining unit 1302 includes:

[0144] a fourth detection and determination module, configured to detect, through the hook manager, that all containers in the target container group have been deleted, and determine an indication that the target container group has transitioned from a deleted state to a deregistered state; wherein the deregistered state indicates that all data in the target container group has been deleted;

[0145] The fourth acquisition module is configured to acquire the policy file corresponding to the deletion state from the terminator of the target container group.

[0146] According to another aspect of an embodiment of the present application, an electronic device for implementing the above-mentioned container group lifecycle management method is also provided. The electronic device can be the terminal device or cloud server shown in Figure 1. This embodiment is described using the electronic device as a cloud server as an example. As shown in Figure 14, the cloud server includes a memory 1402 and a processor 1404. The memory 1402 stores a computer program, and the processor 1404 is configured to execute the steps of any of the above-mentioned method embodiments through the computer program.

[0147] Optionally, in this embodiment, the electronic device may be at least one network device among a plurality of network devices of a computer network.

[0148] Optionally, in this embodiment, the processor may be configured to execute the following steps through a computer program:

[0149] S1, detecting, through the hook manager, instruction information for instructing the target container group to transition from a current working state to a next working state, and obtaining a policy file corresponding to the current working state;

[0150] S2, calling the hook function based on the policy file to execute the corresponding target task, and returning the execution result of the target task.

[0151] Alternatively, those skilled in the art will appreciate that the structure shown in FIG14 is merely illustrative. FIG14 does not limit the structure of the electronic device. For example, the electronic device may include more or fewer components (such as network interfaces) than those shown in FIG14, or may have a configuration different from that shown in FIG14.

[0152] Memory 1402 can be used to store software programs and modules, such as program instructions / modules corresponding to the container group lifecycle management method and device in the embodiments of the present application. Processor 1404 executes the software programs and modules stored in memory 1402 to perform various functional applications and data processing, thereby implementing the above-mentioned container group lifecycle management method. Memory 1402 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, memory 1402 may further include memory remotely located relative to processor 1404, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof. Memory 1402 may specifically, but is not limited to, be used to store the execution results of the target task.

[0153] As an example, as shown in FIG14 , the memory 1402 may include, but is not limited to, the acquisition unit 1302 and the execution unit 1304 of the container group lifecycle management device. Furthermore, the memory 1402 may also include, but is not limited to, other modules and units of the container group lifecycle management device, which are not further described in this example.

[0154] Optionally, the transmission device 1406 is configured to receive or send data via a network. Specific examples of the network may include a wired network and a wireless network. In one embodiment, the transmission device 1406 includes a network interface controller (NIC), which can be connected to other network devices and a router via a network cable to communicate with the Internet or a local area network. In one embodiment, the transmission device 1406 is a radio frequency (RF) module, which is configured to communicate with the Internet wirelessly.

[0155] In addition, the electronic device further includes: a display 1408 for displaying the execution result of the target task; and a connection bus 1410 for connecting various module components in the electronic device.

[0156] In other embodiments, the terminal device or server may be a node in a distributed system, wherein the distributed system may be a blockchain system, and the blockchain system may be a distributed system formed by connecting multiple nodes through network communication. The nodes may form a peer-to-peer (P2P) network, and any computing device, such as a server, terminal, or other electronic device, may become a node in the blockchain system by joining the peer-to-peer network.

[0157] In one or more embodiments, the present application further provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the above-described container group lifecycle management method. The computer program is configured to execute the steps of any of the above-described method embodiments when executed.

[0158] Optionally, in this embodiment, the computer-readable storage medium may be configured to store a computer program for performing the following steps:

[0159] S1, detecting, through the hook manager, instruction information for instructing the target container group to transition from a current working state to a next working state, and obtaining a policy file corresponding to the current working state;

[0160] S2, calling the hook function based on the policy file to execute the corresponding target task, and returning the execution result of the target task.

[0161] Optionally, in this embodiment, a person of ordinary skill in the art may understand that all or part of the steps in the various methods of the above embodiments may be completed by instructing the hardware related to the terminal device through a program, and the program may be stored in a computer-readable storage medium, which may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0162] The serial numbers of the above embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0163] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above-mentioned computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a number of instructions for causing one or more computer devices (such as personal computers, servers, or network devices) to execute all or part of the steps of the methods of various embodiments of the present invention.

[0164] In the above embodiments of the present invention, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0165] In the several embodiments provided in this application, it should be understood that the disclosed client can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is merely a logical functional division. In actual implementation, there may be other division methods, such as combining or integrating multiple units or components into another system, or ignoring or not implementing some features. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interface, indirect coupling or communication connection of units or modules, and may be electrical or other forms.

[0166] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.

[0167] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.

[0168] The above are only preferred embodiments of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

[0169] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

Claims

1. A method for lifecycle management of a container group, characterized in that: include: Detecting, through the hook manager, indication information for indicating that the target container group changes from a current working state to a next working state, and obtaining a policy file corresponding to the current working state; Based on the policy file, the hook function is called to execute the corresponding target task, and the execution result of the target task is returned.

2. The method according to claim 1, characterized in that Before the hook manager detects the indication information for indicating the target container group to change from the current working state to the next working state, the method further includes: Creating a policy file that matches each working state of the target container group life cycle, wherein the policy file includes a set of instructions for performing a preset processing operation on the target container group; Register the policy file with the hook manager.

3. The method according to claim 2, characterized in that Creating a policy file that matches each working state of the target container group life cycle, including: Receive a custom resource object corresponding to a working state of the target container group life cycle, wherein the custom resource object includes a definition statement of a hook function to be called in the working state; Based on the definition statement, a policy file matching the working state is created.

4. The method according to any one of claims 1 to 3, characterized in that The method of detecting, by the hook manager, indication information for indicating that the target container group changes from a current working state to a next working state, and acquiring a policy file corresponding to the current state includes: Detecting, by the hook manager, a start instruction of the target container group, and determining that instruction information for instructing the target container group to change from an unstarted state to a started state is detected; Obtain a policy file corresponding to the unstarted state from an initial container of the target container group.

5. The method according to any one of claims 1 to 3, characterized in that The method of detecting, by the hook manager, indication information for indicating that the target container group changes from a current working state to a next working state, and acquiring a policy file corresponding to the current state includes: Detecting, by the hook manager, that the target container group is in a startup state, and determining that indication information indicating that the target container group has changed from a startup state to a termination state is detected; wherein the startup state is used to indicate that at least one container of the target container group is in a running state; Obtain a policy file corresponding to the startup state.

6. The method according to any one of claims 1 to 3, characterized in that The method of detecting, by the hook manager, indication information for indicating that the target container group changes from a current working state to a next working state, and acquiring a policy file corresponding to the current state includes: Detecting a deletion instruction of the target container group through the hook manager, determining that indication information for indicating that the target container group changes from a termination state to a deletion state is detected; wherein the termination state is used to represent a state when the deletion instruction has been received but not executed; Obtain a policy file corresponding to the termination state.

7. The method according to claim 6, characterized in that The method further comprises: The deletion instruction is intercepted, and when the target task corresponding to the termination state is completed, the deletion instruction is executed.

8. The method according to any one of claims 1 to 3, characterized in that: The method of detecting, by the hook manager, indication information for indicating that the target container group changes from a current working state to a next working state, and acquiring a policy file corresponding to the current state includes: Detecting, by the hook manager, that all containers in the target container group are deleted, and determining indication information that the target container group is detected to be transitioned from a deleted state to a deregistered state; wherein the deregistered state is used to represent a state in which all data in the target container group is deleted; Obtain a policy file corresponding to the deletion state from a terminator of the target container group.

9. A lifecycle management device for a container group, characterized in that: include: An acquisition unit, configured to detect, through the hook manager, indication information that the target container group changes from a current working state to a next working state, and acquire a policy file corresponding to the current working state; The execution unit is used to call the hook function based on the policy file to execute the corresponding target task and return the execution result of the target task.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: The processor runs the computer program to implement the method according to any one of claims 1 to 8.

11. A computer-readable storage medium having a computer program stored thereon, characterized in that: The program is executed by a processor to implement the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Kubernetes-based container resource dynamic adjustment method

    CN110287029A

  • Container terminal full life cycle management and control system and method

    CN113656241A

  • Data processing method based on container engine and related equipment

    CN115113970A

  • Life cycle management method and device of container group, electronic equipment and storage medium

    CN116755852A

  • Leveraging digital footprints in software development life cycle

    US11650834B1