A Kubernetes cluster federation system and implementation method thereof

By setting up the cluster controller, state controller, synchronization controller, scheduler and command controller in the Kubernetes system, and using CRD resources and admission webhook, the unified management of the Kubernetes cluster federation is realized and the service discovery and cross-cluster resource discovery and development are solved. Orchestration issues improve management efficiency and compatibility.

CN113742033BActive Publication Date: 2024-08-23GUANGXI DONGXIN DIGITAL CONSTR INFORMATION TECH CO LTD
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202111048076.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-08
Publication Date
2024-08-23
Estimated Expiration
2041-09-08

AI Technical Summary

Technical Problem

Kubernetes cluster federation has problems with service discovery and orchestration of cross-cluster resources. It is difficult to effectively manage and uniformly schedule the resources of multiple Kubernetes clusters with existing technology.

Method used

By setting up the cluster controller, state controller, synchronization controller, scheduler and command controller in the Kubernetes system, the master-slave cluster management and resource scheduling of the Kubernetes cluster federation is realized, and CRD resources and admission webhook access control are used to achieve a single The cluster manages multiple Kubernetes clusters in a unified manner.

Benefits of technology

It realizes the complete federation function of Kubernetes cluster, solves the problem of service discovery and orchestration of cross-cluster resources, simplifies management and maintenance, and has backward-compatible update capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113742033B
    Figure CN113742033B
Patent Text Reader

Abstract

The present invention discloses a method for realizing a Kubernetes cluster federation, relates to the technical field of network communication, and solves the service discovery and orchestration problems of cross-cluster resources of Kubernetes. The method comprises: setting a cluster controller, a state controller, a synchronization controller, a scheduler, and a command controller; initializing the cluster controller, the state controller, the synchronization controller, the scheduler, and the command controller to a Kubernetes system, so that the Kubernetes becomes the main cluster of the federated cluster, and the cluster controller, the state controller, the synchronization controller, the scheduler, and the command controller can run at least one copy. The present invention also discloses a Kubernetes cluster federation system. The present invention runs the cluster controller, the state controller, the synchronization controller, the scheduler, and the command controller in the Kubernetes system, utilizes the CRD resources and admission webhook admission control built in Kubernetes, achieves a complete cluster federation function, realizes unified management of multiple Kubernetes clusters by a single cluster, and can effectively solve the service discovery and orchestration problems of cross-cluster resources of Kubernetes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of network communication technology, and more specifically, to a Kubernetes cluster federation system and an implementation method thereof. Background Art

[0002] With the continuous development of cloud computing, the technical architecture of IT infrastructure is undergoing drastic changes. Kubernetes reduces the development, management, deployment and operation and maintenance costs of applications from a new perspective. Its architecture has become the de facto standard for rapid development, testing and deployment of applications. It has been deployed on a large scale in production environments and adopted by more and more companies.

[0003] For enterprise-level customers, since there are security and compliance requirements for data during the cloud migration process, multi-cloud and hybrid cloud methods are usually used for cloud migration. Before the birth of Kubernetes and container technology, customized development was required for each cloud service provider to achieve multi-cloud and hybrid cloud. With Kubernetes and containers, local data centers and cloud service providers' Kubernetes clusters can provide consistent interfaces, so that applications do not need to be directly bound to specific cloud service providers in most cases, unlocking cloud service provider lock-in and avoiding services from being solely dependent on a certain cloud service provider. At the same time, service availability is improved, and lower-cost solutions can be selected based on the prices of cloud service providers, and elastic expansion of business emergencies is guaranteed, and expansion to other cloud service providers is required when the capacity of a certain cloud service provider is insufficient.

[0004] However, building a Kubernetes cluster federation has problems with Kubernetes' cross-cluster resource service discovery and orchestration. Summary of the invention

[0005] The technical problem to be solved by the present invention is to address the above-mentioned deficiencies in the prior art. One purpose of the present invention is to provide a method for implementing a Kubernetes cluster federation.

[0006] The second objective of the present invention is to provide a Kubernetes cluster federation system.

[0007] In order to achieve the above-mentioned purpose one, the present invention provides a Kubernetes cluster federation implementation method, which sets a cluster controller, a state controller, a synchronization controller, a scheduler, and a command controller;

