K8s micro-service scheduling method and device, storage medium and computer equipment
By obtaining the image size and resource utilization of microservices, adjusting the weight of the scoring plug-in, and calculating the final score of the scheduling node in combination with the type tag, the problem of uneven resource allocation of the K8s scheduler in different exclusive pools is solved, and the resource utilization and scheduling accuracy are improved.
Patent Information
- Application Number
- CN202510584794.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-07
- Publication Date
- 2025-08-01
AI Technical Summary
The unified scheduling algorithm of existing K8s schedulers is difficult to take into account the specific needs of different exclusive pools, resulting in uneven resource allocation and low utilization.
By obtaining the image size of the microservice and the resource utilization of the exclusive pool, adjusting the scoring plug-in's scoring weight, and combining the type tags of the microservices, the final score of the scheduling node is calculated to achieve refined scheduling.
It improves resource utilization and scheduling accuracy, meets the specific needs of different exclusive pools, and achieves uniform distribution of resources and diversified adaptation of business needs.
Smart Images

Figure CN120407119A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of cloud computing technology, and particularly to a K8s microservice scheduling method, apparatus, storage medium, and computer device. Background Art
[0002] With the rapid development of cloud computing technology, Kubernetes (K8s), as a leader in the field of container orchestration, has become the preferred platform for enterprises to build cloud-native applications. Through its powerful scheduling system, K8s can efficiently manage thousands of microservice instances, ensuring their reasonable distribution and efficient operation in the cluster. However, with the increasing complexity of the microservice architecture and the continuous expansion of the cluster scale, how to further optimize the microservice scheduling strategy and improve the utilization efficiency of machine resources has become an urgent problem to be solved.
[0003] Currently, the K8s scheduler mainly determines the scheduling location of Pods through two stages: pre-selection (Predicates) and preference (Priorities). In the pre-selection stage, a series of mandatory rules are used to filter out nodes that do not meet the conditions, while in the preference stage, the remaining nodes are sorted based on node priorities, and finally the optimal node is selected to deploy the Pod. Although this process is effective, the unified scheduling algorithm is difficult to take into account the specific requirements of different dedicated pools (i.e., node sets for different usage scenarios), resulting in uneven resource allocation and low utilization rate. Summary of the Invention
[0004] The purpose of this application aims to at least solve one of the above technical defects, especially the technical defect that the unified scheduling algorithm in the prior art is difficult to take into account the specific requirements of different dedicated pools, resulting in uneven resource allocation and low utilization rate.
[0005] This application provides a K8s microservice scheduling method, and the method includes:
[0006] Obtain the image size of the microservice to be scheduled and the resource utilization rate of the dedicated pool corresponding to the microservice;
[0007] After adjusting the scoring weights of each scoring plugin according to the image size and the resource utilization rate, use each scoring plugin to determine the plugin score of each scheduling node in the dedicated pool;
[0008] Determine the type label of the microservice, and determine the label score of each scheduling node on the type label;
[0009] Sum up the plugin scores and label scores of each scheduling node to obtain the final score of each scheduling node, and schedule the microservice to the scheduling node with the highest final score.
[0010] Optionally, adjusting the scoring weight of each scoring plugin according to the mirror size and the resource utilization rate includes:
[0011] Determining the initial weights of the respective scoring plugins according to the resource utilization rate;
[0012] Adjusting the initial weights of the respective scoring plugins according to the mirror size to obtain the final scoring weight of each scoring plugin.
[0013] Optionally, the scoring plugins include a resource balancing plugin, a mirror caching plugin, and an idle resource plugin;
[0014] The determining the initial weights of the respective scoring plugins according to the resource utilization rate includes:
[0015] Judging whether the resource utilization rate exceeds the utilization rate threshold;
[0016] If so, determining the initial weights of the respective scoring plugins according to the resource priority reorganization; in the resource priority reorganization, the weight of the idle resource plugin is greater than the weights of the resource balancing plugin and the mirror caching plugin;
[0017] If not, determining the initial weights of the respective scoring plugins according to the default weight reorganization; in the default weight reorganization, the weights of the respective scoring plugins are equal.
[0018] Optionally, the adjusting the initial weights of the respective scoring plugins according to the mirror size to obtain the final scoring weight of each scoring plugin includes
[0019] Judging whether the mirror size exceeds the mirror threshold;
[0020] If so, multiplying the initial weight of the mirror caching plugin by a multiple and using the adjusted initial weight of the mirror caching plugin and the initial weights of the other scoring plugins as the final scoring weights;
[0021] If not, using the initial weights of the respective scoring plugins as the final scoring weights.
[0022] Optionally, determining the type label of the microservice includes:
[0023] Extracting the dependencies between the respective microservices from the dedicated pool, constructing a service call matrix according to the dependencies, and reducing the dimension of the service call matrix to a two-dimensional matrix by using the PCA dimensionality reduction method;
[0024] Using the K-means nearest neighbor algorithm to perform label classification on the two-dimensional matrix to obtain a classification result; the classification result includes multiple type labels, and each type label corresponds to at least one microservice;
[0025] Determine the type label of the microservice according to the classification result.
[0026] Optionally, the K-means nearest neighbor algorithm is used to classify the two-dimensional matrix to obtain a classification result, including:
[0027] Set the value of K according to the number of service types in the dedicated pool, and randomly initialize the centroid based on the value of K;
[0028] Allocate the microservices corresponding to each data point in the two-dimensional matrix to the cluster of the nearest mass point through the Euclidean distance, and recalculate the mass point of each cluster until convergence;
[0029] Allocate corresponding type labels to each cluster to obtain a classification result.
[0030] Optionally, determining the label score of each scheduling node on the type label includes:
[0031] Determine the total number of microservices corresponding to the type label in the dedicated pool, and the number of microservices corresponding to the type label on each scheduling node;
[0032] For each scheduling node, calculate the ratio of the number of microservices of this scheduling node to the total number of microservices, and use the ratio as the label score of this scheduling node on the type label.
[0033] This application also provides a K8s microservice scheduling device, including:
[0034] A data acquisition module for acquiring the image size of the microservice to be scheduled and the resource utilization rate of the dedicated pool corresponding to the microservice;
[0035] A plugin score determination module for adjusting the scoring weights of each scoring plugin according to the image size and the resource utilization rate, and then using each scoring plugin to determine the plugin score of each scheduling node in the dedicated pool;
[0036] A label score determination module for determining the type label of the microservice and determining the label score of each scheduling node on the type label;
[0037] A microservice scheduling module for summing the plugin scores and label scores of each scheduling node to obtain the final score of each scheduling node, and scheduling the microservice to the scheduling node with the highest final score.
[0038] The present application also provides a storage medium, in which computer-readable instructions are stored. When the computer-readable instructions are executed by one or more processors, the one or more processors are caused to execute the steps of the K8s microservice scheduling method according to any one of the above embodiments.
[0039] The present application also provides a computer device, including: one or more processors, and a memory;
[0040] Computer-readable instructions are stored in the memory. When the computer-readable instructions are executed by the one or more processors, the steps of the K8s microservice scheduling method according to any one of the above embodiments are executed.
[0041] As can be seen from the above technical solutions, the embodiments of the present application have the following advantages:
[0042] For the K8s microservice scheduling method, device, storage medium and computer device provided by the present application, when scheduling microservices, the image size of the microservices to be scheduled and the resource utilization rate of the dedicated pool corresponding to the microservices can be obtained first, so that different scheduling measures can be adopted according to the specific requirements of different dedicated pools; here, the scoring weights of each scoring plugin can be adjusted according to the image size and resource utilization rate, and each scoring plugin is used to determine the plugin score of each scheduling node in the dedicated pool, so as to realize the adaptive adjustment of the weights of each scoring plugin and improve the adaptability of the application scenario. In addition, since the relevance of each microservice is different, the type label of the microservice can be determined, and the label score of each scheduling node on the type label can be determined, so that the mutual call relationship between microservices can be specified, and thus diverse business requirements can be met; finally, the plugin scores and label scores of each scheduling node can be summed to obtain the final score of each scheduling node, and the microservice is scheduled to the scheduling node with the highest final score, so as to improve the refined scheduling ability of different dedicated pool usage scenarios and improve the resource utilization rate while evenly distributing resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0044] Figure 1 It is a schematic flowchart of a K8s microservice scheduling method provided by an embodiment of the present application;
[0045] Figure 2A schematic flowchart of a microservice type label determination process provided by an embodiment of the present application;
[0046] Figure 3 A schematic logical diagram of a K8s microservice scheduling process provided by an embodiment of the present application;
[0047] Figure 4 A schematic structural diagram of a K8s microservice scheduling device provided by an embodiment of the present application;
[0048] Figure 5 A schematic internal structure diagram of a computer device provided by an embodiment of the present application. Detailed implementation manners
[0049] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0050] Currently, the K8s scheduler mainly determines the scheduling location of a Pod through two stages: pre-selection (Predicates) and preference (Priorities). In the pre-selection stage, a series of mandatory rules are used to filter out nodes that do not meet the conditions, while in the preference stage, the remaining nodes are sorted based on node priorities, and finally the optimal node is selected to deploy the Pod. Although this process is effective, the unified scheduling algorithm is difficult to take into account the specific requirements of different dedicated pools (i.e., node sets for different usage scenarios), resulting in uneven resource allocation and low utilization rate.
[0051] Based on this, the present application proposes the following technical solutions. For details, please refer to the following text:
[0052] In some embodiments, the present application can deploy an admission controller in a K8s cluster and create a default template for KubeSchedulerConfiguration to further refine the scheduling of microservices. When deploying the admission controller, it can be implemented through code, then packaged as a Docker image, and deployed in the cluster in the form of a deployment. Subsequently, MutatingWebhookConfiguration can be used to register the admission controller for the packaged Docker image. Therefore, the present application can use the admission controller as a part of the K8s cluster to execute before API requests are persisted, to enhance functions such as security, policy enforcement, and resource usage control. In addition, after the microservices are scheduled, the present application can also adjust the KubeSchedulerConfiguration according to actual requirements, so as to adaptively adjust relevant scoring parameters such as the weights of scoring plugins according to the dedicated pool through the admission controller, thereby achieving rational scheduling.
[0053] In one embodiment, as Figure 1 shown, Figure 1 is a schematic flowchart of a K8s microservice scheduling method provided by an embodiment of the present application; the present application provides a K8s microservice scheduling method, which specifically includes the following:
[0054] S110: Obtain the image size of the microservice to be scheduled and the resource utilization rate of the dedicated pool corresponding to the microservice.
[0055] In this step, when scheduling the microservice, the computer device can first obtain the image size of the microservice to be scheduled and the resource utilization rate of the dedicated pool corresponding to the microservice, so as to adopt different scheduling measures according to the specific requirements of different dedicated pools.
[0056] It can be understood that the image size can reflect the basic resource consumption required for the startup and deployment of the microservice, and is a key indicator for evaluating the scheduling cost and time; while the dedicated pool refers to a set of computing nodes (servers, virtual machines or container instances) divided to meet specific usage scenarios or business requirements, which can reflect the load situation of the target deployment environment and is an important basis for judging whether the scheduling conditions are met. Therefore, by obtaining the image size of the microservice and the resource utilization rate of the dedicated pool, the present application can effectively conduct a comprehensive resource evaluation of the microservice to be scheduled, and then select the most suitable scheduling measure to ensure that the microservice can be started and run in the most appropriate manner in the dedicated pool.
[0057] S120: After adjusting the scoring weights of each scoring plugin according to the image size and resource utilization rate, use each scoring plugin to determine the plugin score of each scheduling node in the dedicated pool.
[0058] In this step, after obtaining the image size and resource utilization rate through step S110, the computer device can adjust the scoring weights of each scoring plugin according to the image size and resource utilization rate, and use each scoring plugin to determine the plugin scores of each scheduling node in the dedicated pool, so as to achieve the adaptive adjustment of the weights of each scoring plugin and improve the adaptability of the application scenario.
[0059] Among them, the scoring plugin refers to a type of key plugin in the kube-scheduler scheduling framework used to score and evaluate candidate nodes. They can score all nodes that meet the preselection conditions, and the score represents the adaptability of the node to the microservice to be scheduled. The higher the score, the more likely it is to be selected as the final scheduling target. The scoring plugins adopted in this application can include a resource balance plugin (Balanced Allocation), an image cache plugin (image locality), and an idle resource plugin (least allocated).
[0060] Specifically, the resource balance plugin can calculate the difference in the usage ratio of CPU and memory on the node and give a score. The higher the score, the more balanced the resource allocation; while the image cache plugin prefers nodes that have cached the container image, thus reducing the image pulling time; and the idle resource plugin can select the node with the lowest resource utilization rate for scheduling to balance the resource usage among nodes.
[0061] Therefore, the computer device can adaptively adjust the scoring weights of each scoring plugin based on these two core indicators of image size and resource utilization rate to dynamically match the scenario requirements of different microservices and dedicated pools, ultimately improving the accuracy of scheduling, resource utilization rate, and service deployment efficiency.
[0062] For example, when the image is large, the computer device can appropriately increase the weight of the image cache plugin to make the scheduling more inclined to select those nodes that have cached the image to shorten the image pulling time; when the resource utilization rate difference is obvious, the computer device can increase the weight of the idle resource plugin to preferentially select nodes with a lower resource utilization rate to reduce the local load, or increase the weight of the resource balance plugin to maintain the balance of node resource usage.
[0063] Specifically, after the computer device adjusts the weights of the scoring plugins, each scoring plugin can score all the scheduling nodes in the dedicated pool. Each plugin can give an original score to a node based on its own logic. For example, the mirror cache plugin can evaluate whether a node has a target mirror copy and score accordingly; the resource balance plugin can measure the balance of a node based on the current usage ratio of its CPU and memory; and the idle resource plugin can score based on the overall idle resources of the node. Subsequently, these original scores will enter a weighted aggregation process, where the score of each scoring plugin is multiplied by its current weight, and after the weighted scores of all plugins are added together, the final plugin score of the scheduling node is formed.
[0064] S130: Determine the type label of the microservice and determine the label score of each scheduling node on the type label.
[0065] In this step, since the relevance of each microservice is different, the computer device can also determine the type label of the microservice and determine the label score of each scheduling node on the type label, so as to specify the mutual call relationship between microservices and meet diverse business requirements.
[0066] It can be understood that during the microservice scheduling process, due to the complex relevance and business coupling degree between different microservices, in addition to considering resource and mirror factors, the computer device can further identify and determine the type label of each microservice. These type labels are usually set based on factors such as the function, service level, communication mode, response latency requirement, and data dependency relationship of the microservice. By introducing type labels, the computer device can more precisely understand the business attributes of microservices and their role positioning in the system.
[0067] For example, for the order service and the payment service, the order service can call the payment service. If they are scattered on different scheduling nodes, network communication will slow down. Therefore, the computer device can determine their type labels according to the service types they are currently running, such as both the order service and the payment service belong to the payment-related group, so as to enhance the service relevance between them. When scheduling a new microservice, the computer device can score the scheduling nodes according to its corresponding type label. The more microservices with this type label exist on the scheduling node, the higher the label score of this node.
[0068] S140: Sum up the plugin scores and label scores of each scheduling node to obtain the final score of each scheduling node, and schedule the microservice to the scheduling node with the highest final score.
[0069] In this step, after obtaining the plugin score and the label score through step S120 and step S130, the computer device can sum up the plugin scores and the label scores of each scheduling node to obtain the final score of each scheduling node, and schedule the microservice to the scheduling node with the highest final score, so as to improve the refined scheduling ability for different dedicated pool usage scenarios, and improve the resource utilization rate while evenly allocating resources.
[0070] It can be understood that the plugin score reflects the adaptability of the scheduling node to the microservice in different dimensions, while the label score reflects the coordination and fit degree of the scheduling node with the microservice at the business semantic level. Therefore, the computer device can add the plugin score and the label score of each node to form a unified final score, which is used to represent the comprehensive adaptability degree of the corresponding scheduling node in the current scheduling task. It not only considers the basic support ability of the node for the current task, but also takes into account the communication dependence and deployment logic between microservices, making the final deployment decision both resource-efficient and business-rational.
[0071] Specifically, after the final scores of all scheduling nodes are calculated, the computer device can select the scheduling node with the highest score from them and deploy the microservice to this node. This can ensure that each scheduling decision is made on the basis of comprehensively measuring the resource status, the relationship between microservices and the business characteristics, thereby significantly improving the refined scheduling ability of the dedicated pool in different business scenarios. Therefore, this application not only realizes the uniform allocation of resources and avoids the concentration of hot spots, but also improves the overall resource utilization efficiency and the collaborative performance of microservice operation through business-aware deployment.
[0072] In the above embodiment, when scheduling the microservice, the mirror size of the microservice to be scheduled and the resource utilization rate of the dedicated pool corresponding to the microservice can be obtained first, so that different scheduling measures can be adopted according to the specific requirements of different dedicated pools; here, the scoring weights of each scoring plugin can be adjusted according to the mirror size and the resource utilization rate, and each scoring plugin is used to determine the plugin score of each scheduling node in the dedicated pool to realize the adaptive adjustment of the weights of each scoring plugin and improve the adaptability of the application scenario. In addition, since the relevance of each microservice is different, the type label of the microservice can be determined, and the label score of each scheduling node on the type label can be determined, so as to specify the mutual call relationship between microservices, and further meet the diverse business requirements; finally, the plugin scores and the label scores of each scheduling node can be summed up to obtain the final score of each scheduling node, and the microservice is scheduled to the scheduling node with the highest final score, so as to improve the refined scheduling ability for different dedicated pool usage scenarios, and improve the resource utilization rate while evenly allocating resources.
[0073] In one embodiment, the process of adjusting the scoring weights of each scoring plugin according to the image size and resource utilization rate in step S120 may include:
[0074] S121: Determine the initial weights of the respective scoring plugins according to the resource utilization rate.
[0075] S122: Adjust the initial weights of the respective scoring plugins according to the image size to obtain the final scoring weights of each scoring plugin.
[0076] In this embodiment, when the computer device adjusts the scoring weights of the scoring plugins, it may first determine the initial weights of the respective scoring plugins according to the resource utilization rate, and then adjust the initial weights of the respective scoring plugins according to the image size to obtain the final scoring weights of each scoring plugin.
[0077] Specifically, the resource utilization rate can reflect the load conditions of the dedicated pool in aspects such as CPU, memory, and disk I / O. By analyzing these metrics, the computer device can predict the current resource bottleneck, and then adjust to obtain the initial weights of the scoring plugins, indicating the scoring priorities of the respective plugins. For example, in a scenario where the node resources are highly strained, the computer device can increase the weights of the plugins related to resource scoring so that the microservices can be preferentially scheduled to nodes with a higher degree of resource idleness.
[0078] Further, after the initial weights of the respective scoring plugins are determined, the computer device can introduce the key parameter of the microservice image size to perform a secondary adjustment on the plugin weights. Here, the image size directly affects the time and efficiency of service deployment. Especially when the image volume is large, the time cost required to pull the image will increase significantly. Therefore, in a scenario where the image is relatively large, the computer device can appropriately increase the weights of the plugins related to image scoring, enhance the preference for the nodes with cached images, thereby shortening the deployment cycle and improving the system response speed.
[0079] In one embodiment, in step S121, the scoring plugins include a resource balancing plugin, an image caching plugin, and an idle resource plugin; wherein, the process of determining the initial weights of the respective scoring plugins according to the resource utilization rate may include:
[0080] S1211: Determine whether the resource utilization rate exceeds the utilization rate threshold.
[0081] S1212: If so, re-determine the initial weights of the respective scoring plugins according to the resource priority reorganization; in the resource priority reorganization, the weight of the idle resource plugin is greater than the weights of the resource balancing plugin and the image caching plugin.
[0082] S1213: If not, determine the initial weights of the respective scoring plugins according to the default weight reorganization; in the default weight reorganization, the weights of the respective scoring plugins are equal.
[0083] In this embodiment, when determining the initial weights of each scoring plugin, the computer device may first determine whether the resource utilization rate exceeds the utilization rate threshold. If it exceeds, the computer device may reorganize the initial weights of each scoring plugin according to the resource priority; if it does not exceed, the computer device may determine the initial weights of each scoring plugin according to the default weight reorganization.
[0084] It should be noted that the scoring plugins of this application include a resource balancing plugin, a mirror cache plugin, and an idle resource plugin. Among them, the weight of the idle resource plugin in the resource priority reorganization is greater than the weights of the resource balancing plugin and the mirror cache plugin. Therefore, in the resource priority reorganization, the computer device can preferentially schedule microservices to more idle scheduling nodes; while in the default weight reorganization, the weights of each scoring plugin are equal, and at this time each scoring plugin remains balanced.
[0085] For example, in a specific scheduling scenario, the utilization rate threshold of the dedicated pool is 70%. When the resource utilization rate of the dedicated pool is greater than 70%, according to the resource priority reorganization, the computer device can adjust the weight of the resource balancing plugin to 0.5, adjust the mirror cache plugin to 0.5, and adjust the weight of the idle resource plugin to 2; when the resource utilization rate of the dedicated pool is not greater than 70%, according to the default weight reorganization, the computer device can adjust the weight of the resource balancing plugin to 1, adjust the mirror cache plugin to 1, and adjust the weight of the idle resource plugin to 1.
[0086] In one embodiment, the process of adjusting the initial weights of each scoring plugin according to the mirror size in step S122 to obtain the final scoring weights of each scoring plugin may include
[0087] S1221: Determine whether the mirror size exceeds the mirror threshold.
[0088] S1222: If so, multiply the initial weight of the mirror cache plugin by a factor and use the adjusted initial weight of the mirror cache plugin and the initial weights of other scoring plugins as the final scoring weights.
[0089] S1223: If not, use the initial weights of each scoring plugin as the final scoring weights.
[0090] In this embodiment, when readjusting the initial weights of each scoring plugin, the computer device may determine whether the mirror size exceeds the mirror threshold. If it exceeds, the computer device may multiply the initial weight of the mirror cache plugin by a factor and use the adjusted initial weight of the mirror cache plugin and the initial weights of other scoring plugins as the final scoring weights; if it does not exceed, the computer device may use the initial weights of each scoring plugin as the final scoring weights.
[0091] It can be understood that when the mirror size exceeds the mirror threshold, it indicates that pulling this mirror will have a greater impact on the scheduling efficiency. At this time, the computer device can perform a multiple-level amplification process on the initial weight of the mirror cache plugin, thereby significantly increasing the influence of this plugin in the comprehensive node score, making the scheduling system more inclined to select those nodes that have cached the target mirror, so as to shorten the mirror transmission time and accelerate the service deployment speed.
[0092] For example, in a specific scheduling scenario, the mirror threshold of a microservice is 1G. When the mirror size of the microservice exceeds 1G, the computer device can adjust the initial weight of the mirror cache plugin to 2 times. At this time, the final score weights of the resource balancing plugin, the mirror cache plugin, and the idle resource plugin are 1, 2, 1, or 0.5, 1, 2; when the mirror size of the microservice does not exceed 1G, the computer device can use the initial weights of each scoring plugin as the final score weights. At this time, the final score weights of the resource balancing plugin, the mirror cache plugin, and the idle resource plugin are 1, 1, 1, or 0.5, 0.5, 2.
[0093] In one embodiment, as Figure 2 shown, Figure 2 is a schematic flowchart of a process for determining a microservice type label provided by an embodiment of the present application; Figure 2 In, the process of determining the type label of the microservice in step S130 may include:
[0094] S131: Extract the dependencies between each microservice from the dedicated pool, construct a service call matrix based on the dependencies, and use the PCA dimensionality reduction method to reduce the service call matrix to a two-dimensional matrix.
[0095] S132: Use the K-means nearest neighbor algorithm to perform label classification on the two-dimensional matrix to obtain a classification result; the classification result includes multiple type labels, and each type label corresponds to at least one microservice.
[0096] S133: Determine the type label of the microservice according to the classification result.
[0097] In this embodiment, when initially determining the type tags of microservices, the computer device can extract the dependency relationships between the microservices from the dedicated pool, construct a service call matrix based on the dependency relationships, and use the PCA (Principal Components Analysis) dimensionality reduction method to reduce the service call matrix to a two-dimensional matrix. Then, the K-means nearest neighbor algorithm is used to classify the two-dimensional matrix to obtain a classification result. The classification result includes multiple type tags, and each type tag corresponds to at least one microservice. Therefore, whenever it is necessary to determine the type tags of microservices, the computer device can directly determine the type tags of microservices based on this classification result.
[0098] Specifically, the computer device can extract trace and span data from the isito component dapper, and obtain the dependency relationships of microservices A, B, C, and D based on these two data and create a service call matrix. If there is a call relationship between microservices, it is 1, and if there is no call relationship, it is 0. The specific is shown in the following table:
[0099]
[0100] After dimensionality reduction by PCA, all service data in the service call matrix is reduced to two-dimensional data, forming a two-dimensional matrix. The specific is shown in the following table:
[0101]
[0102] Finally, the computer device can use the K-means nearest neighbor algorithm to classify the two-dimensional matrix to obtain a classification result. The K-means nearest neighbor algorithm here includes the K-means clustering algorithm and the K-nearest neighbor algorithm (K-Nearest Neighbors, KNN). Among them, the K-means clustering algorithm is an unsupervised learning algorithm mainly used for clustering data, that is, dividing data into several categories without labels; while the K-nearest neighbor algorithm is a supervised learning algorithm commonly used for classification tasks and is suitable for classification tasks with known labels. Therefore, this application can classify the type tags of each microservice through the K-means nearest neighbor algorithm and identify the specific label types of the microservices to be scheduled.
[0103] In one embodiment, the process of using the K-means nearest neighbor algorithm to classify the two-dimensional matrix in step S132 to obtain a classification result may include:
[0104] S1321: Set the value of K according to the number of service types in the dedicated pool, and randomly initialize the centroid based on the value of K.
[0105] S1322: Assign the microservices corresponding to each data point in the two-dimensional matrix to the cluster of the nearest mass point through the Euclidean distance, and recalculate the mass point of each cluster until convergence.
[0106] S1323: Assign corresponding type labels to each cluster to obtain the classification result.
[0107] In this embodiment, when classifying the labels of each microservice, the computer device can set the value of K according to the number of service types in the dedicated pool, randomly initialize the centroid based on the value of K, then assign the microservice corresponding to each data point in the two-dimensional matrix to the cluster of the nearest mass point through the Euclidean distance, and recalculate the mass point of each cluster until convergence. Finally, corresponding type labels can be assigned to each cluster to obtain the classification result.
[0108] Specifically, the computer device can use the K-means nearest neighbor algorithm, and the value of K can be set as: Ka = the number of Ingress + the number of NodePort services + the number of LoadBlancer services. Among them, Ingress is a layer-7 load balancer based on HTTP / HTTPS, used to route external traffic to the services within the cluster; NodePort is a simple way to expose services to the outside of the cluster, Kubernetes will open a listening port on each node and then forward the traffic to the service; while LoadBlancer is a more advanced way to expose services, which accesses the service by automatically configuring the external load balancer. Based on this, this application can cluster the services exposed externally in the Kubernetes cluster according to their exposure methods. Each method represents an access mode of the service. By counting the number of services with the three exposure methods in the cluster, the value of K, Ka, can be calculated, and then used to initialize the number of centroids of the K-means algorithm, that is, the number of clustering centers. Here, each centroid represents a type of service traffic path or access policy, so as to more intelligently classify the services to support microservice scheduling, load optimization, or network configuration suggestions, etc.
[0109] After initializing the centroid, the computer device can, according to distance metrics such as the Euclidean distance, assign the microservice corresponding to each data point in the two-dimensional matrix to the cluster to which its nearest centroid belongs, and then update the centroid, that is, recalculate the centroid of each cluster by calculating the average value of all data points in the cluster. Further, the classification result of the K-means nearest neighbor algorithm can be expressed as follows:
[0110]
[0111] In addition, the computer device can deploy the K-means scheduling service through the deployment method. The kube-scheduler inserts the K-means scheduling into the final label scoring link in the way of extending the scheduling plugin.
[0112] In one embodiment, the process of determining the label score of each scheduling node on the type label in step S130 may include:
[0113] S134: Determine the total number of microservices corresponding to the type label in the dedicated pool and the number of microservices corresponding to the type label on each scheduling node.
[0114] S135: For each scheduling node, calculate the ratio of the number of microservices on the scheduling node to the total number of microservices, and use the ratio as the label score of the scheduling node on the type label.
[0115] In this embodiment, when determining the label score of the scheduling node, the computer device can first determine the total number of microservices corresponding to the type label in the dedicated pool and the number of microservices corresponding to the type label on each scheduling node. Then, for each scheduling node, the computer device can calculate the ratio of the number of microservices on the scheduling node to the total number of microservices, and use the ratio as the label score of the scheduling node on the type label.
[0116] Specifically, after the computer device determines the type label of the microservice to be scheduled, it can count the total number of all microservices matching the type label in the corresponding dedicated pool as the overall scale basis under the label. At the same time, the computer device can also traverse each scheduling node in the dedicated pool respectively, count the number of microservices running on each node that are consistent with the type label, so as to obtain the actual service bearing situation of the scheduling node in this label dimension. After mastering the label distribution situation at the node level and the overall level, the computer device can calculate the ratio between the number of label microservices carried by each scheduling node and the total number of label microservices, and use this ratio as the label score of the scheduling node under the current type label to reflect the degree of fit between the node and the current type label.
[0117] It can be understood that the higher the label score, the stronger the business relevance of the scheduling node in the deployment of this type of service. Scheduling to this node can improve performance indicators such as the communication efficiency, call coordination, and cache hit rate between microservices.
[0118] To better explain the K8s microservice scheduling device method of the present application, the following will be further described through Figure 3 to further illustrate. Schematically, as Figure 3 shown, Figure 3It is a logical schematic diagram of the K8s microservice scheduling process provided by an embodiment of this application.
[0119] Figure 3 In this process, the computer device can perform K-means clustering on microservice pods, determine the number of clusters K = 3 based on the numbers of Ingress, NodePort, and LoadBalancer, initialize the classification centroids, and classify and label the microservices. Subsequently, the computer device can send the pods to the admission controller to analyze the resource attributes of the pods and enable the automatic weight adjustment mechanism.
[0120] Here, the default scoring weights of the kube-scheduler plugin are set as: balanced allocation 1, imagelocality 1, least allocated 1. Then, it is judged whether the resource utilization rate of the dedicated pool where the pod is located is lower than 70%. If so, the weight remains unchanged, and it is further judged whether the image size exceeds 1GB. If it exceeds, the weight of the imagelocality plugin is increased to 2 to guide the image to be deployed nearby. If the resource utilization rate is greater than or equal to 70%, it means that the load in the current pool is relatively high. At this time, the weight of the least allocated plugin can be increased to 2, and the weights of balancedallocation and image locality are reduced to 0.5. Then, it continues to judge the image size. If the image exceeds 1GB, the weight of the image locality plugin is increased to 1; if it does not exceed, the weight remains unchanged. After determining the final weight of the image locality plugin, the computer device can use the image locality plugin to perform conventional scheduling scoring to obtain the plugin score.
[0121] After the conventional scheduling scoring is completed, the computer device can also perform label scoring in combination with the microservice type label to obtain the label score. This label score is calculated based on the ratio between the number of microservices of the same type as the currently to-be-scheduled microservice on each node and the total number. Finally, the computer device performs weighted summation on the plugin score obtained from the conventional scheduling scoring and the label score to form the comprehensive score of each scheduling node, and selects the node with the highest score as the deployment target of the pod, so as to achieve the optimal scheduling between resource balance and service affinity. For example, in Figure 3 the label scores of the three nodes are 2 / 7, 2 / 7, and 3 / 7 respectively. Therefore, the node with the label score of 3 / 7 has a higher possibility of being selected as the deployment node of the pod.
[0122] The K8s microservice scheduling device provided by the embodiments of the present application will be described below. The K8s microservice scheduling device described below can be correspondingly referred to the K8s microservice scheduling method described above.
[0123] In one embodiment, as Figure 4 shown, Figure 4 is a schematic structural diagram of a K8s microservice scheduling device provided by an embodiment of the present application; the present application also provides a K8s microservice scheduling device, including a data acquisition module 210, a plugin score determination module 220, a label score determination module 230, and a microservice scheduling module 240, specifically including the following:
[0124] The data acquisition module 210 is configured to acquire the image size of the microservice to be scheduled and the resource utilization rate of the dedicated pool corresponding to the microservice;
[0125] The plugin score determination module 220 is configured to adjust the scoring weight of each scoring plugin according to the image size and the resource utilization rate, and then use each scoring plugin to determine the plugin score of each scheduling node in the dedicated pool;
[0126] The label score determination module 230 is configured to determine the type label of the microservice and determine the label score of each scheduling node on the type label;
[0127] The microservice scheduling module 240 is configured to sum the plugin scores and label scores of each scheduling node to obtain the final score of each scheduling node, and schedule the microservice to the scheduling node with the highest final score.
[0128] In the above embodiment, when scheduling a microservice, the image size of the microservice to be scheduled and the resource utilization rate of the dedicated pool corresponding to the microservice can be acquired first, so that different scheduling measures can be adopted according to the specific requirements of different dedicated pools; here, the scoring weight of each scoring plugin can be adjusted according to the image size and the resource utilization rate, and each scoring plugin is used to determine the plugin score of each scheduling node in the dedicated pool to achieve the adaptive adjustment of the weights of each scoring plugin and improve the adaptability of the application scenario. In addition, since the relevance of each microservice is different, the type label of the microservice can also be determined, and the label score of each scheduling node on the type label can be determined, so as to specify the mutual call relationship between microservices, and then meet diverse business requirements; finally, the plugin scores and label scores of each scheduling node can be summed to obtain the final score of each scheduling node, and the microservice is scheduled to the scheduling node with the highest final score, so as to improve the refined scheduling ability of different dedicated pool usage scenarios, and improve the resource utilization rate while evenly distributing resources.
[0129] In one embodiment, the plug-in score determination module 220 may include:
[0130] A weight determination sub-module for determining the initial weights of each scoring plug-in according to the resource utilization rate.
[0131] A weight adjustment sub-module for adjusting the initial weights of each scoring plug-in according to the image size to obtain the final scoring weights of each scoring plug-in.
[0132] In one embodiment, the scoring plug-ins in the weight determination sub-module include a resource balancing plug-in, an image caching plug-in, and an idle resource plug-in; the weight determination sub-module may further include:
[0133] A first threshold judgment unit for judging whether the resource utilization rate exceeds the utilization rate threshold.
[0134] A first weight determination unit for reorganizing and determining the initial weights of each scoring plug-in according to the resource priority when the resource utilization rate exceeds the utilization rate threshold; in the resource priority reorganization, the weight of the idle resource plug-in is greater than the weights of the resource balancing plug-in and the image caching plug-in.
[0135] A second weight determination unit for determining the initial weights of each scoring plug-in according to the default weight group when the resource utilization rate does not exceed the utilization rate threshold; the weights of each scoring plug-in in the default weight group are equal.
[0136] In one embodiment, the weight adjustment sub-module may include
[0137] A second threshold judgment unit for judging whether the image size exceeds the image threshold.
[0138] A first weight adjustment unit for multiplying and increasing the initial weight of the image caching plug-in when the image size exceeds the image threshold, and using the increased initial weight of the image caching plug-in and the initial weights of other scoring plug-ins as the final scoring weights.
[0139] A second weight adjustment unit for using the initial weights of each scoring plug-in as the final scoring weights when the image size does not exceed the image threshold.
[0140] In one embodiment, the label score determination module 230 may include:
[0141] A matrix construction sub-module for extracting the dependencies between each microservice from the dedicated pool, constructing a service call matrix according to the dependencies, and reducing the dimension of the service call matrix to a two-dimensional matrix by using the PCA dimension reduction method.
[0142] A label classification sub-module, which is used to classify the labels of a two-dimensional matrix by using the K-means nearest neighbor algorithm to obtain a classification result; the classification result includes multiple type labels, and each type label corresponds to at least one microservice.
[0143] A label determination sub-module, which is used to determine the type label of the microservice according to the classification result.
[0144] In one embodiment, the label classification sub-module may include:
[0145] A centroid initialization unit, which is used to set the value of K according to the number of service types in the dedicated pool and randomly initialize the centroid based on the value of K.
[0146] A microservice allocation unit, which is used to allocate the microservice corresponding to each data point in the two-dimensional matrix to the nearest cluster of the mass points through the Euclidean distance, and recalculate the mass points of each cluster until convergence.
[0147] A label allocation unit, which is used to allocate a corresponding type label to each cluster to obtain a classification result.
[0148] In one embodiment, the label score determination module 230 may further include:
[0149] A service quantity determination sub-module, which is used to determine the total number of microservices corresponding to the type label in the dedicated pool and the number of microservices corresponding to the type label on each scheduling node.
[0150] A score calculation sub-module, which is used to calculate the ratio of the number of microservices on each scheduling node to the total number of microservices for each scheduling node, and use the ratio as the label score of the scheduling node on the type label.
[0151] In one embodiment, the present application further provides a storage medium, in which computer-readable instructions are stored. When the computer-readable instructions are executed by one or more processors, one or more processors are caused to execute the steps of the K8s microservice scheduling method as described in any one of the above embodiments.
[0152] In one embodiment, the present application further provides a computer device, in which computer-readable instructions are stored. When the computer-readable instructions are executed by one or more processors, one or more processors are caused to execute the steps of the K8s microservice scheduling method as described in any one of the above embodiments.
[0153] Schematically, as Figure 5 shown, Figure 5 is an internal structural diagram of a computer device provided by an embodiment of the present application. The computer device 300 may be provided as a server. Referring to Figure 5, the computer device 300 includes a processing component 302, which further includes one or more processors, and memory resources represented by a memory 301 for storing instructions executable by the processing component 302, such as application programs. The application programs stored in the memory 301 may include one or more modules each corresponding to a set of instructions. In addition, the processing component 302 is configured to execute instructions to perform the K8s microservice scheduling method of any of the above embodiments.
[0154] The computer device 300 may further include a power component 303 configured to perform power management of the computer device 300, a wired or wireless network interface 304 configured to connect the computer device 300 to a network, and an input / output (I / O) interface 305. The computer device 300 may operate based on an operating system stored in the memory 301, such as Windows Server TM, Mac OS XTM, Unix TM, Linux TM, Free BSDTM or the like.
[0155] Those skilled in the art can understand that Figure 5 the structure shown in is only a block diagram of some structures related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.
[0156] Finally, it should also be noted that in this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including a..." does not exclude the existence of additional identical elements in the process, method, article or device including the said element.
[0157] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can be referred to each other.
[0158] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but rather to the broadest scope consistent with the principles and novel features disclosed herein.
Claims
1. A K8s microservice scheduling method, characterized in that, The method includes: Obtaining the image size of the microservice to be scheduled and the resource utilization rate of the dedicated pool corresponding to the microservice; After adjusting the scoring weights of each scoring plugin according to the image size and the resource utilization rate, using each scoring plugin to determine the plugin score of each scheduling node in the dedicated pool; Determining the type label of the microservice and determining the label score of each scheduling node on the type label; Summing up the plugin scores and label scores of each scheduling node to obtain the final score of each scheduling node, and scheduling the microservice to the scheduling node with the highest final score.
2. The K8s microservice scheduling method according to claim 1, characterized in that: The adjusting the scoring weight of each scoring plugin according to the image size and the resource utilization rate includes: Determining the initial weights of each scoring plugin according to the resource utilization rate; Adjusting the initial weights of each scoring plugin according to the image size to obtain the final scoring weight of each scoring plugin.
3. The K8s microservice scheduling method according to claim 2, wherein The scoring plugins include a resource balance plugin, an image cache plugin, and an idle resource plugin; The determining the initial weights of each scoring plugin according to the resource utilization rate includes: Judging whether the resource utilization rate exceeds the utilization rate threshold; If so, determining the initial weights of each scoring plugin according to the resource priority recombination; in the resource priority recombination, the weight of the idle resource plugin is greater than the weights of the resource balance plugin and the image cache plugin; If not, determining the initial weights of each scoring plugin according to the default weight recombination; in the default weight recombination, the weights of each scoring plugin are equal.
4. The K8s microservice scheduling method according to claim 3, wherein The adjusting the initial weights of each scoring plugin according to the image size to obtain the final scoring weight of each scoring plugin includes Judging whether the image size exceeds the image threshold; If so, multiplying the initial weight of the image cache plugin by a factor and using the adjusted initial weight of the image cache plugin and the initial weights of other scoring plugins as the final scoring weights; If not, using the initial weights of each scoring plugin as the final scoring weights.
5. The K8s microservice scheduling method according to claim 1, wherein The determining the type label of the microservice includes: Extracting the dependencies between each microservice from the dedicated pool, constructing a service call matrix according to the dependencies, and using the PCA dimensionality reduction method to reduce the service call matrix to a two-dimensional matrix; Using the K-means nearest neighbor algorithm to perform label classification on the two-dimensional matrix to obtain a classification result; the classification result includes multiple type labels, and each type label corresponds to at least one microservice; Determining the type label of the microservice according to the classification result.
6. The K8s microservice scheduling method according to claim 5, wherein The using the K-means nearest neighbor algorithm to perform label classification on the two-dimensional matrix to obtain a classification result includes: Setting the value of K according to the number of service types in the dedicated pool and randomly initializing the centroid based on the value of K; Assigning the microservice corresponding to each data point in the two-dimensional matrix to the cluster of the nearest mass point through the Euclidean distance, and recalculating the mass point of each cluster until convergence; Assigning a corresponding type label to each cluster to obtain a classification result.
7. The K8s microservice scheduling method according to claim 1, wherein, The determining the label score of each scheduling node on the type label includes: Determine the total number of microservices corresponding to the type label in the dedicated pool, and the number of microservices corresponding to the type label on each scheduling node; For each scheduling node, calculate the ratio of the number of microservices on the scheduling node to the total number of microservices, and use the ratio as the label score of the scheduling node on the type label.
8. A K8s microservice scheduling device, characterized in that, Comprising: A data acquisition module, configured to acquire the mirror size of the microservice to be scheduled and the resource utilization rate of the dedicated pool corresponding to the microservice; A plugin score determination module, configured to adjust the scoring weights of each scoring plugin according to the mirror size and the resource utilization rate, and then use each scoring plugin to determine the plugin score of each scheduling node in the dedicated pool; A label score determination module, configured to determine the type label of the microservice, and determine the label score of each scheduling node on the type label; A microservice scheduling module, configured to sum up the plugin scores and label scores of each scheduling node to obtain the final score of each scheduling node, and schedule the microservice to the scheduling node with the highest final score.
9. A storage medium, characterized in that: The computer-readable instructions are stored in the storage medium, and when the computer-readable instructions are executed by one or more processors, the one or more processors are caused to execute the steps of the K8s microservice scheduling method according to any one of claims 1 to 7.
10. A computer device, characterized in that, Comprising: One or more processors, and a memory; The computer-readable instructions are stored in the memory, and when the computer-readable instructions are executed by the one or more processors, the steps of the K8s microservice scheduling method according to any one of claims 1 to 7 are executed.