Search

CN-121996346-A - Container pool expansion and contraction method, system, device, storage medium and program product

CN121996346ACN 121996346 ACN121996346 ACN 121996346ACN-121996346-A

Abstract

The embodiment of the application provides a container pool expansion and contraction method, a system, equipment, a storage medium and a program product. According to the method, a container pool construction thought based on an elastic resource instance and an elastic expansion and contraction thought based on a declaration are fused, the problem that the elastic expansion and contraction capacity of the container pool is limited by the number of resource nodes is solved by means of the elasticity and flexibility of the elastic resource instance, the elastic expansion and contraction capacity based on the declaration refers to the process of expanding and contracting the container pool based on the state and the number of containers in the container pool and matched with the expansion and contraction conditions and expansion and contraction stepping parameters which are configured in advance, prediction of future task quantity is not relied on, the elastic expansion and contraction capacity of the container pool is not limited by the precision of a prediction algorithm, expansion and contraction operation can be carried out on the container pool more flexibly, expansion and contraction capacity of the container pool is stronger and more flexible, and therefore the situations of more or insufficient free containers are reduced, resource waste is reduced, and user experience is improved.

Inventors

  • CHEN ZEFENG
  • DING YU

Assignees

  • 阿里云计算有限公司

Dates

Publication Date
20260508
Application Date
20241106

