Container management method, device, equipment and storage medium
1. A method of container management, comprising:
configuring a custom resource object and a corresponding container controller instance, the resource object including its desired operation;
the container controller instance performs corresponding container control based on the desired operation of the resource object, the container control including at least: the vessel is paused.
2. The method of claim 1, wherein configuring the custom resource object and the corresponding container controller instance comprises:
configuring the resource object by using a container cluster management system, and registering the resource object in the container cluster management system;
and configuring the container controller instance by using a container cluster management system, and deploying the container controller instance into the container cluster management system.
3. The method of claim 2, further comprising:
when the container cluster management system monitors that the resource object has an update event, the update event is distributed to the container controller instance for container control, and the update event comprises the expected operation.
4. The method of claim 3, wherein the container controller instance performs container control based on the desired operation of the resource object, comprising:
parsing the desired operation in the update event for the resource object;
performing the container control based on the desired operation;
updating the state of the resource object in the container cluster management system based on the desired operation.
5. The method of claim 2, wherein configuring the resource object with the container cluster management system comprises:
configuring the type of the resource object based on the resource object format of the container cluster management system;
configuring the attribute of the resource object based on the actual application scene, wherein the attribute at least comprises the address of the resource object;
configuring an instance of the resource object, the instance including the desired operation.
6. The method of claim 2, wherein configuring the container controller instance of the resource object with the container cluster management system comprises:
configuring at least one aspect of the following vessel control regimes based on the desired operation:
when the desired operation is a stop operation, the container is controlled to be container-paused.
7. The method according to any one of claims 2 to 6,
the container cluster management system is Kubernets, and the resource object is an extended resource object of the Kubernets.
8. A container management apparatus, comprising:
a configuration module for configuring a custom resource object and a corresponding container controller instance, the resource object including its desired operations;
a control module for the container controller instance to perform container control based on a desired operation of the resource object, the container control comprising at least: the vessel is paused.
9. A computing device, comprising:
a bus;
a communication interface connected to the bus;
at least one processor coupled to the bus; and
at least one memory coupled to the bus and storing program instructions that, when executed by the at least one processor, cause the at least one processor to perform the method of any of claims 1 to 7.
10. A computer-readable storage medium having stored thereon program instructions, which, when executed by a computer, cause the computer to perform the method of any of claims 1 to 7.
Background
Docker is an application container engine, which itself has the functions of: run containers, delete containers, restart containers, pause containers, open containers, etc. The containers are separate entities, each container being independently separable.
Kubernetes is a container cluster management system, can realize the functions of automatic deployment, automatic expansion and contraction of container clusters, maintenance and the like, and is an arrangement tool for carrying out unified management, deployment, operation and maintenance on containers. The kubernets' minimum management scheduling unit is Pod, one Pod includes one or more containers, and also includes shared resources of each container such as storage and network, which are generally managed by a kubernets controller. The Kubernetes controller has the functions of: create Pod, update Pod, delete Pod, etc. But does not include the functionality of suspending the Pod.
In the initial design concept of kubernets, kubernets are only deployed in internet scenes, and the purpose is to simplify the processes of development, compilation, testing and deployment. The Kubernetes can always guarantee the normal and continuous operation of the container application in the Kubernetes in the production environment, and if the container application fails, the Kubernetes provides the automatic repair function. Kubernets provides the functionality to scroll through updates if the container application has a new version updated. Therefore, the application deployed by Kubernetes only has the functions of creating, deleting and updating, and does not have the function of suspending the container application.
With the continuous development of kubernets, in an embedded device level scene, a uniform programming management container application is also required to be performed through kubernets. However, in the embedded device, physical resources are limited, and many containers cannot be simultaneously operated in an internet scene, so kubernets are required to provide a function of suspending the containers.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method, an apparatus, a device, and a storage medium for managing a container, where a container cluster management system configures a custom resource object and a container controller instance, and the container controller instance performs container control based on a container of the resource object to implement container suspension or restart, so as to implement quick suspension and quick recovery of a container in a device with limited physical resources, and improve resource utilization.
In a first aspect, an embodiment of the present invention provides a container management method, including: configuring a custom resource object and a corresponding container controller instance, the resource object including desired operating parameters thereof; the container controller instance performs container control based on the desired operation of the resource object, the container control including at least: the vessel is paused.
Therefore, the container is controlled based on the self-defined resource object and the container controller instance, and the container is at least paused, so that the container is quickly paused in the physical resource limited device, the delay and the expense for recreating the container are avoided, the stopped state of the container does not occupy the resources of a CPU (central processing unit), a memory and the like, the resource utilization rate is improved, the container can be quickly recovered when the paused container application needs to be operated, and the corresponding time of the container is improved. In a possible implementation manner of the first aspect of the present invention, the configuring the customized resource object and the corresponding container controller instance includes: configuring the resource object by using a container cluster management system, and registering the resource object in the container cluster management system; and configuring the container controller instance of the resource object by using the container cluster management system, and deploying the container controller instance into the container cluster management system.
Therefore, the resource object and the container controller instance are defined based on the container cluster management system, so that the self-defined resource object is monitored by the container cluster management system, and management is facilitated.
In a possible implementation manner of the first aspect of the present invention, when the container cluster management system monitors that the resource object has an update event, the update event is distributed to the container controller instance for container control.
Therefore, the user-defined resource objects are monitored by using the container cluster management system, and management is facilitated.
In a possible implementation manner of the first aspect of the present invention, the container controller instance performing container control based on the desired operation of the resource object includes: parsing the desired operation in the update event for the resource object; performing the container control based on the desired operation; updating the state of the resource object in the container cluster management system based on the desired operation.
In this way, the configured container controller instance performs container management based on the expected operation, so that control over a single container is realized, and the resource utilization rate in a resource-limited scene is improved.
In a possible implementation manner of the first aspect of the present invention, the configuring, by the container cluster management system, the resource object includes: configuring the type of the resource object based on the resource object format of the container cluster management system; defining the attribute of the resource object based on the actual application scene, wherein the attribute at least comprises the address of the resource object; configuring an instance of the resource object, the instance including the desired operation.
Therefore, the type, the attribute and the example of the resource object are configured based on the container cluster management system, so that the self-defined resource object is consistent with the format of the container cluster management system, and the monitoring and the management of the container cluster management system are facilitated.
In a possible implementation manner of the first aspect of the present invention, the configuring, by the container cluster management system, the container controller instance of the resource object includes: based on the expected operation configuration, at least the following container control modes are included: when the desired operation is a stop operation, the container is controlled to be container-paused.
Therefore, the control mode of the corresponding container controller instance is configured based on the expected operation in the self-defined resource object instance, and at least the container pause function is supported.
In one possible implementation manner of the first aspect of the present invention, the container cluster management system is kubernets; the resource object is an extended resource object of Kubernetes.
Therefore, the Kubernets are used as the container cluster management system to configure the self-defined resource object, and the monitoring, storage and change event distribution of the self-defined resource object are realized by using the Kubernets.
In a second aspect, an embodiment of the present invention provides a container management apparatus, including: a configuration module for configuring a custom resource object and a corresponding container controller instance, the resource object including desired operating parameters thereof; a control module for the container controller instance to perform container control based on a desired operation of the resource object, the container control comprising at least: the vessel is paused.
Therefore, the container is controlled based on the self-defined resource object and the container controller instance, and the container pause function is realized, so that the container is quickly paused in the physical resource limited device, the delay and the expense for recreating the container are avoided, the stopped state of the container does not occupy the resources such as a CPU (central processing unit), a memory and the like, the resource utilization rate is improved, the suspended container can be quickly recovered when the application is required to run, and the corresponding time of the container is improved.
In one possible implementation of the second aspect of the invention, the configuration module comprises: the resource object configuration module is used for configuring the resource object by utilizing the container cluster management system and registering the resource object into the container cluster management system; and the controller configuration module is used for configuring the container controller instance of the resource object by using the container cluster management system and deploying the container controller instance into the container cluster management system.
Therefore, the resource object and the container controller instance are defined based on the container cluster management system, so that the self-defined resource object is monitored by the container cluster management system, and management is facilitated.
In one possible implementation manner of the second aspect of the present invention, the method further includes: the monitoring module is used for distributing the update event to the container controller instance for container control when the container cluster management system monitors that the resource object has the update event.
Therefore, the user-defined resource objects are monitored by using the container cluster management system, and management is facilitated.
In a possible implementation of the second aspect of the invention, the control module is specifically configured to parse the desired operation in the update event for the resource object; further for performing the container control based on the desired operation; and updating the state of the resource object in the container cluster management system based on the expected operation.
Therefore, the corresponding container controller instance performs container management based on the expected operation, so that control over a single container is realized, and the resource utilization rate in a resource-limited scene is improved.
In a possible implementation manner of the second aspect of the present invention, the resource object configuration module is specifically configured to configure the type of the resource object based on a resource object format of a container cluster management system; the method is further specifically configured to define attributes of the resource object based on an actual application scenario, including at least an address of the resource object; and is further specifically configured to configure an instance of the resource object, the instance including the desired operation.
Therefore, the type, the attribute and the example of the resource object are configured based on the container cluster management system, so that the self-defined resource object is consistent with the format of the container cluster management system, and the monitoring and the management of the container cluster management system are facilitated.
In a possible implementation manner of the second aspect of the present invention, the controller configuration module is specifically configured to configure, by using the container cluster management system, the following container control manners based on the desired operation, including at least: when the desired operation is a stop operation, the container is controlled to be container-paused.
In this way, the control mode of the container controller instance corresponding to the desired operation configuration in the customized resource object instance at least supports the container suspension function.
In one possible embodiment of the second aspect of the present invention, the container cluster management system is kubernets; the resource object is an extended resource object of Kubernetes.
Therefore, the Kubernets are used as the container cluster management system to configure the self-defined resource object, and the monitoring, storage and change event distribution of the self-defined resource object are realized by using the Kubernets.
In a third aspect, embodiments of the invention provide a computing device comprising,
a bus;
a communication interface connected to the bus;
at least one processor coupled to the bus; and
at least one memory coupled to the bus and storing program instructions that, when executed by the at least one processor, cause the at least one processor to perform any of the embodiments of the first aspect of the present invention.
In a fourth aspect, there is provided a computer readable storage medium having stored thereon program instructions which, when executed by a computer, cause the computer to perform the embodiments of any of the first aspects of the present application.
Drawings
FIG. 1 is a flowchart illustrating a first embodiment of a container management method according to the present invention;
FIG. 2 is a flowchart illustrating a second embodiment of a container management method according to the present invention;
FIG. 3 is a flowchart illustrating a configuration method according to a second embodiment of a container management method of the present invention;
FIG. 4 is a flow chart of a monitoring and control method according to a second embodiment of the container management method of the present invention;
FIG. 5 is a schematic structural diagram of a container management apparatus according to a first embodiment of the present invention;
FIG. 6 is a schematic structural diagram of a second embodiment of a container management apparatus according to the present invention;
fig. 7A is a schematic structural diagram of a second configuration module of a second embodiment of a container management apparatus according to the present invention;
fig. 7B is a schematic structural diagram of a second monitoring module of a second embodiment of a container management apparatus according to the present invention;
fig. 7C is a schematic structural diagram of a second control module of a second embodiment of a container management apparatus according to the present invention;
fig. 8 is a schematic structural diagram of a computing device according to various embodiments of the present invention.
Detailed Description
In the following description, reference is made to "some embodiments" which describe a subset of all possible embodiments, but it is understood that "some embodiments" may be the same subset or different subsets of all possible embodiments, and may be combined with each other without conflict.
In the following description, references to the terms "first \ second \ third, etc." or module a, module B, module C, etc. are used solely to distinguish between similar objects or different embodiments and are not intended to imply a particular ordering with respect to the objects, it being understood that where permissible any particular ordering or sequence may be interchanged to enable embodiments of the invention described herein to be practiced otherwise than as shown or described herein.
In the following description, reference to reference numerals indicating steps, such as S110, S120 … …, etc., does not necessarily indicate that the steps are performed in this order, and the order of the preceding and following steps may be interchanged or performed simultaneously, where permissible.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. The terminology used herein is for the purpose of describing embodiments of the invention only and is not intended to be limiting of the invention.
Before further detailed description of the embodiments of the present invention, terms and expressions in the embodiments of the present invention, and their corresponding uses, functions, and so on in the present invention will be described.
Embodiments of the present invention are implemented based on a container cluster management system, kubernets is a typical container cluster management system, and the following terms and terms in kubernets according to embodiments of the present application are applicable to the following explanations.
1. Kubernetes: a container cluster management system can realize the functions of automatic deployment, automatic expansion and contraction, maintenance and the like of a container cluster, and is an arrangement tool for carrying out unified management, deployment, operation and maintenance on containers. Kubernetes' minimum management schedule element is Pod, and one Pod contains one or more containers.
2. CRD: kubernetes' client Resource Definition mechanism (CRD). While kubernets provides many built-in resource objects, there may be some special requirements for the platform in different application service environments. The Kubernetes CRD defines the Kubernetes' extended resource object for these requirements and ensures registration, monitoring and use of new resource objects.
3. Informmer: the Kubernetes completes the functions of monitoring resource objects, storing and distributing the resource objects and distributing the resource object change events. Reflector, DeltaFIFO, Indexer and ThreadSafeteStore, described later, are all components of the Informer.
4. A Reflector: monitoring each resource object in Kubernets through Kubernets API, monitoring creation, updating and deletion of the resource object in Kubernets, and then putting the change event into a Delta FIFO queue.
5. Delta FIFO: a first-in first-out queue in Kubernets can store change events of resource objects, including creation, update and deletion events of the resource objects.
6. Indexer: the kubernets local storage of resource objects, the Informer stores the fetched resource objects from the DeltaFIFO to Indexer. Indexer has an index function with a resource object as an identifier.
7. ThreadSafeStore: the Kubernetes stores resource object state in Kubernetes by using index as identification, Indexer internally encapsulates ThreadSafetStore, self generates index of resource object, and stores various operations by using index as identification.
8. Docker: an application container engine, having its own functions of: run containers, delete containers, restart containers, pause containers, open containers, etc. The containers are separate entities, each container being independently separable.
The embodiments of the invention are applied to an embedded device based on Kubernets, the physical resources of the embedded device are limited, and a plurality of containers cannot be operated in an internet scene at the same time, so that the Kubernets are required to provide a function of suspending the containers. The embodiments of the invention configure a self-defined resource object and a corresponding container controller instance based on a CRD of a Kubernets container cluster management system, register the self-defined resource object in the Kubernets and operate the corresponding container controller instance in the Kubernets, monitor an update event of the self-defined resource object by using an Informer of the Kubernets, and distribute the update event to the corresponding container controller instance to perform the functions of suspending and restarting a single container, thereby improving the resource utilization rate of embedded equipment.
Embodiments of a method for managing a computer memory according to the present invention are described below with reference to fig. 1 to 4.
[ first embodiment of Container management method ]
Fig. 1 shows a flow of a first embodiment of a container management method of the present invention, which includes:
s110, configuring a self-defined resource object and a corresponding container controller instance by using the container cluster management system, wherein the resource object comprises expected operation of the resource object.
The container cluster management system provides a self-defined resource object and a corresponding container controller instance, defines a new resource object as an extended resource object of the container cluster management system according to actual scene requirements, and registers the new resource object into the container cluster management system for monitoring and container control.
When defining the resource object, configuring an instance of the resource object, wherein the instance comprises expected operation of the resource object, and the expected operation at least comprises pause.
Wherein configuring the corresponding container controller instance comprises: and carrying out instantiation configuration on the container controller based on the self-defined resource object, generating a corresponding container controller instance, and deploying the container controller instance to a container cluster management system.
S120, monitoring the self-defined resource object by using the container cluster management system, and distributing the monitored update event of the resource object to the container controller instance.
When the container cluster management system monitors that the customized resource object has the update event, the update event is distributed to the container controller instance according to the management mode of the container cluster management system, the update operation event of the customized resource object is distributed in the mode of the customized resource object instance, and the customized resource object instance comprises the expected operation.
S130, the corresponding container controller instance performs container control based on the update operation event of the self-defined resource object, and the container control at least comprises the following steps: the vessel is paused.
The updating operation event of the self-defined resource object is distributed in a mode of an example of the self-defined resource object, the example of the self-defined resource object comprises expected operation of the example, and container control is carried out based on the expected operation.
Wherein when the desired operation is stop, the container suspension control is performed.
And when the expected operation is running and the customized resource object already exists, carrying out container restart control without recreating a container.
The pause state of the container does not occupy resources such as a CPU (central processing unit) and a memory, and the restart of the container does not have delay and overhead of recreating the container.
In summary, in an embodiment of a container management method, a container is controlled in a container cluster management system based on a self-defined resource object and a container controller instance, and functions including at least container suspension and restart are implemented, so that in a physical resource-limited device, a container is quickly suspended and quickly restored, and a resource utilization rate is improved.
(second embodiment of Container management method)
Fig. 2 shows a flow of a second embodiment of the container management method of the present invention, which includes:
s210, configuring the self-defined resource object and the corresponding container controller instance by using CRD of Kubernetes.
The CRD of Kubernetes provides a resource object with custom expansion and a corresponding container controller example, a new resource object is defined according to actual scene requirements and serves as an expansion resource object of the Kubernetes, and the new resource object is registered to the Kubernetes for monitoring and container control.
The corresponding container controller instance is a container controller instance configured by instantiation based on a self-defined resource object, and the container controller instance is deployed into Kubernets.
Please refer to a configuration method of the second embodiment of the container management method.
S220, Kubernetes monitors the self-defined resource object and distributes the update event monitored to the resource object to the corresponding container controller instance.
When the Kubernets monitor that the self-defined resource object has the update event, the update event is distributed to the corresponding container controller instance according to the management mode of the Kubernets, the update event of the self-defined resource object is distributed in the mode of the self-defined resource object instance, and the self-defined resource object instance comprises expected operation of the self-defined resource object instance.
Please refer to the monitoring method of the second embodiment of the container management method.
S230, the corresponding container controller instance performs container control based on the desired operation of the customized resource object, where the container control at least includes: container suspension, container restart, container deletion.
The updating event of the self-defined resource object is distributed in a mode of an example of the self-defined resource object, the example of the self-defined resource object comprises expected operation, and container control is carried out based on the expected operation.
The pause state of the container does not occupy resources such as a CPU (central processing unit) and a memory, and the restart of the container does not have delay and overhead of recreating the container.
Please refer to a control method of the second embodiment of the container management method.
(configuration method of second embodiment of container management method) ]
The present embodiment utilizes the kubernets CRD to configure a custom resource object and a corresponding container controller instance. Fig. 3 shows a flow of a configuration method of an embodiment of a container management method of the present invention, which includes:
and S2110, configuring the customized resource object type.
The CRD of Kubernetes is called to configure a self-defined resource object type based on the resource object format of Kubernetes.
Illustratively, this step configures the custom resource object types using the yaml language (the language used to express data serialization), including at least configuring: and configuring the called Kubernetes library apiVersion, the resource object type kid and the environment metadata.
Exemplarily, the customized resource object name of the present embodiment is RT, the type is RealTime, and the following shows part of the content of its type profile RealTime.
S2120, configuring attribute parameters of the self-defined resource object, and registering the attribute parameters in Kubernets to enable the Kubernets to monitor and manage the resource object.
The CRD of the Kubernetes is called to configure the attribute parameters of the self-defined resource object based on the actual scene requirement, and the attribute parameters are registered in the Kubernetes to become the extended resource object of the Kubernetes, so that the Kubernetes can monitor and manage conveniently.
Illustratively, this step uses GO language (a compiling language, syntax similar to C language) to configure the attribute parameters of the custom resource object, configure at least the container IP address and Port attribute related to the custom resource object, and compile into an executable file for running.
Illustratively, continuing with the example of the customized resource object with the type RealTime, the following shows part of the content of the attribute parameter profile type.
S2130, configuring an instance of the custom resource object, and deploying the instance into Kubernets.
In this step, the CRD of Kubernetes is invoked to configure an instance of a custom resource object, which includes a desired operation in an update event that is dispatched to a corresponding container controller instance for container control.
Illustratively, the present embodiment uses YAML language for configuration, and configures at least the customized resource object type, container IP address and Port, and container image number replicas, and the desired operation action of the customized resource object.
Wherein, the corresponding relation between the expected operation action and the expected state is as follows:
the expected state of the expected operation being a restart operation (start) > resource object is running (running),
the desired state of the desired operation being a stop operation (stop) > resource object is suspended (stopped),
the desired state of the desired operation being a delete operation (delete) - > resource object is delete (deleted).
Continuing exemplarily with the example of the customized resource object of type RealTime, the following shows a part of the content of which example profile 1 is rt.yaml.
S2140, configuring the container controller instance corresponding to the self-defined resource object, and running in Kubernets.
In the step, the CRD of Kubernetes is called to carry out instantiation configuration on the container controller instance of the user-defined resource object, and the following functions are realized:
(1) and acquiring an update event of the distributed self-defined resource object, and determining the expected operation of the self-defined resource object according to the action parameter of the instance.
(2) And calling a Docker API to perform corresponding container control according to the expected operation of the user-defined resource object. Exemplarily, when the desired operation is a Stop operation (Stop), the associated container is paused; illustratively, the associated container is restarted when the desired operation is a restart operation (Start) and the custom resource object already exists.
(3) And updating the state of the custom resource object according to the expected operation of the custom resource object. Illustratively, when the desired operation is a Stop operation (Stop), updating the state of the custom resource object to Stopped; illustratively, when the desired operation is restart (Start) and the custom resource object already exists, the state of the custom resource object is updated to Running.
Illustratively, the present embodiment will write a container controller instance, operating in kubernets, using the GO language, to perform container control including at least container suspension or restart. Continuing with the example of a custom resource object of type RealTime, the following shows the file directories of its corresponding container controller instance.
Monitoring method of second embodiment of container management method
The embodiment utilizes various components of Kubernetes' Informer to monitor, store and update the distribution of events to the custom resource object. Fig. 4 is a flowchart illustrating a monitoring method according to an embodiment of a container management method of the present invention, which includes:
s2210 and a Reflector monitor the self-defined resource object through a Kubernets API.
The Reflector can monitor change events of all resource objects registered in kubernets, including change events of resource objects customized in this embodiment and resource objects built in kubernets.
Illustratively, when the Reflector is used for monitoring the built-in resource object, the change event at least includes: add event (Added), update event (Updated), delete event (Deleted). The indicator is configured to monitor the custom resource object, where the change event is an update event (Updated), and the change event includes the desired operation defined in the configuration embodiment.
S2220 and Reflector store the monitored updating event of the self-defined resource object into the Delta FIFO queue.
The Delta FIFO queue is a queue supporting First-in Fisrt-out (FIFO), and changes of all resource objects registered in Kubernets are stored in a queue form. For the custom resource object, an update event (Updated) is stored for the custom resource object.
S2230, Informer takes self-defined resource object and its update event from DeltaFIFO queue.
The Informer outputs all resource objects registered in kubernets and change events thereof from a delta fifo queue POP in a queue first-in first-out mode based on queues. POP out for this embodiment is the defined resource object and its update event.
S2240, the Informmer inquires the self-defined resource object in the Indexer, and if the self-defined resource object does not exist, the self-defined resource object is created in the Indexer.
Wherein, a cache database is established in Indexer for all resource objects registered in kubernets, and a cache is established for the customized resource object in this embodiment. The cache database is an encapsulation with a ThreadSafeStore database as a bottom layer, and the ThreadSafeStore database operates by taking the index of a resource object as an identifier. When the Informmer or the subsequent corresponding container controller instance uses the resource object as the identifier to operate the Indexer, the Indexer internally shows that the threadSafeStore is operated by using the index as the identifier.
S2250, the Informer distributes the update events to the corresponding container controller instance in a self-defined resource object instance mode.
The Informer distributes the change events of all resource objects registered in kubernets to the relevant container controller instance for container control. For a customized resource object, the update event is distributed to the corresponding container controller instance, and the customized resource object is distributed to the corresponding container controller instance in the configuration embodiment in the form of the instance of the customized resource object, so as to perform container control.
Control method of second embodiment of container management method
This embodiment utilizes a corresponding container controller instance running in kubernets for container control. Continuing with fig. 4 as an example, the flow of the control method according to an embodiment of the container management method of the present invention includes:
s2310, analyzing the updating event of the self-defined resource object, and determining the expected operation of the self-defined resource object.
Wherein, the update event of the self-defined resource object is distributed in a self-defined resource object instance mode, and comprises the expected operation of the self-defined resource object.
Continuing exemplarily with the example of the custom resource object of type RealTime, the following shows a part of the content of which example profile 2 is rt.yaml.
S2320, calling a Dockers API interface to control the container based on the expected operation.
When the desired operation is a start operation (start), the container is controlled to be a container restart;
when the desired operation is a delete operation (delete), the container control is container deletion;
when the desired operation is a stop operation (stop), the vessel control is a vessel pause.
S2330, updating the state of the custom resource object in the ThreadSafeStore based on the expected operation.
When the expected operation is a stop operation (stop), the state of the custom resource object is set to a pause state (Stopped);
when the expected operation is a starting operation (start), setting the state of the user-defined resource object to be a running state (running);
when the desired operation is a delete operation (delete), the state of the custom resource object sets a delete state (deleted).
Illustratively, the corresponding container controller instance sets the customized resource object to the following state according to the corresponding relationship based on the instance configuration file 2:
[[email protected]~]#kubectl get rt
NAME STATUS TYPE READY IMAGE NAMESPACE AGE
rt Running RealTime 3/3nginx:latest rt 48d
wherein STATUS is the state of the customized resource object, and its value is Running (Running).
Illustratively, after the corresponding container controller instance is based on the instance configuration file 1, the customized resource object is set to the following state according to the corresponding relationship:
[[email protected]~]#kubectl get rt
NAME STATUS TYPE READY IMAGE NAMESPACE AGE
rt Stopped RealTime 3/3nginx:latest rt 48d
wherein STATUS is the STATUS of the custom resource object, and its value is suspended (Stopped).
In summary, in kubernets, a resource object and a corresponding container controller instance are defined by a CRD in a kubernets method, and the container controller instance controls a container to implement functions including at least container suspension and restart, so that in a physical resource-constrained device, a container is suspended and restored quickly, and a resource utilization rate is improved.
An embodiment of a computer memory management device according to the present invention is described below with reference to fig. 5 to 7C.
First embodiment of a container management device
Fig. 5 shows a structure of a second embodiment of the container management apparatus, which includes the following modules:
a configuration module 510 for configuring the custom resource object and the corresponding container controller instance using the container cluster management system. For the principles and advantages, reference is made to step S110 of a first embodiment of a method for managing containers.
The monitoring module 520 is configured to monitor the customized resource object by the container cluster management system, and distribute the monitored update event of the resource object to the corresponding container controller instance. The principle and advantages of this embodiment refer to step S120 of the first embodiment of a container management method.
The control module 530 is configured to perform container control on the corresponding container controller instance based on the update operation event of the customized resource object, where the container control at least includes: container suspension, container restart, container deletion. For the principles and advantages, reference is made to step S130 of a first embodiment of a method for managing containers.
In summary, in an embodiment of a container management apparatus, a container is controlled based on a self-defined resource object and a container controller instance, and functions at least including container suspension and restart are implemented, so that in a physical resource-limited device, a container is quickly suspended and quickly restored, and a resource utilization rate is improved.
(second embodiment of Container management device)
Fig. 6 shows a structure of a second embodiment of the container management apparatus, which includes the following modules:
a second configuration module 610 for configuring custom resource objects and container controller instances with the kubernets CRD. For the principle and advantages, please refer to step S210 of an embodiment of a container management method, and refer to a second configuration module of an embodiment of a container management apparatus for the module structure.
The second monitoring module 620 is configured to monitor the customized resource object by kubernets, and distribute the monitored update event of the resource object to the corresponding container controller instance. Please refer to step S220 of an embodiment of a container management method, and refer to the second monitoring module of an embodiment of a container management apparatus in terms of the module structure.
The second control module 630, configured to perform container control on the corresponding container controller instance based on the update operation event of the customized resource object, where the container control at least includes: container suspension, container restart, container deletion. For the principle and advantages, please refer to step S230 of the second embodiment of the container management method, and refer to the second control module of the second embodiment of the container management apparatus for the module structure.
Second configuration module of second embodiment of container management device
Fig. 7A shows a configuration module structure of a second embodiment of the container management apparatus, which includes the following modules:
the type configuration module 6110 is used to configure the customized resource object type. For the principles and advantages, reference is made to step S2110 of a configuration method of the second embodiment of the container management method.
The attribute configuration module 61120 is used for configuring the attribute parameters of the customized resource object and registering in kubernets, so that kubernets can monitor and manage the resource object. For the principles and advantages, reference is made to step S2120 of a configuration method of an embodiment two of a container management method.
An instance configuration module 61130 for configuring instances of custom resource objects, and deployed into kubernets. Please refer to step S2130 of the configuration method of the second embodiment of the container management method.
The control configuration module 61140, which is used to configure the corresponding container controller instance, runs in kubernets. Please refer to step S2140 of the configuration method of the second embodiment of the container management method.
(second monitoring module of second embodiment of container management device)
Fig. 7B shows a structure of a monitoring module of a second embodiment of the container management apparatus, which includes the following modules:
the event monitoring module 6210 is configured to monitor the customized resource object through kubernets API by the Reflector. Please refer to step S2210 of the monitoring method of the second embodiment of the container management method.
The event storage module 6220 is configured to store the monitored update event of the customized resource object into the delta fifo queue by the Reflector. Please refer to step S2220 of the monitoring method in the second embodiment of the container management method.
An event fetching module 6230 is used for the Informer to fetch the self-defined resource object and its update event from the DeltaFIFO queue. For the principle and advantages, refer to step S2230 of the monitoring method of the second embodiment of the container management method.
The event cache module 6240 is used for the Informer to query the customized resource object in the Indexer, and if the customized resource object does not exist, create it in the Indexer. Please refer to step S2240 of the monitoring method according to the second embodiment of the container management method.
The event distribution module 6250 is used for the Informer to distribute the update event to the corresponding container controller instance in a customized resource object instance manner. Please refer to step S2250 of the monitoring method according to the second embodiment of the container management method.
(second control module of second embodiment of container management device)
Fig. 7C shows a structure of a control module of a second embodiment of the container management apparatus, which includes the following modules:
the operation parsing module 6310 is configured to parse the update event of the customized resource object and determine a desired operation of the customized resource object. Please refer to step S2310 of the control method of the second embodiment of the container management method.
A container control module 6320 for invoking a Dockers API interface to perform the container control based on the desired operation. Please refer to step S2320 of the control method of the second embodiment of the container management method.
A state updating module 6330, configured to update the state of the custom resource object in ThreadSafeStore based on the desired operation. For the principle and advantages, refer to step S2330 of the control method of the second embodiment of the container management method.
In summary, in kubernets, the second configuration module of the second embodiment of the container management apparatus customizes the resource object and the corresponding container controller instance through CRD, and the second control module controls the container by using the container controller instance to implement the functions including at least container suspension and restart, so that in the physical resource-limited device, the container is quickly suspended and quickly restored, and the resource utilization rate is improved.
[ calculating device ]
The invention also provides a computing device, which is described in detail in the following fig. 8.
The computing device 800 includes a processor 810, a memory 820, a communication interface 830, and a bus 840.
It is to be appreciated that the communication interface 830 in the computing device 800 illustrated in this figure can be utilized to communicate with other devices.
The processor 810 may be coupled to the memory 820. The memory 820 may be used to store the program codes and data. Therefore, the memory 820 may be a storage unit inside the processor 810, may be an external storage unit independent of the processor 810, or may be a component including a storage unit inside the processor 810 and an external storage unit independent of the processor 810.
Optionally, computing device 800 may also include a bus 840. The memory 820 and the communication interface 830 may be connected to the processor 810 through a bus 840. The bus 840 may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The bus 840 may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one line is shown, but this does not represent only one bus or one type of bus.
It should be understood that, in the embodiment of the present invention, the processor 810 may employ a Central Processing Unit (CPU). The processor may also be other general purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. Or the processor 810 adopts one or more integrated circuits for executing related programs to implement the technical solutions provided by the embodiments of the present invention.
The memory 820 may include both read-only memory and random access memory, and provides instructions and data to the processor 810. A portion of the processor 810 may also include non-volatile random access memory. For example, the processor 810 may also store information of the device type.
When the computing device 800 is run, the processor 810 executes the computer-executable instructions in the memory 820 to perform the operational steps of the various method embodiments.
It should be understood that the computing device 800 according to the embodiment of the present invention may correspond to a corresponding main body for executing the method according to the embodiments of the present invention, and the above and other operations and/or functions of each module in the computing device 800 are respectively for implementing corresponding flows of each method of the embodiment, and are not described herein again for brevity.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the embodiments provided in the present invention, it should be understood that the disclosed system, apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. The storage medium includes various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
[ computational Medium ]
Embodiments of the present invention also provide a computer-readable storage medium having stored thereon a computer program for performing, when executed by a processor, the operational steps of the method embodiments.
Computer storage media for embodiments of the invention may employ any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer-readable storage medium include an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in more detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention.