A Kubernetes scheduling method
By deploying management components in kubernetes and configuring aggregation calculation rules for real-time resource utilization, the scheduler intervenes in the pre-selecting and selection stages, solving the problem that schedulers are difficult to schedule according to real-time resource utilization in the prior art, and achieving more accurate and consistent scheduling results.
Patent Information
- Application Number
- CN202210281744.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-21
- Publication Date
- 2025-06-20
- Estimated Expiration
- 2042-03-21
AI Technical Summary
In actual application scenarios, existing kubernetes schedulers are difficult to schedule according to real-time resource utilization, resulting in a large deviation from the user's expected results, and custom scheduling strategies are difficult to apply to most usage scenarios.
By deploying a management component in kubernetes and configuring aggregation calculation rules for real-time resource utilization, the scheduler intervenes based on the real-time resource utilization of nodes during the pre-selecting and selection stages, filters high-load nodes and calculates the node's score value based on the metric value and weight of real-time resource utilization.
It realizes flexible scheduling based on real-time resource utilization, which is suitable for most usage scenarios, improving the accuracy and consistency of scheduling results.
Smart Images

Figure CN114637575B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Internet technologies, and more specifically, to a kubernetes scheduling method. Background Art
[0002] Kubernetes is a portable and extensible open-source platform for managing containerized workloads and services. In Kubernetes, scheduling refers to placing Pods on appropriate Nodes (nodes), and then the Kubelet on the corresponding node can run these pods. Under the default configuration, the Kubernetes scheduler can meet most requirements, such as ensuring that pods are only assigned to nodes with sufficient resources, spreading Pods in the same set across different computing nodes, and balancing the resource utilization rates of different nodes. However, in most actual application scenarios, different resource measurement strategies are required to determine the scheduling conditions and priorities, and the default scheduler does not perform scheduling based on real-time resource utilization, which may lead to a large deviation between the scheduling result and the result expected by the actual user. In the prior art, most manufacturers provide custom scheduling strategies, and the scheduling strategies adjusted according to certain usage scenarios are difficult to apply to most usage scenarios. Summary of the Invention
[0003] The technical problem to be solved by the present invention is the above-mentioned deficiencies of the prior art. The object of the present invention is to provide a kubernetes scheduling method that can be applied to most usage scenarios.
[0004] The technical solution of the present invention is: a kubernetes scheduling method, in which the scheduler intervenes in the scheduling preselection stage and the preference stage according to the real-time resource utilization rate of the nodes.
[0005] As a further improvement, the scheduling specifically includes the following steps:
[0006] Step S1. Deploy a management component for processing scheduling metric transactions through a deployment; an administrator sets scheduling metric parameters through a configuration file, and the metric parameters include a metric name, a metric expression, a metric threshold, a metric weight, a prometheus rules rule, and a real-time resource utilization rate metric, and the real-time resource utilization rate metric includes at least one of a CPU real-time utilization rate, a memory real-time utilization rate, a storage resource real-time utilization rate, and a GPU real-time resource utilization rate;
[0007] Step S2. When the management component is initialized, it modifies the prometheus recordingrules according to the configuration file, configures the aggregation operation rules, and then executes the configuration hot - loading instruction to make promethues aware that the configuration has been modified and run with the new configuration file;
[0008] Step S3. Prometheus aggregates and calculates the aggregated metric values according to the sampling interval and returns the already calculated results;
[0009] Step S4. The management component starts a scheduled task, periodically collects the metric values in Step S3, traverses all node metrics in the cluster, extracts the metric names and sampling times of the node metrics, and formats and outputs them into a string in combination with the metric thresholds and metric weight values of the metric parameters in Step S1; sends a request through the kubernetes API Server to inject the metric names and the formatted strings into the corresponding node annotations in the form of key - value pairs;
[0010] Step S5. When the metric values of all nodes are greater than the threshold, the metric thresholds of all nodes are adjusted to the maximum value so that the subsequent pre - selection phase skips these metric values and enters the optimal selection phase for scoring;
[0011] Step S6. The scheduler listens for pod resource creation requests. In the pre - selection phase, it filters out high - load nodes;
[0012] Step S7. In the optimal selection phase, according to the weights of the real - time resource utilization metric values in the node annotations injected in Step S4, calculates the scoring values of each node;
[0013] Step S8. The scheduler selects the node with the highest score according to the current scoring rules and binds the pod to this node.
[0014] Further, in Step S1, the metric expression is an aggregation expression or an existing metric name.
[0015] Further, in Step S6, the pre - selection algorithm includes: checking whether the node annotation is a scheduling metric annotation and whether it has a custom prefix defined by the scheduler. If it is a scheduling metric annotation, then check whether the metric parameter format is legal. If it is not legal, skip the current scheduling and allow it to enter the optimal selection phase.
[0016] Further, in Step S6, the pre - selection algorithm includes: checking the metric sampling time of the real - time resource utilization metric in the node annotation injected in Step S4 compared with the current time. If it is greater than twice the sampling time, the metric value is invalid, skip the current scheduling and allow it to enter the optimal selection phase.
[0017] Further, in step S6, the preselection algorithm includes: checking whether the metric value of the resource utilization metric in the node annotation injected in step S4 is greater than the corresponding threshold. If it is greater than the threshold, skip this node and continue to perform scheduling on other nodes.
[0018] Further, in step S7, the optimization algorithm includes: checking whether the node annotation is a scheduling metric annotation and whether it has a scheduler custom prefix. If it is a scheduling metric annotation, check whether the metric parameter format is legal. If it is not legal, skip the current scoring and the score is 0.
[0019] Further, in step S7, the optimization algorithm includes: checking the metric sampling time of the real-time resource utilization metric in the node annotation injected in step S4 compared with the current time. If it is greater than twice the sampling time, the metric value is invalid, then skip the current scoring and the score is 0.
[0020] Further, in step S7, the optimization algorithm includes a scoring algorithm:
[0021] score = ∑((1 - m i ) * w i * 100) / ∑w i
[0022] where m i is a single metric value, w i is a single metric weight, and score should be between 0 and 100.
[0023] Further, if there are multiple nodes with the highest scores, randomly select one of the nodes with the highest scores and bind the pod to this node.
[0024] Beneficial effects
[0025] Compared with the prior art, the advantages of the present invention are:
[0026] By flexibly configuring the real-time resource utilization aggregation calculation rule, the present invention does not require modifying the scheduler. By modifying the aggregation operation rule, the scheduling strategy can be adjusted, and the metric threshold and weight can be flexibly adjusted according to the actual application scenario, which is applicable to most usage scenarios. Description of the drawings
[0027] Figure 1 is a flowchart of the present invention;
[0028] Figure 2 is a relationship diagram of the scheduler, scheduler-manager, and Prometheus in the present invention. Detailed implementation manners
[0029] The present invention will be further described below with reference to specific embodiments in the accompanying drawings.
[0030] Refer to Figure 1 and 2 , a kubernetes scheduling method, where the scheduler intervenes in the scheduling pre-selection phase and the optimization phase according to the real-time resource utilization rate of the nodes.
[0031] The scheduling specifically includes the following steps:
[0032] Step S1. Deploy a management component scheduler-manager for processing scheduling metric transactions through deployment; the administrator sets scheduling metric parameters through a configuration file, and the metric parameters include metric name, metric expression, metric threshold, metric weight, prometheus rules, and real-time resource utilization metrics. The real-time resource utilization metrics include at least one of CPU real-time utilization rate, memory real-time utilization rate, storage resource real-time utilization rate, and GPU real-time resource utilization rate; the metric expression can be an existing metric name or an aggregation expression; the configuration file is as follows:
[0033]
[0034]
[0035]
[0036] Step S2. When the management component scheduler-manager is initialized, it modifies the prometheus recording rules according to the configuration file, configures the aggregation operation rules, and then executes the configuration hot reload instruction to make promethues aware that the configuration has been modified and runs with the new configuration file; among them, prometheus is an open-source system monitoring and alerting system, natively supporting cloud environments and seamlessly docking with kubernetes; recording rules is an expression that is set in advance and takes a relatively long time to calculate or is frequently calculated, and its result is saved as a new set of time series data; the promethues hot reload command is: curl -XPOST <prometheus-url> / - / reload, where prometheus-url is the base address exposed by Prometheus;
[0037] Step S3. Prometheus aggregates and calculates the aggregated metric values according to the sampling interval and returns the already calculated results;
[0038] Step S4. The management component scheduler-manager starts a scheduled task, for example, scheduled every 5 minutes. Every 5 minutes, it collects the metric values in Step S3, traverses all node metrics in the cluster, extracts the metric names and sampling times of the node metrics, and formats and outputs them into a string in combination with the metric thresholds and metric weight values of the metric parameters in Step S1; It sends a request through the kubernetes API Server to inject the metric names and the formatted strings into the corresponding node annotations in the form of key-value pairs; The following is a way of formatting the string combination, and the parameter information is separated by colons:
[0039] caihcloud / scheduler_meticsKey=[meticsValue]:[interval]:[timestamp]:[threshold]:[weight]
[0040] Step S5. When the metric values of all nodes are greater than the threshold, the metric thresholds of all nodes are adjusted to the maximum value, so that the subsequent preselection phase skips the metric values and enters the optimal selection phase for scoring;
[0041] Step S6. The scheduler listens for pod resource creation requests and filters out high-load nodes during the preselection phase;
[0042] Step S7. In the optimal selection phase, calculate the scoring values of each node according to the weight of the real-time resource utilization metric value in the node annotation injected in Step S4;
[0043] Step S8. The scheduler selects the node with the highest score according to the current startup scoring rule and binds the pod to this node; If there are multiple nodes with the highest score, randomly select one of the nodes with the highest score and bind the pod to this node.
[0044] In Step S6, the preselection algorithm includes: checking whether the node annotation is a scheduling metric annotation, whether the node annotation has a custom prefix defined by the scheduler, such as "caihcloud / scheduler_". If it is a scheduling metric annotation, check whether the metric parameter format is legal. If it is not legal, skip the current scheduling and allow entering the optimal selection phase;
[0045] Check whether the metric sampling time of the real-time resource utilization metric in the node annotation injected in step S4 is greater than twice the sampling time compared with the current time. If it is, the metric value is invalid, skip the current scheduling, and allow entering the optimization stage;
[0046] Check whether the metric value of the resource utilization metric in the node annotation injected in step S4 is greater than the corresponding threshold. If it is, skip this node and continue to perform scheduling on other nodes.
[0047] In step S7, the optimization algorithm includes: checking whether the node annotation is a scheduling metric annotation, and whether it has a scheduler custom prefix such as "caihcloud / scheduler_" in the node annotation. If it is a scheduling metric annotation, check whether the metric parameter format is legal. If it is not legal, skip the current scoring and the score is 0;
[0048] Check whether the metric sampling time of the real-time resource utilization metric in the node annotation injected in step S4 is greater than twice the sampling time compared with the current time. If it is, the metric value is invalid, then skip the current scoring and the score is 0;
[0049] Scoring algorithm:
[0050] score = ∑((1 - m i * w i * 100) / ∑w i
[0051] where m i is the single metric value. The larger the metric value, the smaller the probability of scheduling to this node; w i is the single metric weight. score should be between 0 and 100, that is, the larger the score, the greater the probability of scheduling to this node.
[0052] The above is only the preferred implementation manner of the present invention. It should be pointed out that for those skilled in the art, without departing from the structure of the present invention, several deformations and improvements can be made, which will not affect the implementation effect of the present invention and the practicability of the patent.
Claims
1. A kubernetes scheduling method, characterized in that, The scheduler intervenes in the pre-selection phase and the optimal selection phase according to the real-time resource utilization rate of the nodes; The scheduling specifically includes the following steps: Step S1. Deploy a management component for processing scheduling metric transactions through deployment; the administrator sets scheduling metric parameters through a configuration file, and the metric parameters include metric name, metric expression, metric threshold, metric weight, prometheus rules, and real-time resource utilization rate metrics. The real-time resource utilization rate metrics include at least one of CPU real-time utilization rate, memory real-time utilization rate, storage resource real-time utilization rate, and GPU real-time resource utilization rate; Step S2. When the management component is initialized, it modifies the prometheus recordingrules according to the configuration file, configures the aggregation operation rules, and then executes the configuration hot reload instruction to make promethues aware that the configuration has been modified and runs with the new configuration file; Step S3. Prometheus aggregates and calculates the aggregated metric values according to the sampling interval and returns the calculated results; Step S4. The management component starts a timing task, periodically collects the metric values in Step S3, traverses all node metrics in the cluster, extracts the metric names and sampling times of the node metrics, and formats and outputs them into a string in combination with the metric thresholds and metric weight values of the metric parameters in Step S1; sends a request through the kubernetes API Server to inject the metric names and the formatted strings into the corresponding node annotations in the form of key-value pairs; Step S5. When the metric values of all nodes are greater than the threshold, raise the metric thresholds of all nodes to the maximum value so that the subsequent pre-selection phase skips the metric values and enters the optimal selection phase for scoring; Step S6. The scheduler listens for pod resource creation requests. In the pre-selection phase, filter out high-load nodes; Step S7. In the optimal selection phase, calculate the scoring values of each node according to the metric value weights of the real-time resource utilization rate metrics in the node annotations injected in Step S4; Step S8. The scheduler selects the node with the highest score according to the current startup scoring rules and binds the pod to this node.
2. The kubernetes scheduling method according to claim 1, characterized in that, In Step S1, the metric expression is an aggregation expression or an existing metric name.
3. The kubernetes scheduling method according to claim 1, characterized in that, In Step S6, the pre-selection algorithm includes: checking whether the node annotation is a scheduling metric annotation and whether it has a custom prefix defined by the scheduler. If it is a scheduling metric annotation, check whether the metric parameter format is legal. If it is not legal, skip the current scheduling and allow entry into the optimal selection phase.
4. The kubernetes scheduling method according to claim 1, characterized in that, In Step S6, the pre-selection algorithm includes: checking the metric sampling time of the real-time resource utilization rate metric in the node annotation injected in Step S4 compared with the current time. If it is greater than twice the sampling time, the metric value is invalid, skip the current scheduling, and allow entry into the optimal selection phase.
5. The kubernetes scheduling method according to claim 1, characterized in that, In step S6, the preselection algorithm includes: checking whether the metric value of the resource utilization metric in the node annotation injected in step S4 is greater than the corresponding threshold. If it is greater than the threshold, skip this node and continue to perform scheduling on other nodes.
6. The kubernetes scheduling method according to claim 1, characterized in that, In step S7, the optimization algorithm includes: checking whether the node annotation is a scheduling metric annotation and whether it has a scheduler custom prefix. If it is a scheduling metric annotation, check whether the metric parameter format is legal. If it is illegal, skip the current scoring and the score is 0.
7. The kubernetes scheduling method according to claim 1, characterized in that, In step S7, the optimization algorithm includes: checking the metric sampling time of the real-time resource utilization metric in the node annotation injected in step S4 compared with the current time. If it is greater than twice the sampling time, the metric value is invalid, then skip the current scoring and the score is 0.
8. The kubernetes scheduling method according to claim 1, characterized in that, In step S7, the optimization algorithm includes a scoring algorithm: score = ∑((1 - m i ) * w i * 100) / ∑w i where m i is a single index value, w i is a single index weight, and score should be between 0 and 100.
9. The kubernetes scheduling method according to claim 1, characterized in that, If there are multiple nodes with the highest scores, randomly select one of the nodes with the highest scores and bind the pod to this node.
Citation Information
Patent Citations
Container scheduling method associated with time based on Kubernetes container cluster
CN109783218A