Claims (18)

  1. 1. The expansion and contraction method of a container pool is characterized in that the container pool is borne on an elastic resource instance, the elastic resource instance is obtained by virtualizing resource nodes in a container cluster, the container pool is configured with expansion and contraction conditions and expansion and contraction stepping parameters, and the method comprises the following steps: Monitoring the state and the number of containers in the container pool during the operation of the container pool, wherein the state and the number of the containers are dynamically changed; If the container pool meets the capacity expansion condition according to the state and the number of the containers, determining the capacity expansion step length according to the capacity expansion step parameters, and expanding the capacity of the container pool according to the capacity expansion step length; And if the container pool meets the capacity reduction condition according to the state and the number of the containers, determining the capacity reduction step length according to the capacity reduction step parameters, and carrying out capacity reduction on the container pool according to the capacity reduction step length.
  2. 2. The method of claim 1, wherein the expansion condition comprises a first container occupancy threshold, the contraction condition comprises a second container occupancy threshold and a preset duration, the second container occupancy threshold is less than the first container occupancy threshold, the method further comprising: Determining the container occupancy rate of the container pool according to the state and the number of the containers, wherein the container occupancy rate refers to the ratio of the number of the containers in a use state to the total number of the containers; if the container occupancy rate is greater than or equal to the first container occupancy rate threshold value, determining that the container pool meets the capacity expansion condition; and if the container occupancy rate is smaller than or equal to the second container occupancy rate threshold value and lasts for the preset duration, determining that the container pool meets the capacity reduction condition.
  3. 3. The method of claim 1, wherein the step-by-step expansion parameter comprises a step-by-step expansion ratio value and a step-by-step expansion lower limit, and determining the step-by-step expansion according to the step-by-step expansion parameter comprises: Calculating a first basic step length according to the number of the containers and the expansion ratio value; And selecting the larger one from the first basic step length and the capacity expansion step length lower limit value as the capacity expansion step length.
  4. 4. The method of claim 1, wherein the step size parameter comprises a step size ratio value and a step size upper limit value, and determining the step size according to the step size parameter comprises: Calculating a second basic step length according to the number of the containers and the volume reduction ratio value; and selecting the smaller one from the second basic step length and the volume reduction step length upper limit value as the volume reduction step length.
  5. 5. The method of any one of claims 1-4, wherein expanding the reservoir according to the expansion step comprises: obtaining a pre-created container snapshot, wherein the container snapshot comprises a basic container environment and a tool kit installed in the basic container environment, and tools required for deploying tasks in a container are included in the tool kit; and creating new containers with the capacity expansion step size in the container pool by using the container snapshot so as to expand the container pool.
  6. 6. The method of claim 5, wherein pre-creating the container snapshot comprises: Creating a base container according to the mirror image file of the container, wherein the base container provides a base container environment; Installing a tool pack in the base container, and creating a snapshot for the base container on which the tool pack is installed as the container snapshot.
  7. 7. The method of any of claims 1-4, wherein collapsing the reservoir according to the collapsing step size comprises: Selecting the idle containers with the shrinking step length from the container pool according to the states of the containers in the container pool; and deleting the idle containers with the shrinking step length from the container pool so as to shrink the container pool.
  8. 8. The method of claim 7, wherein selecting the step size free containers from the pool of containers based on the status of the containers in the pool of containers comprises: And selecting the idle containers with the earliest creation time from the container pool according to the states and the creation time of the containers in the container pool, or randomly selecting the idle containers with the earliest creation time from the container pool according to the states of the containers in the container pool.
  9. 9. The method of any one of claims 1-4, further comprising: Under the condition of receiving a user task, inquiring whether an idle container exists in the container pool; if the container pool has an idle container, deploying the user task in a first container in the idle container, and updating the state of the first container from the idle state to the using state; And if no free container exists in the container pool, a container creation interface provided by the container cluster is called to create a second container on the resource nodes in the container cluster, and the user task is deployed in the second container.
  10. 10. The container pool system is characterized by comprising a container pool, a service end node and a control node, wherein the container pool is borne on an elastic resource instance, and the elastic resource instance is obtained by virtualizing resource nodes in a container cluster; The control node is used for monitoring the state and the quantity of the containers in the container pool in the operation process of the container pool and reporting the state and the quantity of the containers to the server node, wherein the state and the quantity of the containers are dynamically changed; the server node is used for configuring expansion and contraction conditions and expansion and contraction stepping parameters of the container pool, receiving the states and the quantity of the containers reported by the control node, determining expansion step length according to the expansion stepping parameters if the container pool meets the expansion conditions according to the states and the quantity of the containers, expanding the container pool according to the expansion step length, determining contraction step length according to the contraction stepping parameters if the container pool meets the contraction conditions according to the states and the quantity of the containers, and contracting the container pool according to the contraction step length.
  11. 11. The system of claim 10, wherein the server node expands the container pool according to the expansion step size, comprising generating an expansion task according to the expansion step size, providing the expansion task to the control node for the control node to execute the expansion task, wherein the expansion task indicates to expand the container pool according to the expansion step size; The server node performs the capacity reduction on the container pool according to the capacity reduction step length, and the method comprises the steps of generating a capacity reduction task according to the capacity reduction step length, providing the capacity reduction task for the control node so as to enable the control node to execute the capacity reduction task, and enabling the capacity reduction task to instruct the container pool to perform capacity reduction according to the capacity reduction step length.
  12. 12. The system of claim 11, wherein the server node comprises: a creation module for creating the container pool on the elastic resource instance; the configuration module is used for configuring the expansion and contraction conditions and expansion and contraction stepping parameters of the container pool; The decision module is used for receiving the state and the quantity of the containers reported by the control node and determining whether the container pool meets the capacity expansion condition or the capacity contraction condition according to the state and the quantity of the containers; And the task processing module is used for determining the capacity expansion step length according to the capacity expansion step length under the condition that the decision module determines that the container pool meets the capacity expansion condition, generating a capacity expansion task according to the capacity expansion step length and providing the capacity expansion task for the control node, or determining the capacity reduction step length according to the capacity reduction step length under the condition that the decision module determines that the container pool meets the capacity reduction condition, generating a capacity reduction task according to the capacity reduction step length and providing the capacity reduction task for the control node.
  13. 13. The system of claim 12, wherein the server node further comprises: The task scheduling module is used for receiving user tasks and inquiring whether idle containers exist in the container pool or not under the condition that the user tasks are received, if the idle containers exist in the container pool, the user tasks are deployed in a first container in the idle containers, the state of the first container is updated from the idle state to the using state, and if the idle containers do not exist in the container pool, a container creation interface provided by a container cluster is called to create a second container on a resource node in the container cluster, and the user tasks are deployed in the second container.
  14. 14. The system of claim 11, wherein the control node comprises: The monitoring module is used for monitoring the state and the quantity of the containers in the container pool in the running process of the container pool and reporting the state and the quantity of the containers to the server node; And the task execution module is used for acquiring the capacity expansion task provided by the service end node, executing the capacity expansion task to expand the container pool according to the capacity expansion step length, or acquiring the capacity reduction task provided by the service end node, and executing the capacity reduction task to reduce the container pool according to the capacity reduction step length.
  15. 15. The system of any of claims 11-14, further comprising the container cluster exposing a container creation interface to the server node for the server node to invoke the container creation interface to create a container in the container pool.
  16. 16. An electronic device comprising a memory and a processor, the memory for storing a computer program, the processor coupled to the memory for executing the computer program for implementing the steps in the method of any of claims 1-9.
  17. 17. A computer readable storage medium comprising a computer program/instructions which, when executed by a processor, cause the processor to carry out the steps of the method of any one of claims 1 to 9.
  18. 18. A computer program product comprising computer programs/instructions which, when executed by a processor, cause the processor to carry out the steps of the method of any of claims 1-9.