[0008] Initialize the cluster controller, state controller, synchronization controller, scheduler, and command controller into the kubernetes system, so that the kubernetes becomes the master cluster of the federated cluster. The cluster controller, state controller, synchronization controller, scheduler, and command controller can run at least one copy.

[0009] Configure the federated cluster through the command controller and interact with the administrator, including initializing the federated cluster, adding slave clusters, and viewing information about the federated cluster;

[0010] Managing the life cycle of the federated cluster through the cluster controller, and checking the health of the master cluster and the slave cluster;

[0011] The state controller senses and caches the running state of the federated resources from the cluster;

[0012] Distributing workload instances to different clusters of the federated cluster by the scheduler;

[0013] The synchronization controller monitors the expected value and current operating status of the federated resources of the slave cluster. When the expected value and the operating status are inconsistent, the synchronization controller is responsible for operating the federated resources of the slave cluster to keep the operating status of the resource consistent with the expected value.

[0014] As a further improvement, the command controller operates as follows:

[0015] Step 1.1. The command controller is initialized to run to the main cluster, communicates with the kube-apiserver of the main cluster, and obtains the configuration information of the federated cluster; if the acquisition is successful, execute step 1.3; otherwise, execute step 1.2;

[0016] Step 1.2. The command controller initializes the configuration information of the federated cluster; if the initialization is successful, the command controller is started successfully and step 1.3 is executed; otherwise, step 1.1 is re-executed;

[0017] Step 1.3. The command controller waits for the user to input a command;

[0018] Step 1.4. When the command controller receives the add slave cluster command, the add slave cluster step is executed;

[0019] Step 1.5. When the command controller receives the delete from cluster command, the delete from cluster step is executed;

[0020] Step 1.6. When the command controller receives a request to display a list of slave clusters, it searches for resources from the cluster and displays them;

[0021] Step 1.7. Perform step 1.3.

[0022] Furthermore, the steps of adding a slave cluster include:

[0023] Step 1.4.1. The command controller receives configuration file information for adding a slave cluster;

[0024] Step 1.4.2. The command controller generates a CRD resource of Kubernetes according to the configuration file information of the slave cluster;

[0025] Step 1.4.3. The command controller connects to the kube-apiserver of the slave cluster according to the connection information of the CRD resource;

[0026] Step 1.4.4. The command controller creates a role resource on the slave cluster, and returns a success message if the creation is successful; otherwise, it returns a failure message.

[0027] Further, the steps of performing the deletion from the cluster include:

[0028] Step 1.5.1. The command controller receives a request to delete a specified slave cluster and searches for connection information of CRD resources in the resources in the slave cluster;

[0029] Step 1.5.2. The command controller connects to the specified slave cluster kube-apiserver according to the connection information in step 1.5.1, and deletes the relevant information on the specified slave cluster;

[0030] Step 1.5.3. The command controller deletes the CRD resource in the specified slave cluster. If the deletion is successful, a success message is returned; otherwise, a failure message is returned.

[0031] Furthermore, the cluster controller operates as follows:

[0032] Step 2.1. The cluster controller is initialized and runs to the main cluster, communicates with the kube-apiserver of the main cluster, obtains the configuration information of the federated cluster and the list of slave clusters; if the acquisition is successful, execute step 2.2; otherwise, continue to execute this step;

[0033] Step 2.2. The cluster controller records the current time T1, traverses the slave cluster list to obtain slave cluster access information, and then accesses the kube-apiserver of the slave cluster; when the request can be returned correctly and the return value is the set value, it means that the slave cluster is in a healthy state, otherwise it means that the slave cluster is in an unhealthy state;

[0034] If the health status changes, the new health information is written into the slave cluster list, and the current time T2 is recorded after the traversal is completed;

[0035] Step 2.3. The cluster controller obtains the health check delay time T according to the configuration information of the federated cluster. If T < T2 - T1, execute Step 2.2; otherwise, repeat this step.

[0036] Further, the status controller operates as follows:

[0037] Step 3.1. The status controller initializes and runs to the master cluster, communicates with the kube-apiserver of the master cluster, and obtains the configuration information and cluster list of the federated cluster. If the acquisition is successful, execute Step 3.2; otherwise, continue to execute this step.

