Database scheduling method and system across multiple K8S clusters
By deploying the CRD and Operator controllers of the database on multiple K8S clusters, database deployment scheduling across multiple K8S clusters is realized, and problems such as insufficient cross-regional disaster recovery capabilities and high management complexity are solved in the existing technology, and the availability and disaster recovery capabilities of the database are significantly improved.
Patent Information
- Application Number
- CN202411784317.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-06
- Publication Date
- 2025-04-11
Smart Images

Figure CN119807165A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of cloud and distributed database storage, and in particular to a database scheduling method and system across multiple K8S clusters. Background Art
[0002] There are generally two ways to deploy multi-cluster databases in the existing technology: (1) deploying multiple copies of the database in a K8S cluster, which does not have disaster recovery capabilities across data centers and regions; (2) not deploying across K8S clusters in a cloud-native way, using the container pods on the K8S cluster as server nodes, and adjusting the status of database copies according to the data center location to which different nodes belong. It is impossible to automatically and flexibly adjust the copy role, add copies, and other operations.
[0003] The main defects of existing technologies are the lack of cross-regional disaster recovery capabilities, high management complexity, insufficient automation and flexibility, and difficulty in ensuring data consistency. These defects limit the availability, reliability and scalability of database services, especially when facing large-scale distributed deployment and high availability requirements. Summary of the invention
[0004] In order to solve the shortcomings of the prior art, the present invention proposes a database deployment scheduling method across multiple K8S clusters. When multiple K8S clusters are connected to the network, by deploying the CRD and Operator of the database on any K8S cluster, under the condition that all K8S clusters have database mirrors, the network can be established autonomously without relying on external input adjustment, specifically including:
[0005] S1. Basic conditions for configuring multiple K8S clusters;
[0006] S2. Compile the first-level CRD files and controller files across the K8S cluster;
[0007] S3. The controller manages the corresponding resource status according to the definition of the first-level CRD file.
[0008] The basic conditions of S1 include:
[0009] Deploy database images of the same resource type in multiple K8S clusters and ensure network interconnection;
[0010] Deploy corresponding coordination service devices in multiple K8S clusters to complete the networking;
[0011] Deploy a single K8S cluster in the same computer room.
[0012] Exemplarily, the coordination service device may be a ZooKeeper cluster, which is mainly used for data synchronization and management across K8S clusters.
[0013] Exemplarily, the compilation of the first-level CRD file and controller file across the K8S cluster includes:
[0014] Multiple sub-level CRD files are nested in the first-level CRD file. After the user customizes the first-level CRD file, it is split into sub-level files, and the obtained multiple sub-level files are saved in the ZooKeeper cluster;
[0015] The controller periodically splits the first-level CRD file into second-level files. After obtaining the second-level files, the sub-level files are compared with the second-level files. If they are inconsistent, the second-level files directly overwrite the sub-level files; if they are consistent, no processing is performed.
[0016] Exemplarily, the S3 controller manages the corresponding resource status according to the definition of the first-level CRD file, including:
[0017] The controller in each K8S cluster determines the resource status corresponding to the second-level file or sub-level file obtained by splitting the first-level CRD file. If the second-level file or sub-level file is inconsistent with the corresponding resource status, it is reported to the ZooKeeper cluster; the main controller in the main K8S cluster summarizes the resource status reported to the ZooKeeper cluster, and compares the summarized resource status with the resource status defined by the first-level CRD file. If they are the same, the first-level CRD file is re-decomposed into a third-level file and updated to the ZooKeeper cluster;
[0018] If they are not the same, the second-level file or sub-level file is adjusted in a small range according to the first-level CRD file. After the controller of each K8S cluster receives the second-level file or sub-level file that needs to be adjusted, the corresponding resource status is adjusted.
[0019] Exemplarily, the method further includes: the user updates the first-level CRD file from time to time, and the controller updates the split second-level file to the ZooKeeper cluster; after a small range of resource status adjustment, the adjusted resource status will be updated to the ZooKeeper cluster.
[0020] The present application also provides a database scheduling system across multiple K8S clusters, which is characterized by including:
[0021] Configuration module, used to configure the basic conditions of multiple K8S clusters;
[0022] Compilation module, used to compile the first-level CRD files and controller files across K8S clusters;
[0023] A management module is used to manage the corresponding resource status according to the definition of the first-level CRD file.
[0024] The present invention also provides a computer-readable storage medium, characterized in that a computer program is stored on the storage medium, and when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
[0025] The present invention also provides an electronic device, characterized in that it includes a processor and a memory;
[0026] The memory is used to store computer programs;
[0027] The processor is configured to execute the method according to any one of claims 1 to 6 by calling a stored computer program.
[0028] The present invention also relates to a computer program product, comprising a computer program and / or instructions, characterized in that the computer program and / or instructions implement the steps of the above method when executed by a processor.
[0029] The beneficial effects of the present invention are: (1) by deploying multiple copies of the database across multiple K8S clusters and realizing automatic switching, the availability and disaster recovery capabilities of the database are significantly improved; (2) the use of CRD and Operator controllers simplifies the deployment and management of databases across multiple K8S clusters, making database management more centralized and automated; (3) when a database or K8S cluster fails, the system can automatically recover and adjust, reducing manual intervention, enhancing the system's elasticity and self-healing capabilities, and ensuring business continuity; (4) by centrally managing database instances and automating database-related operation and maintenance tasks, the complexity of database operation and maintenance across multiple K8S clusters is reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 This is a flow chart of a database scheduling method across multiple K8S clusters of the present invention.
[0031] Figure 2 A schematic diagram of a database scheduling deployment structure across multiple K8S clusters in the present invention
[0032] Figure 3 This is a schematic diagram of the structure of a database scheduling system across multiple K8S clusters of the present invention. DETAILED DESCRIPTION
[0033] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. The components of the embodiments of the present invention generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the claimed invention, but merely represents selected embodiments of the present invention. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0034] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in the subsequent drawings. At the same time, in the description of the present invention, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.
[0035] Technical term explanation:
[0036] Kubernetes (K8S) cluster is a container orchestration platform that provides functions such as container scheduling and resource management within the cluster. In this solution, multiple K8S clusters are deployed across multiple data centers to achieve distributed resource management and high availability.
[0037] Operator is a controller of K8S, which helps the cluster to implement custom control of CRD and split the definition of CRD into smaller resource units for refined control. In this solution, Operator not only manages the life cycle of resources, but also is responsible for status checking and synchronization across K8S clusters.
[0038] Custom Resource Definition (CRD) allows users to define new K8S resource types that can contain custom configuration, status, and other information. In this solution, CRD defines the resources that need to be managed across K8S clusters, such as databases, services, and so on.
[0039] ZooKeeper cluster (ZK cluster), ZK cluster is the metadata management and synchronization center, used to share and synchronize resource status and configuration information across K8S clusters.
[0040] The relationship between ZK and K8S cluster: ZK cluster provides cross-network data synchronization between different K8S clusters, allowing multiple K8S clusters to share resource status.
[0041] Relationship between ZK and Operator: The Operator in each K8S cluster will report the status and configuration changes to the ZK cluster. The Operator in the main cluster will obtain the status summary of other clusters in ZK, determine whether resources need to be adjusted, and update them to the ZK cluster. The ZK cluster is responsible for synchronizing resource data and maintaining status consistency between multiple K8S clusters.
[0042] Relationship between CRD and K8S: CRD extends the native resource type of K8S, allowing users to create and manage custom resources in the K8S API. Multiple K8S clusters use the same CRD definition to maintain resource consistency.
[0043] Relationship between CRD and Operator: Operator will monitor and manage the resources in CRD according to the definition of CRD, and regularly check whether the status is as expected. Operator can break down CRD definition into smaller resource units (such as crd1.1, crd1.2, etc.) for more fine-grained control. Operator automatically creates, updates, and deletes these resources based on the resources defined in the CRD file, and regularly checks the resource status to ensure that it is consistent with the CRD definition.
[0044] Relationship between Operator and ZK: Operator regularly reports the resource status of each K8S cluster to ZK. The Operator of the main cluster summarizes the status from the ZK cluster and makes judgments. If adjustments are required, the adjusted CRD will be pushed to other clusters to maintain the overall consistency.
[0045] Relationship between K8S and CRD: K8S allows its API to be extended through CRD, defining new resource types and specifications for custom resources (such as databases, services, etc.), so that users can manage resources that they do not originally have in K8S; expand processing capabilities, resources that the original cluster cannot handle;
[0046] The relationship between K8S and Operator: In each K8S cluster, Operator monitors and manages the life cycle of custom resources, regularly checks the resource status and reports it to the ZK cluster.
[0047] The first aspect of the present application provides a database scheduling method across multiple K8S clusters, such as Figure 1 As shown, specifically including:
[0048] S1. Basic conditions for configuring multiple K8S clusters;
[0049] S2. Compile the first-level CRD files and controller files across the K8S cluster;
[0050] S3. The controller manages the corresponding resource status according to the definition of the first-level CRD file.
[0051] Specifically, the basic conditions of this application also include networking, deployment of a single K8S cluster, network connectivity across clusters, deployment and processing of database mirroring, and ensuring network interconnection.
[0052] Networking: By deploying distributed collaboration devices, network connections can be established between multiple Kubernetes clusters to achieve service and load balancing.
[0053] Cross-cluster network connectivity: Ensuring network connectivity between multiple Kubernetes clusters is a prerequisite for cross-cluster deployment. By deploying the database's CRD (Custom Resource Definitions) and Operator controller on any K8S cluster, you can autonomously establish networking without relying on external input adjustments, provided that all K8S clusters have database mirroring.
[0054] Data synchronization: The distributed coordination service is also responsible for synchronizing database status and configuration information between different clusters to ensure that database instances in all clusters remain consistent.
[0055] A ZK-like coordination service is used to manage cluster state and synchronize information. This service can ensure data consistency and service discovery across multiple data centers or regions.
[0056] like Figure 2 As shown in the figure, the database deployment scheduling across multiple K8S clusters is that the three K8S clusters are located locally, in the same city, and in a different location, and the three K8S are connected by network. Interconnected ZK clusters are deployed on the three K8S clusters, and have the same database image and database operator controller. Any K8S cluster can be used as an exposed deployment service for external use, and the deployment service on any K8S cluster is split through the database operator controller.
[0057] Metadata synchronization across multiple K8S clusters is performed through the Zookeeper cluster. Multiple copies of the database are deployed through any K8S cluster. The component status of the distributed database on different K8S clusters is observed through the ZooKeeper cluster. The master-slave requirements between the copies of the database are described through the CRD file. The master-slave control and switching control across the K8S clusters are performed through the operator. Finally, the status of the distributed database is uniformly adjusted through the master operator controller of the unified master K8S cluster. In addition, the interaction process between the Operator and GDB specifically includes: after the first-level CRD file (CRD1) is disassembled to obtain the secondary file (crd 1.x), it is uploaded to the ZK cluster for storage; the operator of each K8S cluster completes the action of reporting the status to the ZK cluster; the main controller compares the complete topological status on the ZK cluster with the topological logic in the original CRD1, triggering the corresponding maintenance action (the topological structure after maintenance). The maintenance action requires each K8S cluster to be disassembled into secondary files for operation; the networking and interaction of the ZK cluster depend on the network, and the networking of GDB itself depends on the network;
[0058] The Operator controller periodically splits CRD into smaller units, compares the split second-level CRD files with crd1.1 (secondary file) stored in the ZK cluster, and directly overwrites crd1.1 (secondary file) in the ZK cluster if they are inconsistent.
[0059] The Operator controller determines whether the overwritten second-level file or sub-level file conforms to the corresponding resource status. If the defined status is inconsistent with the actual resource status, the exception is reported to the ZK cluster.
[0060] Operator determines whether the resource reporting status on the ZK cluster needs to be adjusted. The judgment is based on the resource description of the first-level CRD file. If it meets the rules, it will be split into smaller crd1.1 (third-level file) and updated to the ZK cluster; if it does not meet the rules, after re-splitting the first-level CRD file to obtain a partially non-compliant fourth-level file, the fourth-level file with the smallest range split will be pushed to the ZK cluster (the inconsistent part will be re-split and replaced, and the consistent part does not need to be replaced). After receiving the fourth-level file, the corresponding K8S cluster will make the minimum adjustment to the corresponding resource status according to the received fourth-level file information, and the Operator controller will make the adjustment. The adjusted resource status will be pushed to the ZK cluster, and the controller under the main K8S cluster will get a summary resource status view.
[0061] This application also provides a database scheduling system across multiple K8S clusters, such as Figure 3As shown, including:
[0062] Configuration module, used to configure the basic conditions of multiple K8S clusters;
[0063] Compilation module, used to compile the first-level CRD files and controller files across K8S clusters;
[0064] A management module is used to manage the corresponding resource status according to the definition of the first-level CRD file.
[0065] The management module is also used to automatically process complex database operations, such as data persistence, backup, recovery, and capacity expansion. By designing an efficient Operator controller, it is possible to ensure that the database state is consistent with the definition of the CRD file, such as creating a database instance, configuring a backup strategy, etc.
[0066] The device also includes a coordination module for coordinating and managing cluster status and information synchronization. When spanning multiple data centers or regions, a distributed coordination service is required to manage cluster status and synchronize information, such as ZooKeeper. This service can solve the problems of data consistency and service discovery, especially when the network complexity increases.
[0067] By using this system, the above-mentioned processing method can be executed and the corresponding technical effects can be achieved.
[0068] An embodiment of the present invention also provides a computer-readable storage medium capable of implementing all the steps in the method in the above embodiment, wherein a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, all the steps in the method in the above embodiment are implemented.
[0069] An embodiment of the present invention also provides an electronic device for executing the above method. As an implementation device of the method, the electronic device has at least a processor and a memory, and in particular, the memory stores data and related computer programs required for executing the method, and the processor calls the data and programs in the memory to execute all steps of the implementation method and obtains the corresponding technical effect.
[0070] Preferably, the electronic device may include a bus architecture, the bus may include any number of interconnected buses and bridges, and the bus will include various circuits linked together by one or more processors and memories. The bus may also link together various other circuits such as peripherals, voltage regulators, and power management circuits, which are all well known in the art and are therefore not further described herein. The bus interface provides an interface between the bus and the receiver and transmitter. The receiver and transmitter may be the same component, i.e., a transceiver, providing a unit for communicating with various other systems over a transmission medium. The processor is responsible for managing the bus and general processing, while the memory may be used to store data used by the processor when performing operations.
[0071] In addition, the electronic device may further include components such as a communication module, an input unit, an audio processor, a display, and a power supply. The processor (or controller, operation control) used may include a microprocessor or other processor device and / or a logic device, which receives input and controls the operation of various components of the electronic device; the memory may be one or more of a cache, a flash memory, a hard drive, a removable medium, a volatile memory, a non-volatile memory, or other suitable devices, which may store the above-mentioned related data information, and may also store a program for executing related information, and the processor may execute the program stored in the memory to realize information storage or processing, etc.; the input unit is used to provide input to the processor, for example, it may be a key or a touch input device; the power supply is used to provide power to the electronic device; the display is used to display display objects such as images and text, for example, it may be an LCD display. The communication module is a transmitter / receiver that sends and receives signals via an antenna. The communication module (transmitter / receiver) is coupled to the processor to provide input signals and receive output signals, which may be the same as the case of a conventional mobile communication terminal. Based on different communication technologies, multiple communication modules may be provided in the same electronic device, such as a cellular network module, a Bluetooth module and / or a wireless local area network module, etc. The communication module (transmitter / receiver) is also coupled to a speaker and a microphone via an audio processor to provide an audio output via the speaker and receive an audio input from the microphone, thereby realizing a common telecommunication function. The audio processor may include any suitable buffer, decoder, amplifier, etc. In addition, the audio processor is also coupled to a central processor, so that recording can be performed on the machine through the microphone, and the sound stored on the machine can be played through the speaker.
[0072] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0073] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A system that specifies the functions of a box or multiple boxes.
[0074] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory produce a product including an instruction system, which is implemented in the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0075] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps of the functions specified in a box or multiple boxes. Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they know the basic creative concept. Therefore, the attached claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.
[0076] The above is only a preferred specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A database scheduling method across multiple K8S clusters, characterized in that: include: S1. Basic conditions for configuring multiple K8S clusters; S2. Compile the first-level CRD files and controller files across the K8S cluster; S3. The controller manages the corresponding resource status according to the definition of the first-level CRD file.
2. The method according to claim 1, characterized in that The basic conditions of S1 include: Deploy database images of the same resource type in multiple K8S clusters and ensure network interconnection; Deploy corresponding coordination service devices in multiple K8S clusters to complete the networking; Deploy a single K8S cluster in the same computer room.
3. The method according to claim 1, characterized in that: The coordination service device can be a ZooKeeper cluster, which is mainly used for cross-K8S cluster data synchronization and management.
4. The method according to claim 1, characterized in that: The compilation of the first-level CRD file and controller file across the K8S cluster includes: Multiple sub-level CRD files are nested in the first-level CRD file. After the user customizes the first-level CRD file, it is split into sub-level files, and the obtained multiple sub-level files are saved in the ZooKeeper cluster; The controller periodically splits the first-level CRD file into second-level files. After obtaining the second-level files, the sub-level files are compared with the second-level files. If they are inconsistent, the second-level files directly overwrite the sub-level files; if they are consistent, no processing is performed.
5. The method according to claim 4, characterized in that The S3 controller manages the corresponding resource status according to the definition of the first-level CRD file, including: The controller in each K8S cluster determines the resource status corresponding to the second-level file or sub-level file obtained by splitting the first-level CRD file. If the second-level file or sub-level file is inconsistent with the corresponding resource status, it is reported to the ZooKeeper cluster; the main controller in the main K8S cluster summarizes the resource status reported to the ZooKeeper cluster, and compares the summarized resource status with the resource status defined by the first-level CRD file. If they are the same, the first-level CRD file is re-decomposed into a third-level file and updated to the ZooKeeper cluster; If they are not the same, the second-level file or sub-level file is adjusted in a small range according to the first-level CRD file. After the controller of each K8S cluster receives the second-level file or sub-level file that needs to be adjusted, the corresponding resource status is adjusted.
6. The method according to claim 5, characterized in that The method further includes: the user updates the first-level CRD file from time to time, and the controller updates the split second-level file to the ZooKeeper cluster; After a small range of resource status adjustments, the adjusted resource status will be updated to In a ZooKeeper cluster.
7. A database scheduling system across multiple K8S clusters, characterized in that: include: Configuration module, used to configure the basic conditions of multiple K8S clusters; Compilation module, used to compile the first-level CRD files and controller files across K8S clusters; A management module is used to manage the corresponding resource status according to the definition of the first-level CRD file.
8. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and 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, characterized in that: including a processor and a memory; The memory is used to store computer programs; The processor is configured to execute the method according to any one of claims 1 to 6 by calling a stored computer program.
10. A computer program product comprising a computer program and / or instructions, characterized in that: When the computer program and / or the instructions are executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.