Description

Container pool expansion and contraction method, system, device, storage medium and program product Technical Field The present application relates to the field of cloud computing technologies, and in particular, to a method, a system, an apparatus, a storage medium, and a program product for expanding and shrinking a container pool. Background In a cloud computing environment, different tasks can provide different services for users by executing different code logics, for example, compiling tasks, code scanning tasks, automatic testing tasks and the like are involved in pipeline products from code development to deployment in power-assisted enterprises, and editing services, code scanning services and automatic testing services can be provided for users by executing different code logics. In order to realize the security isolation between different tasks, when a user submits a task, a container carrying the task can be created on a Node (Node) in a K8s (Kubernetes) cluster, and the different tasks are deployed and run in different containers. The creation process of the container involves allocation of a Virtual Machine (VM), application of an IP address, loading of an image file, and the like, which takes a long time, results in a long task start time, and is poor in user experience. For this purpose, the prior art proposes the concept of a container pool, i.e. creating a container pool in advance on nodes in a K8s cluster and dynamically adjusting the number of containers in the container pool by predicting the amount of tasks in a future period of time. Therefore, when a user submits a task, an idle container can be directly obtained from the container pool, the task is arranged in the idle container after the related tool package is downloaded in the idle container, the container creation process is saved, the starting time of the user task is shortened, and the user experience is improved. However, the existing container pool has insufficient elastic expansion capacity and poor flexibility, so that the situation that the number of idle containers is large or insufficient easily occurs, and the resource waste or the user experience is reduced. Disclosure of Invention Aspects of the present application provide a method, a system, an apparatus, a storage medium, and a program product for expanding and shrinking a container pool, which are used for improving the capacity of elastic expansion and shrinking of the container pool, reducing situations of more or insufficient idle containers as much as possible, reducing resource waste, and improving user experience. The embodiment of the application provides a container pool expansion and contraction method, wherein the container pool is borne on an elastic resource instance, the elastic resource instance is obtained by virtualizing resource nodes in a container cluster, the container pool is configured with expansion and contraction conditions and expansion and contraction stepping parameters, the method comprises the steps of monitoring the states and the numbers of containers in the container pool in the operation process of the container pool, dynamically changing the states and the numbers of the containers, determining an expansion step length according to the expansion stepping parameters if the container pool meets the expansion conditions according to the states and the numbers of the containers, expanding the container pool according to the expansion step length, determining a contraction step length according to the contraction stepping parameters if the container pool meets the contraction conditions according to the states and the numbers of the containers, and expanding the container pool according to the contraction step length. The embodiment of the application also provides a container pool system which comprises a container pool, a service end node and a control node, wherein the container pool is borne on an elastic resource instance, the elastic resource instance is obtained by virtualizing resource nodes in a container cluster, the control node is used for monitoring the state and the quantity of containers in the container pool in the operation process of the container pool, reporting the service end node, the state and the quantity of the containers are dynamically changed, the service end node is used for configuring expansion and contraction conditions and expansion and contraction step parameters of the container pool, receiving the state and the quantity of the containers reported by the control node, determining expansion step length according to the expansion step length if the container pool meets the expansion conditions according to the state and the quantity of the containers, expanding the container pool according to the expansion step length, determining contraction step length according to the contraction step length if the container pool meets the contraction step parameters, and expanding the container pool according to t