[0038] Step 3.2. The status controller traverses and obtains all running federated resources.

[0039] Step 3.3. The status controller obtains the current single federated resource, subscribes to the changes of the current resource using the kubernetes Informer mode, and caches them to the master cluster. Loop this step until all running federated resources are monitored.

[0040] Step 3.4. The status controller continuously monitors the changes of all running federated resources. When changes in federated resources occur, cache the changed information to the master cluster.

[0041] Further, the scheduler operates as follows:

[0042] Step 4.1. The scheduler initializes and runs to the master cluster, communicates with the kube-apiserver of the master cluster. If successful, execute Step 4.2; otherwise, continue to execute this step.

[0043] Step 4.2. The scheduler records the current time T3, and obtains the running Deployment federated resources, ReplicaSet federated resources, Statefulset federated resources, and Daemonset federated resources.

[0044] Step 4.3. The scheduler obtains the current single federated resource mentioned in Step 4.2, compares the scheduling status of the current federated resource, and extracts the newly created kubernetes Pods, unscheduled kubernetes Pods, and kubernetes Pods with scheduling failures.

[0045] Step 4.4. The scheduler calls the set scheduling algorithm to schedule the currently obtained resources to a suitable cluster, writes the scheduling result into the resource, and the synchronization controller performs resource synchronization.

[0046] Step 4.5. If the scheduler has traversed all the resources mentioned in step 4.2, execute step 4.6; otherwise, the scheduler obtains the next resource and executes step 4.3;

[0047] Step 4.6. The scheduler obtains the current time T4, T5 = T4-T3, and if T5> the set time, execute step 4.2; otherwise, wait for the set time-T5 and then execute step 4.2.

[0048] Furthermore, setting the scheduling algorithm includes:

[0049] Step 4.4.1. Get the current resource type, kubernetes nodes, cluster information, and resource usage;

[0050] Step 4.4.2. Orchestrate the Kubernetes resources to obtain the PSP file based on the total number of replicas and the cluster's defined strategy;

[0051] Step 4.4.3. Perform a priority sorting operation according to the PSP file to prioritize nodes suitable for resource operation;

[0052] Step 4.4.4. Select one of the clusters with the highest final priority as the result of resource scheduling.

[0053] Furthermore, the synchronization controller operates as follows:

[0054] Step 5.1. The synchronization controller is initialized to run to the main cluster and communicate with the kube-apiserver of the main cluster. If successful, execute step 5.2; otherwise, continue to execute this step;

[0055] Step 5.2. The synchronization controller records the current time T6 and traverses the list of resources that need to be synchronized;

[0056] Step 5.3. The synchronization controller obtains a single resource and the latest state of the resource. If the expected state of the resource is inconsistent with the latest state, execute step 5.4; otherwise, execute step 5.6;

[0057] Step 5.4. The synchronization controller obtains the slave cluster name from the resource, queries the master cluster for the slave cluster connection information based on the slave cluster name, and communicates with the kube-apiserver of the slave cluster. If successful, execute step 5.5, otherwise execute step 5.6;

[0058] Step 5.5. The synchronization controller creates or modifies the corresponding resource information on the slave cluster according to the acquired resource data, and executes step 5.6;

[0059] Step 5.6. If the synchronization controller has traversed all resources, execute step 5.7; otherwise, execute step 5.3;

[0060] Step 5.7. If the synchronization controller obtains the current time T7, T8 = T7-T6, if T8> the set time, execute step 5.2; otherwise, wait for the set time-T8 and then execute step 5.2.

[0061] In order to achieve the above-mentioned second objective, the present invention provides a Kubernetes cluster federation system, including a cluster controller, a state controller, a synchronization controller, a scheduler, and a command controller;

[0062] The cluster controller, state controller, synchronization controller, scheduler, and command controller are initialized into the Kubernetes system and run according to the above-mentioned Kubernetes cluster federation implementation method.

[0063] Beneficial Effects

[0064] Compared with the prior art, the present invention has the following advantages:

[0065] The present invention runs a cluster controller, a state controller, a synchronization controller, a scheduler, and a command controller in a kubernetes system, and utilizes the CRD resources and admission webhook admission control built into kubernetes to achieve a complete cluster federation function, realize unified management of multiple Kubernetes clusters by a single cluster, and can effectively solve the service discovery and orchestration problems of cross-cluster resources of kubernetes. The present invention realizes a complete cluster federation function, is easy to maintain, and by cleverly utilizing Kubernetes CRD resources, the present invention is unbound from a specific Kubernetes version and is backward compatible with updated versions. BRIEF DESCRIPTION OF THE DRAWINGS

[0066] Figure 1 This is a schematic diagram of the present invention. DETAILED DESCRIPTION

[0067] The present invention will be further described below with reference to the specific embodiments in the accompanying drawings.

[0068] See also Figure 1 , a kubernetes cluster federation implementation method, setting cluster controller ClusterController, status controller Status Controller, synchronization controller Sync Controller, scheduler Scheduler, command controller Command Controller;

[0069] Initialize the cluster controller Cluster Controller, status controller Status Controller, synchronization controller Sync Controller, scheduler Scheduler, and command controller Command Controller to the Kubernetes system, making the Kubernetes system the master cluster of the federated cluster. The cluster controller Cluster Controller, status controller Status Controller, synchronization controller Sync Controller, scheduler Scheduler, and command controller Command Controller can run at least one copy;

[0070] Configure the federated cluster through the Command Controller and interact with the administrator, including initializing the federated cluster, adding slave clusters, and viewing the federated cluster information.

[0071] The Cluster Controller manages the life cycle of the federated cluster and checks the health of the master and slave clusters.

[0072] The Status Controller senses and caches the running status of federated resources in the cluster;

[0073] Use the scheduler to distribute workload instances to different clusters in the federated cluster.

[0074] The Sync Controller monitors the expected value and current running status of the federated resources of the slave cluster. When the expected value and the running status are inconsistent, the Sync Controller is responsible for operating the federated resources of the slave cluster to make the running status of the resource consistent with the expected value.

[0075] The Command Controller operates as follows:

[0076] Step 1.1. The command controller Command Controller is initialized to run in the main cluster, communicates with the kube-apiserver of the main cluster, and obtains the configuration information CaihFederalConfig of the federal cluster; if the acquisition is successful, execute step 1.3; otherwise, execute step 1.2;

[0077] Step 1.2. Command Controller initializes the configuration information of the federated cluster; if the initialization is successful, the Command Controller is started successfully and step 1.3 is executed; otherwise, step 1.1 is executed again; the initialized configuration information is as follows:

[0078] -Role, general role information;

[0079] -ServiceAccount, service account information;

[0080] -ClusterRoleBinding, cluster role and account binding information;

[0081] -RoleBinding, common role and account binding information;

[0082] -CaihFederalCluster, a CRD resource of kubernetes, is used to save the connection information of the slave cluster. Initialization only declares this resource without any content.

[0083] -CaihFederalConfig, a CRD resource of Kubernetes, is used to describe the configuration information of the federated cluster, including the following:

[0084] - Health check delay time;

[0085] -Failure retry time;

[0086] -Whether to enable domain name service;

[0087] -Whether to enable the scheduler;

[0088] -Whether to enable cross-cluster service discovery;

[0089] -ValidatingWebhookConfiguration and MutatingWebhookConfiguration, used to unify the format and associated calls when cluster federation generates resources;

[0090] -CaihFederalCRDs, federalized Kubernetes resources, enables the federalization of Namespace, Deployment, Service, ConfigMap, Secret, Ingress, Job, ReplicaSet, ClusterRole, Role, ServiceAccount, ClusterRoleBinding, and RoleBinding resources during initialization. Other resources can also be federalized using the command line;

[0091] Step 1.3. Command Controller waits for the user to input a command;

[0092] Step 1.4. When the command controller receives the command to add a slave cluster, the step of adding a slave cluster is executed;

[0093] Step 1.5. When the command controller receives the command to delete the slave cluster, the step of deleting the slave cluster is executed;

[0094] Step 1.6. When the command controller receives a request to display a list of slave clusters, it searches for resources of the slave clusters and displays them; that is, it searches for resources of the slave clusters in the CaihFederalCluster resources and displays them;

[0095] Step 1.7. Perform step 1.3.

