Cluster resource management method and device, storage medium and electronic equipment
By using the ListAndWatch mechanism in K8s to establish Watch connections with multiple sub-clusters and uniformly encoding resource version numbers, the problem of low management efficiency of multiple K8s clusters is solved, and efficient unified management of multi-cluster resources and unconscious multi-cluster usage are achieved.
Patent Information
- Application Number
- CN202410597304.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-14
- Publication Date
- 2024-08-23
AI Technical Summary
Due to the large number of K8s clusters, the client can only manage one cluster in the existing technology, resulting in low cluster resource management efficiency.
Through the ListAndWatch mechanism, the server establishes Watch connections with multiple sub-clusters to be managed, collects resource event information, and uniformly encodes resource version numbers to achieve aggregation and unified management of multi-cluster resources, allowing clients to use unified resource version numbers. Manage multiple clusters.
It improves the efficiency of cluster resource management and realizes unified management of multiple clusters without relying on third-party storage media, allowing single-cluster applications to use multi-cluster resources without any awareness.
Smart Images

Figure CN118540371A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a cluster resource management method, device, storage medium and electronic device. Background Art
[0002] Kubernetes (K8s) is an open source platform for managing containerized applications on multiple hosts in a cloud platform. The goal of Kubernetes is to make the deployment of containerized applications simple and efficient. Kubernetes provides a mechanism for application deployment, planning, updating, and maintenance.
[0003] At present, the server is mainly connected to the server through the ListAndWatch mechanism, and then the cluster resource information of a single cluster connected to the server is sent to the client through ApiServer, so that the client can obtain all resource information in the cluster in real time and then manage the cluster resources.
[0004] However, due to the large number of K8s clusters, using this management method, one client can only manage one cluster, resulting in low management efficiency of cluster resources. Summary of the invention
[0005] In view of this, the present application provides a cluster resource management method, device, storage medium and electronic device, the main purpose of which is to improve the current technical problem that due to the existence of a large number of K8s clusters, one client can only manage one cluster, resulting in low management efficiency of cluster resources.
[0006] In a first aspect, the present application provides a cluster resource management method, comprising:
[0007] Based on the ListAndWatch mechanism, a Watch connection is established between the server and multiple subclusters to be managed, and resource event information of the multiple subclusters to be managed is collected;
[0008] Uniformly encode the first resource version number corresponding to the resource event information to obtain a second resource version number corresponding to the resource event information, wherein the first resource version number is a resource version number obtained by encoding based on a single cluster, and the second resource version number is a resource version number obtained by uniformly encoding based on the multiple subclusters to be managed;
[0009] In response to receiving the resource acquisition request and the target resource version number uploaded by the client, searching the resource event information corresponding to the second resource version number based on the target resource version number;
[0010] The found target resource event information is sent to the client, and the client is used to manage the multiple subclusters to be managed according to the target resource event information.
[0011] In a second aspect, the present application provides a cluster resource management device, including:
[0012] A collection module is configured to establish a Watch connection between the server and the multiple subclusters to be managed based on the ListAndWatch mechanism, and collect resource event information of the multiple subclusters to be managed;
[0013] an encoding module configured to uniformly encode a first resource version number corresponding to the resource event information to obtain a second resource version number corresponding to the resource event information, wherein the first resource version number is a resource version number obtained by encoding based on a single cluster, and the second resource version number is a resource version number obtained by uniformly encoding based on the multiple subclusters to be managed;
[0014] A search module, configured to, in response to receiving a resource acquisition request and a target resource version number uploaded by a client, search the resource event information corresponding to the second resource version number based on the target resource version number;
[0015] The sending module is configured to send the found target resource event information to the client, and the client is used to manage the multiple subclusters to be managed according to the target resource event information.
[0016] In a third aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the cluster resource management method of the first aspect is implemented.
[0017] In a fourth aspect, the present application provides an electronic device, including a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, wherein the processor implements the cluster resource management method of the first aspect when executing the computer program.
[0018] In a fifth aspect, the present application provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, it implements the facial image clustering method of the first aspect.
[0019] By means of the above-mentioned technical scheme, the present application provides a cluster resource management method, device, storage medium and electronic device, which first establishes a Watch connection between a server and multiple sub-clusters to be managed based on the ListAndWatch mechanism, and collects resource event information of the multiple sub-clusters to be managed; uniformly encodes the first resource version number corresponding to the resource event information to obtain the second resource version number corresponding to the resource event information, wherein the first resource version number is a resource version number obtained by encoding based on a single cluster, and the second resource version number is a resource version number obtained by uniformly encoding based on the multiple sub-clusters to be managed; in response to receiving a resource acquisition request and a target resource version number uploaded by a client, search is performed in the resource event information corresponding to the second resource version number based on the target resource version number; the found target resource event information is sent to the client, and the client is used to manage the multiple sub-clusters to be managed according to the target resource event information. Compared with the current existing technology, this application realizes the aggregation of cluster resource events of multiple clusters by establishing Watch connections between the server and multiple sub-clusters to be managed, collecting resource event information of multiple sub-clusters to be managed, and thus realizing the ListAndWatch function of the server for multiple clusters; by uniformly encoding the first resource version number corresponding to the resource event information to obtain the second resource version number corresponding to the resource event information, the multi-cluster resources can be uniquely identified by the second resource version number. Through the unified second resource version number, identification and sorting are realized, unified management of multiple clusters is realized, and the operation efficiency of the entire system is improved. Based on the target resource version number, the resource event information corresponding to the second resource version number can be directly queried, and the resource event information corresponding to the second resource version number does not need to be stored in other locations, thus getting rid of the dependence on third-party storage media; allowing single-cluster applications to monitor and use the capabilities of multiple clusters without modification, thereby realizing the ListAndWatch function of the client for multiple clusters.
[0020] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0022] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0023] Figure 1 A schematic diagram of a process flow of a cluster resource management method provided in an embodiment of the present application is shown;
[0024] Figure 2 A schematic diagram of a process flow of a cluster resource management method provided in an embodiment of the present application is shown;
[0025] Figure 3 A schematic diagram of an example process provided by an embodiment of the present application is shown;
[0026] Figure 4 A schematic diagram of the structure of a cluster resource management device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0027] The embodiments of the present application will be described in more detail below with reference to the accompanying drawings. It should be noted that the embodiments and features in the embodiments of the present application can be combined with each other without conflict.
[0028] In the existing technology, all components in K8s and container applications running on K8s interact with each other through ApiServer (ApiServer will synchronize the real-time status of all resources in the cluster to components and container applications). ApiServer uses ListAndWatch to synchronize the real-time status of all resources in the K8s cluster. When the Informer client connects to ApiServer for the first time, it will list all K8s cluster resources to the local cache at one time through the Http short link, and then establish an Http long link through Watch, constantly receiving Event events sent by ApiServer, and updating the local cache in real time. When the client needs to query a resource, it can directly query the local cache, which greatly reduces the pressure on ApiServer.
[0029] However, with the increasing number of K8s clusters, cross-cluster applications are inevitable. It has become an urgent need to enable cloud-native applications to use multiple clusters without changing the current business code. To meet this demand, the implementation of the multi-cluster ListAndWatch mechanism has become the most critical link. At present, for multi-cluster solutions, Karmada can achieve true open multi-cloud K8s mainly by using K8s native API and providing advanced scheduling functions. At present, Karmada only achieves the state aggregation of some K8s resources in multiple clusters, and does not support the multi-cluster ListAndWatch mechanism; or, by aggregating multiple K8s cluster resources, it provides more powerful search functions on the basis of compatibility with K8s OpenAPI, allowing users to obtain any resources they want in multiple clusters faster and more conveniently. At present, Clusterpedia only achieves multi-cluster resource retrieval, and has not implemented the multi-cluster ListAndWatch mechanism.
[0030] In the computing network scenario, after the cloud native application is scheduled by the computing network brain, the management module of the cloud native application (such as Operator, etc.) needs to dynamically manage and coordinate the running status of the cloud native application on multiple K8s clusters. The management module of the cloud native application cannot run on multiple K8s clusters without modifying the code. Specifically, the Karmada project of the CNCF Foundation has currently realized the resource scheduling of multiple K8s clusters based on multiple strategies, and the multi-cluster state aggregation of cluster resources, which plays a good role in the multi-cluster management of K8s resources. However, Karmada does not support the multi-cluster ListAndWatch mechanism, and cloud native applications still cannot use the running resources of multiple clusters without perception based on Karmada. Correspondingly, the Clusterpedia project of the CNCF Foundation, based on MySql at the bottom layer, realizes the persistence of multi-cluster resource objects, and on this basis, provides multi-cluster retrieval functions in the K8s OpenAPI mode. However, Clusterpedia currently only implements simple Get and List functions, and does not support more complex Watch functions. Clusterpedia is mainly used by operation and maintenance personnel and R&D personnel to retrieve multi-cluster resources through the Kubectl tool.
[0031] In order to improve the current existing technology, due to the large number of K8s clusters, one client can only manage one cluster, which leads to low management efficiency of cluster resources. This embodiment provides a cluster resource management method, such as Figure 1 As shown, the method includes:
[0032] Step 101: Establish a Watch connection between the server and multiple subclusters to be managed based on the ListAndWatch mechanism to collect resource event information of the multiple subclusters to be managed.
[0033] In an embodiment of the present application, ListAndWatch is a core mechanism in Kubernetes for synchronizing and monitoring resource status changes. ListAndWatch is a core mode for synchronously and asynchronously monitoring the status of Kubernetes resources, ensuring that each component can respond to changes in resources in the cluster in a timely manner. It is widely used in internal components of Kubernetes and client libraries that interact with the Kubernetes API Server. Specifically, in Kubernetes internal components such as Kube-apiserver, cacher components also use similar mechanisms to List and Watch objects, such as Secret objects, in order to maintain consistency between the local cache and the cluster state. If ListAndWatch encounters an error, such as an inability to list resources from the API Server or a listening failure, it may cause the component to fail or restart.
[0034] In some examples, multiple subclusters to be managed can correspond to different Kubernetes clusters. Specifically, the Kubernetes (K8s) cluster is an open source platform for automating the deployment, expansion, and management of containerized applications. The Master nodes in the Kubernetes cluster may include: kube-apiserver: As the unified entrance to the cluster, it is responsible for receiving and processing operation requests for all objects in the cluster. etcd: A distributed key-value storage system that stores all configuration data and status information of the cluster. kube-scheduler: Responsible for scheduling newly created Pods to run on appropriate Worker nodes. kube-controller-manager: Runs a series of controller processes, such as Node Controller, ReplicaSetController, Service Account&Token Controllers, etc., which jointly maintain the state of the cluster consistent with the expected state.
[0035] Optionally, the resource event information can be a cluster event. In a Kubernetes cluster, an event is a core concept used to record detailed information about changes in the state of resource objects in the cluster. Each event represents an operation result or current state of a specific resource, such as container creation, restart, service endpoint change, etc. Kubernetes components such as Kubelet, controller manager, and other custom controllers will generate and report events.
[0036] Step 102: uniformly encode the first resource version number corresponding to the resource event information to obtain the second resource version number corresponding to the resource event information.
[0037] The first resource version number is a resource version number obtained by encoding based on a single cluster, and the second resource version number is a resource version number obtained by uniformly encoding based on multiple subclusters to be managed.
[0038] For this embodiment, the resource version number is ResourceVersion. Specifically, in Kubernetes, the resource version number (ResourceVersion) is a string identifier that represents a specific version of each API object in the cluster. Each Kubernetes resource object (such as Pod, Deployment, Service, etc.) has a ResourceVersion field in its metadata. In an embodiment of the present application, the watch operation is an important feature of the Kubernetes API, allowing the client to monitor changes in resource collections. The client can monitor resource change events since a specific version by specifying the ResourceVersion parameter.
[0039] Correspondingly, the first resource version number is the resource version number encoded by the Kubernetes cluster based on itself, and the second resource version number is the resource version number obtained after re-encoding based on multiple subclusters to be managed.
[0040] Step 103: In response to receiving the resource acquisition request and the target resource version number uploaded by the client, searching in the resource event information corresponding to the second resource version number based on the target resource version number.
[0041] In an embodiment of the present application, the resource acquisition request may include a resource acquisition request corresponding to the List mechanism and a resource acquisition request corresponding to the Watch mechanism in the ListAndWatch mechanism; the target resource version number is the resource version number required by the client to obtain resource event information.
[0042] Step 104: Send the found target resource event information to the client.
[0043] The client is used to manage multiple subclusters to be managed according to target resource event information.
[0044] Compared with the current existing technology, this embodiment establishes a Watch connection between the server and multiple sub-clusters to be managed, collects resource event information of multiple sub-clusters to be managed, and realizes the aggregation of cluster resource events of multiple clusters, thereby realizing the ListAndWatch function of the server for multiple clusters; by uniformly encoding the first resource version number corresponding to the resource event information to obtain the second resource version number corresponding to the resource event information, the multi-cluster resources can use the second resource version number as the unique identifier, and through the unified second resource version number, identification and sorting are realized, and unified management of multiple clusters is realized; thereby improving the operating efficiency of the entire system and getting rid of dependence on third-party storage media; allowing single-cluster applications to monitor and use the capabilities of multiple clusters without modification, thereby realizing the ListAndWatch function of the client for multiple clusters.
[0045] In order to further illustrate the specific implementation process of the method of this embodiment, this embodiment provides the following Figure 2 The specific method shown includes:
[0046] Step 201: Obtain cluster access information and cluster configuration information corresponding to a plurality of subclusters to be managed.
[0047] In an embodiment of the present application, the cluster access information may be the address information of the ApiServer. The Kubernetes APIServer is one of the core components of the Kubernetes cluster. It provides a RESTful API interface for the cluster and serves as a unified entry point for all resource operations. Correspondingly, the cluster configuration information may be Kubeconfig. The kubeconfig file is a Kubernetes client configuration file for storing authentication information, cluster details, and context information required to access the Kubernetes cluster. This file is usually named config or kubeconfig.
[0048] Step 202: Based on the cluster access information and cluster configuration information, a Watch connection is established between the server and the multiple sub-clusters to be managed according to the ListAndWatch mechanism.
[0049] In some examples, ClusterResource is a CRD definition, in which the most important field is ClusterSpec. In ClusterSpec, the Kubeconfig of the subcluster, the address of the ApiServer, and all K8s cluster resources GVR to be monitored are defined respectively. ClusterSpec represents a detailed specification describing the overall configuration of the Kubernetes cluster.
[0050] For example, Figure 3 As shown, it can specifically include a multi-cluster management module, a sub-cluster data collection module, a ResourceVersion transcoding module and a WatchCache module, wherein the sub-cluster management module may include a Watch information collection channel (result chan) and an event handler (event handler); the ResourceVersion transcoding module may include an Aggregator Channel, an RV Generator, and a Delta Fifo; the WatchCache module includes a DeltaHander, a preset sliding window, a dispatchEvent, a Stores memory search engine and a result chan. The embodiment included in step 202 can be executed by the multi-cluster management module in the server, and the multi-cluster management module is responsible for the registration, modification and deletion process of the sub-cluster. When a new sub-cluster needs to be managed, the multi-cluster management module needs to parse out the list of resource types that need to be managed in the sub-cluster, that is, the Group-Version-Resources (GVR) of K8s; at the same time, the resource list of the sub-cluster can support changes and deletions. In order to effectively manage multiple clusters, the CustomResourceDefinition (CRD) method of K8s is adopted. CRD is a custom resource of K8s. We monitor CRD through Informer and use the Handler hook function of the Informer architecture to responsively perform corresponding logical processing on sub-cluster events, thereby achieving flexible management of sub-clusters. In the embodiment of the present application, the name of the multi-cluster management module can also be management module, etc. The specific name of the multi-cluster management module is not specifically limited here.
[0051] It should be noted that in Kubernetes, Group-Version-Resources (GVR) is a common way to represent API objects. It consists of Group, Version, and Resources, where Group represents the group or category to which the API object belongs. The Kubernetes API consists of multiple different groups, each of which represents a class of related resources and operations. Version specifies the version number used by the API object. Kubernetes supports multiple versions of API for backward compatibility and functional evolution. Resource represents a specific API resource type, such as Pod, Service, Deployment, Namespace, etc. A resource is a specific object instance that a user can create, update, query, or delete. In this way, Kubernetes can effectively organize and manage its huge API set and allow clients (such as kubectl or other applications using the Kubernetes client library) to accurately specify the API resources to be operated. At the same time, this also provides infrastructure support for extending Kubernetes functionality, and developers can introduce custom resource types by defining new Groups and Versions.
[0052] Step 203: Determine information collection channels corresponding to the multiple subclusters to be managed, and collect resource event information through the information collection channels.
[0053] Optionally, step 203 may specifically include: if it is determined that the target resource information in the resource event information to be collected is error resource event information, then determining the error category corresponding to the target resource event information; in response to determining that the error category corresponding to the target resource event information is the target error category, resetting the first resource version number corresponding to the target resource event information; and; refreshing other resource event information except the target resource event information in the subcluster to be managed corresponding to the reset target resource event information, and collecting resource event information based on the refresh processing result. In response to determining that the error category corresponding to the target resource event information is other error categories except the target error category, based on the first resource version number corresponding to the target resource event information, re-collecting the resource event information corresponding to the first resource version number to obtain the resource event information.
[0054] In some examples, the information collection channel can be a Result Channel, which can be a channel structure implemented at the application level for transmitting Kubernetes-related operation results. For example, in a Kubernetes custom controller written in Go language, developers can create a channel as a result channel to receive notifications or result information after the API resource operation is completed. For example, when performing asynchronous operations (such as monitoring resource events, asynchronously calling Kubernetes API to update resource status, etc.), the operation results can be returned to the main process through the channel for subsequent processing; in an embodiment of the present application, the Result Channel is used to receive resource event information of the sub-cluster to be managed.
[0055] Exemplarily, based on step 202, the embodiments included in step 203 can be executed by the sub-cluster data collection module and the ResourceVersion transcoding module in the server. The function of the sub-cluster data collection module is to perform the Watch operation on the ApiServer of the sub-cluster and insert the received Event event into the Aggregator Channel. The collection module is triggered by the Handler hook function of the multi-cluster management module, and the correspondence between the sub-cluster data collection module and Cluster / GVR is 1:1. After the sub-cluster data collection module is started, the KubeConfig of the sub-cluster is parsed, and the ClientSet is initialized according to the KubeConfig. Based on the ClientSet, Watch is performed on the ApiServer of the sub-cluster (ResourceVersion is 0 for the first time), and the Result Channel of Watch is obtained.
[0056] Furthermore, the ResourceVersion transcoding module aggregates the data collected by the sub-cluster data collection module and starts a thread (or coroutine) to monitor the Result Channel of the Watch. When a normal Event is received, the latest ResourceVersion of the current sub-cluster data collection module is updated, and the Event is inserted into the Aggregator Channel. When an abnormal Event is received, the Watch will be re-executed based on the ResourceVersion currently maintained by the module, so that Event breakpoint continuation can be achieved; when the exception is an Expired ERROR, the ResourceVersion maintained by the module is reset to 0, and an abnormal Event is inserted into the Aggregator Channel to perform a Refresh operation on the resources of this sub-cluster.
[0057] Step 204: uniformly encode the first resource version number corresponding to the resource event information to obtain the second resource version number corresponding to the resource event information.
[0058] The first resource version number is a resource version number obtained by encoding based on a single cluster, and the second resource version number is a resource version number obtained by uniformly encoding based on multiple subclusters to be managed.
[0059] Optionally, step 204 may specifically include: aggregating the resource event information in a preset aggregation channel, and determining the name of the sub-cluster to be managed corresponding to the resource event information in the preset aggregation channel; performing hash encoding based on the name of the sub-cluster to be managed and the first resource version number to obtain a second resource version number corresponding to the resource event information; accordingly, after step 204, the method of this embodiment also includes: storing the resource event information in a preset sliding window and a preset memory search engine through a preset first-in-first-out pipeline, respectively.
[0060] The preset memory search engine is used to store all resource event information, and the sliding window is used to store resource event information within a preset time period.
[0061] In an embodiment of the present application, the preset aggregation channel may be an Aggregator Channel, specifically, the Aggregator Channel is used to aggregate resource event information; the first-in-first-out pipeline may be a Delta Fifo, specifically, Delta Fifo (Incremental First-In-First-Out) is a data structure for storing and processing event data, and is widely used in Kubernetes environments. In the Kubernetes client library client-go, DeltaFIFO is a custom double-ended queue implementation, which is particularly suitable for caching and deduplicating change events of API objects.
[0062] For example, DeltaFifo can store the addition, deletion, and modification events (Delta) of resource objects observed from the Kubernetes API Server in sequence. When the same resource object undergoes multiple changes in a short period of time, DeltaFIFO can identify and merge these continuous change events, retaining only the changes in the final state, thereby avoiding the problem of repeatedly processing the same event. Both synchronous and asynchronous modes can be supported to process events. In synchronous mode, the next event in the queue can be directly obtained and processed through the Pop() method; in asynchronous mode, a processor function can be set to automatically trigger processing when a new event enters the queue. DeltaFIFO can also track the ResourceVersion of resource objects to ensure that data inconsistency or expiration is not caused by concurrent operations. In components such as Kubernetes controllers, DeltaFIFO is used in conjunction with Reflector to monitor state changes of resources in the cluster and take corresponding actions based on these changes.
[0063] Exemplarily, based on step 203, the ResourceVersion of the Event is transcoded into the ResourceVersion of the multi-cluster version, and then the transcoded Event is inserted into Delta Filo. The purpose of the ResourceVersion of the multi-cluster version is to enable the two ResourceVersions to be compared when the Events of multiple sub-clusters are aggregated, just like a single K8s cluster, so that the order of the Events can be identified based on the ResourceVersion.
[0064] The multi-cluster version ResourceVersion maintains a Hash structure, the Key of the Hash is ClusterName, and the Value is the single-cluster ResourceVersion. The algorithm for comparing the size of the multi-cluster version ResourceVersion is as follows (the two ResourceVersions are ResourceVersion1 and ResourceVersion2): traverse the Hash structure of ResourceVersion1 to obtain Key1 and Value1; use Key1 to get Value2 from ResourceVersion2; compare Value1 and Value2, if they are different, return the comparison result, otherwise continue to step 1; if there is no return after traversing ResourceVersion1, the two are equal.
[0065] Step 205: In response to receiving the resource acquisition request and the target resource version number uploaded by the client, searching in the resource event information corresponding to the second resource version number based on the target resource version number.
[0066] Optionally, step 205 may specifically include: in response to receiving a first resource acquisition request sent by the client, sending all resource event information in a preset memory search engine to the client; in response to receiving a second resource acquisition request and a target resource version number sent by the client, searching in the resource event information within a preset time period in a preset sliding window based on the target resource version number; in the preset sliding window, determining the target resource event information corresponding to the target resource version number.
[0067] Among them, all resource event information includes the target resource version number, the first resource acquisition request is sent by the client based on the List mechanism in the ListAndWatch mechanism; the second resource acquisition request is sent by the client based on the Watch mechanism in the ListAndWatch mechanism; the target resource event information is the resource event information stored in the preset sliding window after the resource event information corresponding to the target resource version number is stored.
[0068] In an embodiment of the present application, a preset sliding window can be an Event event sliding window that stores the latest Event with a capacity limit. As Events are added, the Event event sliding window is constantly refreshed. The purpose of designing this sliding window is to configure the Watch mechanism. When a Watch request from a client is received, a binary search can be performed in the sliding window based on ResourceVersion (Events are arranged in ascending order according to ResourceVersion in the sliding window), and eligible Events are returned to the client. The sliding window is implemented based on an array + double pointer, where capacity is the upper limit of the capacity of the sliding window; cache is the array itself, and each element stores an Event; startIndex and endIndex are double pointers, which are the starting position and end position of the window, respectively. When a new Event is added to the sliding window, endIndex will slide back one position. When the number of Events reaches capacity, startIndex will slide forward one position in advance to cover the oldest Event in the window.
[0069] Correspondingly, the preset memory search engine can be the Indexer memory search engine, which is the final storage place for multi-cluster K8s resource objects. It can convert Events into final K8s resource objects. As long as all Events can be received, the cluster resources stored by the Indexer memory search engine can be consistent with all ApiServers in the multi-cluster. The final storage of Informer also depends on the Indexer memory search engine, which is the cornerstone for the Watch mechanism to be realized.
[0070] In some examples, in stores, there is an important Hash table indexers, the key of indexers is the name of the subcluster, and the value is the cache data structure. It can be seen that the resource objects of different subclusters are stored separately. The advantage of separate storage is that when a subcluster has a problem, the resource objects of the subcluster can be easily cleared.
[0071] The cache structure is the final storage location of multi-cluster resource objects in memory. The cache structure contains two data structures, cacheStorage and keyFunc. The type of cacheStorage is ThreadSafeStore, which is a memory search engine that supports multi-threaded concurrency, and keyFunc is the key value generation function of the resource object. Before the resource object is stored, keyFunc needs to generate the key value, and the generated key value and the resource object are stored in cacheStorage together.
[0072] This ResourceVersion counter is the ClusterRVStore in Module 3. In WatchCache, the ResourceVersion counter is used to record the ResourceVersion of the latest Event, which represents the current state of WatchCache.
[0073] When an Event is sent to WatchCache by Delta Handler, the Event is passed to the Event sliding window and Indexer memory search engine for processing (Add, Update and Delete) respectively. Finally, the ResourceVersion counter is assigned the ResourceVersion of the current Event.
[0074] Step 206: Send the found target resource event information to the client.
[0075] The client is used to manage multiple subclusters to be managed according to target resource event information.
[0076] Optionally, after step 206, the method of this embodiment further includes: in response to establishing a Watch connection between the server and the client, forwarding the resource event information to be forwarded to the client through a preset forwarding channel.
[0077] The resource event information to be forwarded is the resource event information received by the preset forwarding channel after the Watch connection is established.
[0078] In an embodiment of the present application, the preset forwarding channel is DispatchEvent, and DispatchEvent can pass an event object to an appropriate processor or listener to trigger corresponding business logic processing.
[0079] For example, based on step 204, the List method is implemented based on HTTP short connection, returning all cluster resources to the client at one time; while Watch needs to transmit the latest Event to the client in real time, so the Watch method is based on HTTP long connection. The List method and the Watch method body have been implemented in the Handler of ApiServer, and this application proposal only needs to implement the internal implementation logic of the method.
[0080] Specifically, the List method returns only two parts to the client: all current cluster resource objects, and the latest version of ResourceVersion. In this application proposal, to obtain all cluster resource objects of multiple clusters, it is necessary to traverse the Indexer memory search engine in WatchCache. Since the resource objects of multiple subclusters are stored in the cache separately, there are cases where different subclusters have duplicate names. During the traversal process, deduplication is also required. The deduplication strategy can be based on configuration, such as only taking the first cluster resource object, etc.; It is relatively convenient to obtain the latest version of ResourceVersion, and just return the ResourceVersion counter of WatchCache.
[0081] Furthermore, the Watch method has two main stages. Stage 1: When the client initiates a Watch request, a CacheWatcher data structure needs to be established for the client; and based on the ResourceVersion parameter RVx passed in the Watch request, it is necessary to find all Events whose ResourceVersion is greater than RVx in the Event event sliding window based on the binary search method, and return these Events to the client Channel; finally, the CacheWatcher coroutine is started to continuously receive real-time Events from the Delta Handler. Stage 2: At this time, the Http long connection with the client has been established, and the real-time Events passed by the Delta Handler need to be continuously transmitted to the client. The CacheWatchers array is maintained in the WatcherBuffer, and the elements of the array are CacheWatcher data structures, and each array element corresponds to a client. In CacheWatcher, input is responsible for receiving Events from the Delta Handler, and the result Channel is connected to the Http long connection. Events inserted into the result Channel will be sent directly to the client. Whenever the Delta Handler receives a new Event, it will loop through the CacheWatchers array and send the Event to each CacheWatcher's input Channel. When the input Channel receives a new Event, the relevant CacheWatcher coroutine will take out the Event and put it into its own result Channel.
[0082] The problem to be solved by the embodiments of the present application is to manage and aggregate multi-cluster resources based on the current ApiServer architecture, and provide List, Watch and other interfaces (including Create, Update, etc.) to the outside world in a K8s OpenAPI manner, so that cloud-native applications running on a single K8s cluster can use the capabilities of multiple clusters without being aware of it.
[0083] It should be noted that the embodiment of the present application is implemented based on the K8s ApiServer or ApiServer class (which can be Karmada ApiServer, Clusterpedia ApiServer). ApiServer can be understood as a complex Webservice. Each K8s cluster resource (such as Pod, Deployment, etc.) is a Rest resource that provides Rest services to the outside world. Inside ApiServer, for each K8s cluster resource, a Webserver-Handler-Storage call chain is maintained, and this call chain provides Rest services to the outside world.
[0084] This application proposal transforms the Handler-Storage part of ApiServer. Handler can be understood as the Handler of Webservice, which implements List and Watch methods; Storage layer stores cluster resource objects for the List and Watch methods of Handler to call. Among them, the Storage layer of K8s ApiServer is Cache+Etcd, while the Storage layer of Clusterpedia ApiServer is MySQL.
[0085] Compared with the current existing technology, this embodiment establishes a Watch connection between the server and multiple sub-clusters to be managed, collects resource event information of multiple sub-clusters to be managed, realizes the aggregation of cluster resources and Events of multiple clusters, and thus realizes the ListAndWatch function of the server for multiple clusters; by uniformly encoding the first resource version number corresponding to the resource event information to obtain the second resource version number corresponding to the resource event information, the multi-cluster resources can be uniquely identified by the second resource version number, and the identification and sorting are realized through the unified second resource version number, thereby realizing the unified management of multiple clusters; the memory-based storage engine WatchCache stores the latest Event through the Event event sliding window, and stores the cluster resources of multiple sub-clusters through the Indexer memory search engine, realizing the caching and storage of multi-cluster Events and cluster resources, thereby improving the operating efficiency of the entire system and getting rid of the dependence on third-party storage media; allowing single-cluster applications to monitor and use the capabilities of multiple clusters without modification, thereby realizing the ListAndWatch function of the client for multiple clusters.
[0086] In order to illustrate the specific implementation process of this embodiment, the following specific application examples are given, but are not limited thereto:
[0087] First, by watching multiple sub-K8s clusters, cluster resource Events of sub-clusters are collected; then, the collected Events of multiple sub-clusters are aggregated to the Aggregator Channel aggregation pipeline, and the transcoding module re-encodes the ResourceVersion of the Event and inserts it into the Delta Fifo pipeline; after receiving the Event from the Delta Fifo pipeline, the DeltaHandler of the WatchCache module updates the Cache sliding window and the Stores memory search engine respectively, and sends the Event to the client that is watching through the dispatchEvent method. When the client initiates a List or Watch request, the multi-cluster resource and cluster resource Events are taken out from the cache sliding window and the store memory search engine and returned to the client.
[0088] Compared with the current existing technology, this embodiment establishes a Watch connection between the server and multiple sub-clusters to be managed, collects resource event information of multiple sub-clusters to be managed, realizes the aggregation of cluster resources and Events of multiple clusters, and thus realizes the ListAndWatch function of the server for multiple clusters; by uniformly encoding the first resource version number corresponding to the resource event information to obtain the second resource version number corresponding to the resource event information, the multi-cluster resources can be uniquely identified by the second resource version number, and the identification and sorting are realized through the unified second resource version number, thereby realizing the unified management of multiple clusters; the memory-based storage engine WatchCache stores the latest Event through the Event event sliding window, and stores the cluster resources of multiple sub-clusters through the Indexer memory search engine, realizing the caching and storage of multi-cluster Events and cluster resources, thereby improving the operating efficiency of the entire system and getting rid of the dependence on third-party storage media; allowing single-cluster applications to monitor and use the capabilities of multiple clusters without modification, thereby realizing the ListAndWatch function of the client for multiple clusters.
[0089] Further, as Figure 1 and Figure 2 The specific implementation of the method shown in the embodiment provides a cluster resource management device, such as Figure 4 As shown, the device includes: a collection module 31, an encoding module 32, a search module 33, and a sending module 34.
[0090] The collecting module 31 is configured to establish a Watch connection between the server and the multiple sub-clusters to be managed based on the ListAndWatch mechanism, and collect resource event information of the multiple sub-clusters to be managed;
[0091] The encoding module 32 is configured to uniformly encode the first resource version number corresponding to the resource event information to obtain a second resource version number corresponding to the resource event information, wherein the first resource version number is a resource version number obtained by encoding based on a single cluster, and the second resource version number is a resource version number obtained by uniformly encoding based on the multiple subclusters to be managed;
[0092] A search module 33 is configured to, in response to receiving a resource acquisition request and a target resource version number uploaded by a client, search the resource event information corresponding to the second resource version number based on the target resource version number;
[0093] The sending module 34 is configured to send the found target resource event information to the client, and the client is used to manage the multiple subclusters to be managed according to the target resource event information.
[0094] In some examples of this embodiment, the collection module 31 is also configured to obtain cluster access information and cluster configuration information respectively corresponding to the multiple sub-clusters to be managed; accordingly, the collection module 31 is specifically configured to establish a Watch connection between the server and the multiple sub-clusters to be managed according to the ListAndWatch mechanism based on the cluster access information and cluster configuration information; determine the information collection channels respectively corresponding to the multiple sub-clusters to be managed, and collect the resource event information through the information collection channels.
[0095] In some examples of the present embodiment, the collection module 31 is further specifically configured to determine the error category corresponding to the target resource event information if it is determined that the target resource information in the resource event information to be collected is error resource event information; in response to determining that the error category corresponding to the target resource event information is the target error category, reset the first resource version number corresponding to the target resource event information; and; refresh the resource event information other than the target resource event information in the subcluster to be managed corresponding to the reset target resource event information, and collect the resource event information based on the refresh processing result. In response to determining that the error category corresponding to the target resource event information is the error category other than the target error category, based on the first resource version number corresponding to the target resource event information, re-collect the resource event information corresponding to the first resource version number to obtain the resource event information.
[0096] In some examples of this embodiment, the encoding module 32 is specifically configured to aggregate the resource event information in a preset aggregation channel, and determine the name of the subcluster to be managed corresponding to the resource event information in the preset aggregation channel; perform hash encoding based on the name of the subcluster to be managed and the first resource version number to obtain the second resource version number corresponding to the resource event information; accordingly, the encoding module 32 is also configured to store the resource event information in a preset sliding window and a preset memory search engine through a preset first-in-first-out pipeline, respectively, wherein the preset memory search engine is used to store all resource event information, and the sliding window is used to store resource event information within a preset time period.
[0097] In some examples of the present embodiment, the search module 33 is specifically configured to, in response to receiving a first resource acquisition request sent by the client, send all the resource event information in the preset memory search engine to the client, wherein the all the resource event information includes the target resource version number, and the first resource acquisition request is sent by the client based on the List mechanism in the ListAndWatch mechanism; in response to receiving a second resource acquisition request and the target resource version number sent by the client, search for the resource event information within the preset time period in the preset sliding window based on the target resource version number, and the second resource acquisition request is sent by the client based on the Watch mechanism in the ListAndWatch mechanism; in the preset sliding window, determine the target resource event information corresponding to the target resource version number, and the target resource event information is the resource event information stored in the preset sliding window after the resource event information corresponding to the target resource version number is stored.
[0098] In some examples of this embodiment, the sending module 34 is also configured to forward the resource event information to be forwarded to the client through a preset forwarding channel in response to establishing a Watch connection between the server and the client, wherein the resource event information to be forwarded is the resource event information received by the preset forwarding channel after the Watch connection is established.
[0099] It should be noted that for other corresponding descriptions of the functional units involved in the cluster resource management device provided in this embodiment, please refer to Figure 1 and Figure 2 The corresponding description in will not be repeated here.
[0100] Based on the above Figure 1 to Figure 2 The method shown in the embodiment also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the above-mentioned Figure 1 to Figure 2 The method shown.
[0101] Based on this understanding, the technical solution of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, USB flash drive, mobile hard disk, etc.), including a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute the methods of various implementation scenarios of the present application.
[0102] Based on the above Figure 1 to Figure 2 The method shown, and Figure 4 In order to achieve the above-mentioned purpose, the embodiment of the present application also provides an electronic device, such as a personal computer, a server, a laptop computer, a smart phone, an intelligent robot or other intelligent terminal, which includes a storage medium and a processor; the storage medium is used to store a computer program; the processor is used to execute the computer program to achieve the above-mentioned Figure 1 to Figure 2 The method shown.
[0103] Optionally, the above-mentioned physical device may also include a user interface, a network interface, a camera, a radio frequency (RF) circuit, a sensor, an audio circuit, a WI-FI module, etc. The user interface may include a display, an input unit such as a keyboard, etc., and the optional user interface may also include a USB interface, a card reader interface, etc. The network interface may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface), etc.
[0104] Those skilled in the art will appreciate that the above-mentioned physical device structure provided in this embodiment does not constitute a limitation on the physical device, and may include more or fewer components, or a combination of certain components, or different arrangements of components.
[0105] The storage medium may also include an operating system and a network communication module. The operating system is a program that manages the hardware and software resources of the above-mentioned physical device, and supports the operation of the information processing program and other software and / or programs. The network communication module is used to realize the communication between the components inside the storage medium, and the communication with other hardware and software in the information processing physical device.
[0106] Based on the above Figure 1 to Figure 2 The present application also provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the above-mentioned Figure 1 to Figure 2 The method shown, the method implemented when the computer program is executed by the processor can refer to the various embodiments of the present application, and will not be described in detail here.
[0107] Through the description of the above implementation mode, the technicians in this field can clearly understand that the present application can be implemented by means of software plus the necessary general hardware platform, or by hardware. Compared with the current prior art, the present embodiment iteratively trains the cyclic generative adversarial network, and the second interface feature data obtained in each iteration are used for the next training, so that the training set used in the training process can be more and more abundant, and a model with higher recognition accuracy can be obtained by training the model once, and a model with higher accuracy can be trained with a smaller sample set, and more interface feature data of abnormal web pages can be identified in the process of identifying the interface feature data, and abnormal requests can be accurately filtered out to generate normal request information, and the generation effect of the generator can be effectively enhanced by sending the feature constraint conditions into the cyclic generative adversarial network, and the conversion accuracy can be improved. The cyclic generative adversarial network can also convert the interface feature data of abnormal web pages into the interface feature data of normal web pages, and filter the request information with obvious abnormal features to a certain extent, thereby effectively preventing malicious attacks on websites, and filtering out the modification of user requests by interceptors, protecting website security, reducing the cost in webpage security risk protection, and ensuring real-time performance and effectiveness.
[0108] It should 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 such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0109] The above is only a specific implementation of the present application, so that those skilled in the art can understand or implement 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 described herein, but will conform to the widest scope consistent with the principles and novel features applied for herein.
Claims
1. A cluster resource management method, characterized in that: include: Based on the ListAndWatch mechanism, a Watch connection is established between the server and multiple subclusters to be managed, and resource event information of the multiple subclusters to be managed is collected; Uniformly encode the first resource version number corresponding to the resource event information to obtain a second resource version number corresponding to the resource event information, wherein the first resource version number is a resource version number obtained by encoding based on a single cluster, and the second resource version number is a resource version number obtained by uniformly encoding based on the multiple subclusters to be managed; In response to receiving the resource acquisition request and the target resource version number uploaded by the client, searching the resource event information corresponding to the second resource version number based on the target resource version number; The found target resource event information is sent to the client, and the client is used to manage the multiple subclusters to be managed according to the target resource event information.
2. The method according to claim 1, characterized in that: Before establishing a Watch connection between the server and the multiple subclusters to be managed based on the ListAndWatch mechanism and collecting resource event information of the multiple subclusters to be managed, the method further includes: Obtaining cluster access information and cluster configuration information respectively corresponding to the multiple sub-clusters to be managed; The method of establishing a connection between the server and multiple sub-clusters to be managed based on the ListAndWatch mechanism and collecting resource event information of the multiple sub-clusters to be managed includes: Based on the cluster access information and cluster configuration information, establish a Watch connection between the server and multiple sub-clusters to be managed according to the ListAndWatch mechanism; Determine information collection channels corresponding to the multiple subclusters to be managed respectively, and collect the resource event information through the information collection channels.
3. The method according to claim 2, characterized in that The determining of information collection channels respectively corresponding to the plurality of subclusters to be managed, and collecting the resource event information through the information collection channels, includes: If it is determined that the target resource information in the resource event information to be collected is error resource event information, determining the error category corresponding to the target resource event information; In response to determining that the error category corresponding to the target resource event information is a target error category, resetting a first resource version number corresponding to the target resource event information, and; Refreshing other resource event information except the target resource event information in the sub-cluster to be managed corresponding to the reset target resource event information, and collecting the resource event information based on the refresh processing result; In response to determining that the error category corresponding to the target resource event information is an error category other than the target error category, based on the first resource version number corresponding to the target resource event information, resource event information corresponding to the first resource version number is re-collected to obtain the resource event information.
4. The method according to claim 1, characterized in that: The step of uniformly encoding the first resource version number corresponding to the resource event information to obtain the second resource version number corresponding to the resource event information includes: Aggregating the resource event information in a preset aggregation channel, and determining a name of a subcluster to be managed corresponding to the resource event information in the preset aggregation channel; Perform hash coding based on the name of the subcluster to be managed and the first resource version number to obtain a second resource version number corresponding to the resource event information; After uniformly encoding the first resource version number corresponding to the resource event information to obtain the second resource version number corresponding to the resource event information, the method further includes: The resource event information is stored in a preset sliding window and a preset memory search engine through a preset first-in-first-out pipeline, wherein the preset memory search engine is used to store all resource event information, and the sliding window is used to store resource event information within a preset time period.
5. The method according to claim 1, characterized in that The step of searching, in response to receiving the resource acquisition request and the target resource version number uploaded by the client, the resource event information corresponding to the second resource version number based on the target resource version number includes: In response to receiving a first resource acquisition request sent by the client, sending all resource event information in the preset memory search engine to the client, wherein all resource event information includes the target resource version number, and the first resource acquisition request is sent by the client based on the List mechanism in the ListAndWatch mechanism; In response to receiving a second resource acquisition request and the target resource version number sent by the client, searching the resource event information within the preset time period in the preset sliding window based on the target resource version number, wherein the second resource acquisition request is sent by the client based on the Watch mechanism in the ListAndWatch mechanism; In the preset sliding window, the target resource event information corresponding to the target resource version number is determined, and the target resource event information is the resource event information stored in the preset sliding window after the resource event information corresponding to the target resource version number is stored.
6. The method according to claim 5, characterized in that After sending the found target resource event information to the client, the method further includes: In response to establishing a Watch connection between the server and the client, the resource event information to be forwarded is forwarded to the client through a preset forwarding channel, and the resource event information to be forwarded is the resource event information received by the preset forwarding channel after establishing the Watch connection.
7. A cluster resource management device, characterized in that: include: A collection module is configured to establish a Watch connection between the server and the multiple subclusters to be managed based on the ListAndWatch mechanism, and collect resource event information of the multiple subclusters to be managed; an encoding module configured to uniformly encode a first resource version number corresponding to the resource event information to obtain a second resource version number corresponding to the resource event information, wherein the first resource version number is a resource version number obtained by encoding based on a single cluster, and the second resource version number is a resource version number obtained by uniformly encoding based on the multiple subclusters to be managed; A search module, configured to, in response to receiving a resource acquisition request and a target resource version number uploaded by a client, search the resource event information corresponding to the second resource version number based on the target resource version number; The sending module is configured to send the found target resource event information to the client, and the client is used to manage the multiple subclusters to be managed according to the target resource event information.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
9. An electronic device comprising a storage medium, a processor, and a computer program stored in the storage medium and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 6 is implemented.
10. A computer program product, comprising a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Cited By
Multi-version compatible method and device based on cluster and storage medium
CN119271263A