[0096] The steps to add a slave cluster include:

[0097] Step 1.4.1. The Command Controller receives the YAML configuration file information for adding the slave cluster; the YAML configuration file information is as follows:

[0098] -Exclusive namespace for the federal cluster: caih-federal

[0099] -ClusterRole, cluster role information

[0100] - From the cluster URL, CA authentication information and cluster name of the cluster

[0101] - From the user configuration information of the cluster, including user name, authentication information cert, authentication key

[0102] -Configuration of association between user name and cluster

[0103] The file format is as follows:

[0104]

[0105] Step 1.4.2. The command controller generates a CRD resource of Kubernetes based on the information in the yaml configuration file of the cluster, that is, generates a CRD resource of CaihFederalCluster;

[0106] Step 1.4.3. The command controller connects to the kube-apiserver of the slave cluster according to the connection information of the CRD resource (that is, according to the connection information of CaihFederalCluster);

[0107] Step 1.4.4. The Command Controller creates a role resource on the slave cluster. If the creation is successful, a success message is returned; otherwise, a failure message is returned.

[0108] The role resources are as follows:

[0109] -Create the namespace where the federal cluster is located: caih-federal;

[0110] -ServiceAccount, service account information;

[0111] -ClusterRole, cluster role information;

[0112] -ClusterRoleBinding, cluster role and account binding information;

[0113] -Secret, account key;

[0114] - CaihFederalCRDs, federalized Kubernetes resources, the same as the CaihFederalCRDs initialized in the main cluster in step 1.2.

[0115] The steps to perform a deletion from a cluster include:

[0116] Step 1.5.1. The command controller receives a request to delete a specified slave cluster, and searches for the connection information of the CRD resource in the resources of the slave cluster, that is, searches for the connection information of the slave cluster in the CaihFederalCluster resource;

[0117] Step 1.5.2. The command controller connects to the specified slave cluster kube-apiserver according to the connection information in step 1.5.1, and deletes the relevant information on the specified slave cluster;

[0118] Step 1.5.3. Command the controller to delete the CRD resource in the specified slave cluster, that is, delete the CaihFederalCluster resource. If the deletion is successful, a success message is returned; otherwise, a failure message is returned.

[0119] The Cluster Controller operates as follows:

[0120] Step 2.1. The Cluster Controller initializes and runs to the master cluster, communicates with the kube-apiserver of the master cluster, and obtains the configuration information CaihFederalConfig of the federated cluster and the list of slave clusters CaihFederalCluster; if the acquisition is successful, proceed to Step 2.2; otherwise, continue to execute this step;

[0121] Step 2.2. The Cluster Controller records the current time T1, traverses the list of slave clusters CaihFederalCluster to obtain the access information of the slave clusters, and then accesses the kube-apiserver of the slave clusters; when the request can be correctly returned and the return value is the set value, in this embodiment, the set value is 200, which indicates that the slave cluster is in a healthy state, otherwise it indicates that the slave cluster is in an unhealthy state;

[0122] If there is a change in the health status, write the new health information into the list of slave clusters CaihFederalCluster, and record the current time T2 after the traversal is completed;

[0123] Step 2.3. The Cluster Controller obtains the health check delay time T according to the configuration information CaihFederalConfig of the federated cluster. If T < T2 - T1, execute Step 2.2; otherwise, repeat this step.

[0124] The Status Controller operates as follows:

[0125] Step 3.1. The Status Controller initializes and runs to the master cluster, communicates with the kube-apiserver of the master cluster, and obtains the configuration information CaihFederalConfig of the federated cluster and the list of clusters CaihFederalCluster; if the acquisition is successful, proceed to Step 3.2; otherwise, continue to execute this step;

[0126] Step 3.2. The Status Controller traverses and obtains all the running federated resources;

[0127] Step 3.3. The Status Controller obtains the current single federated resource, subscribes to the changes of the current resource using the Kubernetes Informer mode, and caches it to the main cluster. This step is repeated until all running federated resources are monitored.

[0128] Step 3.4. The Status Controller continuously monitors changes in all running federated resources, and when a federated resource changes, it caches the change information to the main cluster.

[0129] The scheduler runs as follows:

[0130] Step 4.1. The scheduler is initialized and runs to the main cluster, communicating with the kube-apiserver of the main cluster. If successful, proceed to step 4.2; otherwise, continue to this step;

[0131] Step 4.2. The scheduler records the current time T3 and obtains the running Deployment federal resources, ReplicaSet federal resources, Statefulset federal resources, and Daemonset federal resources;

[0132] Step 4.3. The scheduler obtains the current single federated resource mentioned in step 4.2, compares the scheduling status of the current federated resource, and extracts the newly created Kubernetes Pod, the unscheduled Kubernetes Pod, and the Kubernetes Pod that failed to be scheduled;

[0133] Step 4.4. The scheduler calls the set scheduling algorithm to schedule the currently acquired resources to the appropriate cluster, writes the scheduling results into the resource, and the synchronization controller performs resource synchronization;

[0134] Step 4.5. If the scheduler has traversed all the resources mentioned in step 4.2, execute step 4.6; otherwise, the scheduler obtains the next resource and executes step 4.3;

[0135] Step 4.6. The scheduler obtains the current time T4, T5 = T4-T3. If T5> the set time, execute step 4.2; otherwise, wait for the set time-T5 and then execute step 4.2.

[0136] Setting the scheduling algorithm includes:

[0137] Step 4.4.1. Get the current resource type, kubernetes nodes, cluster information, and resource usage; for example, how many scheduled pods are on the cluster, the resources that have been applied for, and the resources that can be allocated; Get kubernetesnodes, that is, get the information of the slave cluster where the current resource is located and all the nodes in the slave cluster, to confirm which node the pods related to Deployment, ReplicaSet, Statefulset, and Daemonset should be scheduled to;

[0138] Step 4.4.2. Based on the total number of replicas and the defined strategy of the cluster, orchestrate the Kubernetes resources to obtain the PSP (PodSchedulingPreference) file;

[0139] Step 4.4.3. Perform a priority sorting operation according to the PSP file to prioritize nodes suitable for resource operation;

[0140] Step 4.4.4. Select one of the clusters with the highest final priority as the result of resource scheduling.

[0141] The Sync Controller operates as follows:

[0142] Step 5.1. The Sync Controller is initialized and runs to the main cluster, communicating with the kube-apiserver of the main cluster. If successful, proceed to step 5.2; otherwise, continue with this step;

[0143] Step 5.2. The synchronization controller Sync Controller records the current time T6 and traverses the list of resources that need to be synchronized;

[0144] Step 5.3. The synchronization controller Sync Controller obtains a single resource and the latest state of the resource. If the expected state of the resource is inconsistent with the latest state, execute step 5.4; otherwise, execute step 5.6;

[0145] Step 5.4. The Sync Controller obtains the slave cluster name from the resource, queries the master cluster for the slave cluster connection information based on the slave cluster name, and communicates with the kube-apiserver of the slave cluster. If successful, execute step 5.5, otherwise execute step 5.6;

[0146] Step 5.5. The Sync Controller creates or modifies the corresponding resource information on the slave cluster according to the acquired resource data, and executes step 5.6;

[0147] Step 5.6. If the Sync Controller has traversed all resources, execute step 5.7; otherwise, execute step 5.3;

[0148] Step 5.7. If the synchronization controller Sync Controller obtains the current time T7, T8 = T7-T6, if T8> the set time, then execute step 5.2; otherwise, wait for the set time-T8 and then execute step 5.2.

[0149] A kubernetes cluster federation system includes a cluster controller Cluster Controller, a state controller Status Controller, a synchronization controller Sync Controller, a scheduler Scheduler, and a command controller Command Controller;

[0150] The cluster controller Cluster Controller, the state controller Status Controller, the synchronization controller Sync Controller, the scheduler Scheduler, and the command controller Command Controller are initialized into the kubernetes system and run according to the above-mentioned kubernetes cluster federation implementation method.

[0151] The above are only preferred embodiments of the present invention. It should be pointed out that for those skilled in the art, several modifications and improvements can be made without departing from the structure of the present invention, which will not affect the effect of the implementation of the present invention and the practicality of the patent.

Claims

1. A method for implementing a kubernetes cluster federation, characterized in that: Set up a cluster controller, a status controller, a synchronization controller, a scheduler, and a command controller; Initialize the cluster controller, status controller, synchronization controller, scheduler, and command controller into the Kubernetes system, making this Kubernetes the master cluster of the federated cluster. The cluster controller, status controller, synchronization controller, scheduler, and command controller can run at least one replica; Configure the federated cluster and interact with the administrator through the command controller, including initializing the federated cluster, adding slave clusters, and viewing the information of the federated cluster; Manage the lifecycle of the federated cluster through the cluster controller, and check the health of the master cluster and slave clusters; Perceive and cache the running status of federated resources in the slave cluster through the status controller; Disperse workload instances to different clusters in the federated cluster through the scheduler; Monitor the expected value and current running status of federated resources in the slave cluster through the synchronization controller. When the expected value is inconsistent with the running status, the synchronization controller is responsible for operating the federated resources in the slave cluster to make the running status of the resources consistent with the expected value; The cluster controller runs as follows: Step 2.

1. The cluster controller initializes and runs into the master cluster, communicates with the kube-apiserver of the master cluster, and obtains the configuration information of the federated cluster and the list of slave clusters; if the acquisition is successful, execute Step 2.2; otherwise, continue to execute this step; Step 2.

2. The cluster controller records the current time T1, traverses the list of slave clusters to obtain slave cluster access information, and then accesses the kube-apiserver of the slave cluster; when the request can be correctly returned and the return value is the set value, it means that the slave cluster is in a healthy state, otherwise it means that the slave cluster is in an unhealthy state; If the health status changes, write the new health information into the list of slave clusters, and record the current time T2 after traversal is completed; Step 2.

3. The cluster controller obtains the health check delay time T according to the configuration information of the federated cluster. If T < T2 - T1, execute Step 2.2, otherwise repeat running this step; The status controller runs as follows: Step 3.

1. The status controller initializes and runs into the master cluster, communicates with the kube-apiserver of the master cluster, and obtains the configuration information of the federated cluster and the cluster list; if the acquisition is successful, execute Step 3.2; otherwise, continue to execute this step; Step 3.

2. The status controller traverses and obtains all running federated resources; Step 3.

3. The status controller obtains the current single federated resource, subscribes to the changes of the current resource using the Kubernetes Informer mode, and caches it into the master cluster. Loop this step until all running federated resources are monitored; Step 3.

4. The status controller continuously monitors the changes of all running federated resources. When there are changes in the federated resources, cache the changed information into the master cluster.

2. A method for implementing Kubernetes cluster federation according to claim 1, characterized in that: The command controller runs as follows: Step 1.

1. The command controller is initialized to run to the main cluster, communicates with the kube-apiserver of the main cluster, and obtains the configuration information of the federated cluster; if the acquisition is successful, execute step 1.3; Otherwise, proceed to step 1.2; Step 1.

2. The command controller initializes the configuration information of the federated cluster; if the initialization is successful, the command controller is started successfully, and step 1.3 is executed; Otherwise, repeat step 1.1; Step 1.

3. The command controller waits for the user to input a command; Step 1.

4. When the command controller receives the add slave cluster command, the add slave cluster step is executed; Step 1.

5. When the command controller receives the delete from cluster command, the delete from cluster step is executed; Step 1.

6. When the command controller receives a request to display a list of slave clusters, it searches for resources from the cluster and displays them; Step 1.

7. Perform step 1.

3.

3. A method for implementing Kubernetes cluster federation according to claim 2, characterized in that: The steps to add a slave cluster include: Step 1.4.

1. The command controller receives configuration file information for adding a slave cluster; Step 1.4.

2. The command controller generates a CRD resource of Kubernetes according to the configuration file information of the slave cluster; Step 1.4.

3. The command controller connects to the kube-apiserver of the slave cluster according to the connection information of the CRD resource; Step 1.4.

4. The command controller creates a role resource on the slave cluster, and returns a success message if the creation is successful; otherwise, it returns a failure message.

4. A method for implementing Kubernetes cluster federation according to claim 2, characterized in that: The steps to perform a deletion from a cluster include: Step 1.5.

1. The command controller receives a request to delete a specified slave cluster and searches for connection information of CRD resources in the resources in the slave cluster; Step 1.5.

2. The command controller connects to the specified slave cluster kube-apiserver according to the connection information in step 1.5.1, and deletes the relevant information on the specified slave cluster; Step 1.5.

3. The command controller deletes the CRD resource in the specified slave cluster. If the deletion is successful, a success message is returned; otherwise, a failure message is returned.

5. A method for implementing Kubernetes cluster federation according to claim 1, characterized in that: The scheduler operates as follows: Step 4.

1. The scheduler is initialized to run to the main cluster and communicate with the kube-apiserver of the main cluster. If successful, execute step 4.2; otherwise, continue to execute this step; Step 4.

2. The scheduler records the current time T3 and obtains the running Deployment federal resources, ReplicaSet federal resources, Statefulset federal resources, and Daemonset federal resources; Step 4.

3. The scheduler obtains the current single federated resource mentioned in step 4.2, compares the scheduling status of the current federated resource, and extracts the newly created Kubernetes Pod, the unscheduled Kubernetes Pod, and the Kubernetes Pod that failed to be scheduled; Step 4.

4. The scheduler calls the set scheduling algorithm to schedule the currently acquired resources to the appropriate cluster, writes the scheduling result into the resource, and the synchronization controller performs resource synchronization; Step 4.

5. If the scheduler has traversed all the resources mentioned in step 4.2, execute step 4.6; otherwise, the scheduler obtains the next resource and executes step 4.3; Step 4.

6. The scheduler obtains the current time T4, T5 = T4-T3, and if T5> the set time, execute step 4.2; otherwise, wait for the set time-T5 and then execute step 4.

2.

6. A method for implementing Kubernetes cluster federation according to claim 5, characterized in that: Setting the scheduling algorithm includes: Step 4.4.

1. Get the current resource type, kubernetes nodes, cluster information, and resource usage; Step 4.4.

2. Orchestrate the Kubernetes resources to obtain the PSP file based on the total number of replicas and the cluster's defined strategy; Step 4.4.

3. Perform a priority sorting operation according to the PSP file to prioritize nodes suitable for resource operation; Step 4.4.

4. Select one of the clusters with the highest final priority as the result of resource scheduling.

7. A method for implementing Kubernetes cluster federation according to claim 1, characterized in that: The synchronization controller operates as follows: Step 5.

1. The synchronization controller is initialized to run to the main cluster and communicate with the kube-apiserver of the main cluster. If successful, execute step 5.2; otherwise, continue to execute this step; Step 5.

2. The synchronization controller records the current time T6 and traverses the list of resources that need to be synchronized; Step 5.

3. The synchronization controller obtains a single resource and the latest state of the resource. If the expected state of the resource is inconsistent with the latest state, execute step 5.4; Otherwise, proceed to step 5.6; Step 5.

4. The synchronization controller obtains the slave cluster name from the resource, queries the master cluster for the slave cluster connection information based on the slave cluster name, and communicates with the kube-apiserver of the slave cluster. If successful, execute step 5.5, otherwise execute step 5.6; Step 5.

5. The synchronization controller creates or modifies the corresponding resource information on the slave cluster according to the acquired resource data, and executes step 5.6; Step 5.

6. If the synchronization controller has traversed all resources, execute step 5.7; Otherwise, proceed to step 5.3; Step 5.

7. If the synchronization controller obtains the current time T7, T8 = T7-T6, if T8> the set time, execute step 5.2; otherwise, wait for the set time-T8 and then execute step 5.

2.

8. A Kubernetes cluster federation system, characterized in that: Including cluster controller, state controller, synchronization controller, scheduler, and command controller; The cluster controller, state controller, synchronization controller, scheduler, and command controller are initialized into the Kubernetes system and run according to a Kubernetes cluster federation implementation method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Service instance deployment method, data processing method and cluster federation

    CN111176697A

  • PAAS cloud cluster construction method and device, electronic device and storage medium

    CN111193782A

  • Method for ensuring number of available clusters in hybrid cloud scenario, device and system

    CN111800303A

  • Method for constructing dynamic resource admission controller based on Kubernetes

    CN112099911A

  • Disaster recovery, migration and recovery method for Kubernetes cloud native application

    CN112099989A