Stateful service management method and device, equipment and storage medium
By determining the naming interval and naming rules based on Pod sharding and replica information in Kubernetes, the management inconvenience caused by unreasonable pod naming in StatefulSet is solved, and flexible management and stable containerization of stateful services are achieved.
Patent Information
- Application Number
- CN202410004530.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-02
- Publication Date
- 2025-07-04
AI Technical Summary
In Kubernetes, the continuous and ordered pod naming mechanism provided by the existing StatefulSet hinders flexible management of stateful services, especially when the pods are required to operate independently, resulting in poor management results.
By obtaining the initial configuration information of a stateful service, including Pod shard information and replica information, N shards are determined, and Pods are created under each replica of each shard, the Pod naming interval is determined based on the Pod shard information and replica information, and then the Pods in each shard are named, combining naming with shard and replica information to support independent operations.
It realizes flexible management of stateful services, enhances stateful service management in cloud-native scenarios, and helps smooth and stable containerization of databases, middleware and consensus systems.
Smart Images

Figure CN120256077A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present application relate to the field of computer technology, and in particular, to a method, device, equipment, and storage medium for managing stateful services. Background Art
[0002] A stateful service refers to a service that needs to maintain the state of data to ensure reliability and consistency. In k8s, a stateful service usually refers to a service that requires persistent data storage, such as a database service.
[0003] In k8s, the built-in stateful service workload StatefulSet is used to deploy and manage stateful services. For example, StatefulSet provides a unique name for the Pod corresponding to the stateful service. To implement the Pod scaling and rolling update capabilities, the unique names currently determined by StatefulSet for the Pods corresponding to the stateful service are consecutive. However, the consecutive and ordered Pod names prevent users from operating on any Pod at will, resulting in an unsatisfactory management effect of the stateful service. Therefore, how to reasonably name the pods is particularly important. Summary of the Invention
[0004] The present application provides a method, device, equipment, and storage medium for managing stateful services, which can improve the naming rationality of pods and thus enhance the management effect of stateful services.
[0005] In a first aspect, the present application provides a method for managing a stateful service, including:
[0006] Obtaining initial configuration information corresponding to the stateful service, where the initial configuration information includes Pod sharding information and Pod replica information;
[0007] Based on the Pod sharding information and the Pod replica information, determining N shards corresponding to the stateful service, and creating corresponding numbers of Pods under each replica of each shard, where N is a positive integer;
[0008] Based on the Pod sharding information and the Pod replica information, determining the Pod naming interval corresponding to each shard among the N shards;
[0009] For the i-th shard among the N shards, determining the names of the Pods under each replica in the i-th shard within the Pod naming interval corresponding to the i-th shard, where i is a positive integer less than or equal to N.
[0010] In a second aspect, the present application provides a device for managing a stateful service, including:
[0011] An acquisition unit, configured to acquire initial configuration information corresponding to a stateful service, where the initial configuration information includes Pod shard information and Pod replica information;
[0012] A creation unit, configured to determine N shards corresponding to the stateful service based on the Pod shard information and the Pod replica information, and create corresponding numbers of Pods under each replica of each shard, where N is a positive integer;
[0013] An interval determination unit, configured to determine a Pod naming interval corresponding to each of the N shards based on the Pod shard information and the Pod replica information;
[0014] A naming unit, configured to, for the i-th shard among the N shards, determine the names of the Pods under each replica in the i-th shard within the Pod naming interval corresponding to the i-th shard, where i is a positive integer less than or equal to N.
[0015] In some embodiments, the Pod shard information further includes a preset number of shards and the maximum number of replicas included in each shard, and the Pod replica information includes the maximum number of co-existing Pods in each replica; the interval determination unit is specifically configured to, for the i-th shard, determine the index of the i-th shard among the N shards based on the preset number of shards; and determine the Pod naming interval corresponding to the i-th shard based on the index of the i-th shard among the N shards, the maximum number of replicas included in each shard, and the maximum number of co-existing Pods in each replica.
[0016] In some embodiments, the interval determination unit is specifically configured to determine the length of the Pod naming interval corresponding to each of the N shards based on the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica; and determine the Pod naming interval corresponding to the i-th shard based on the length of the Pod naming interval and the index of the i-th shard among the N shards.
[0017] In some embodiments, the interval determination unit is specifically configured to determine the starting value of the Pod naming interval corresponding to the i-th shard as the product of the length of the Pod naming interval and the index of the i-th shard among the N shards; and determine the ending value of the Pod naming interval corresponding to the i-th shard as the value obtained by subtracting 1 from the sum of the starting point of the Pod naming interval corresponding to the i-th shard and the length of the Pod naming interval.
[0018] In some embodiments, the naming unit is specifically configured to determine, for the j-th Pod in the i-th shard, the replica index of the k-th replica where the j-th Pod is located in the i-th shard, where both k and j are positive integers; and determine the name of the j-th Pod based on the replica index of the k-th replica and the Pod naming range corresponding to the i-th shard.
[0019] In some embodiments, the naming unit is specifically configured to multiply the replica index of the k-th replica by the maximum number of Pods coexisting in each replica to obtain a first product; determine the sum of the starting value of the Pod naming range corresponding to the i-th shard and the first product as the name of the first Pod in the k-th replica; and determine the name of the j-th Pod based on the index of the j-th Pod in the k-th replica and the name of the first Pod in the k-th replica.
[0020] In some embodiments, the naming unit is specifically configured to, if the j-th Pod is the first Pod in the k-th replica, determine the name of the first Pod as the name of the j-th Pod; if the j-th Pod is not the first Pod in the k-th replica, determine the sum of the index of the j-th Pod in the k-th replica and the name of the first Pod as the name of the j-th Pod.
[0021] In some embodiments, after determining the names of the Pods under each replica in the i-th shard within the Pod naming range corresponding to the i-th shard, the naming unit is further configured to obtain configuration change information corresponding to the stateful service, where the configuration change information includes at least one of Pod addition indication information, Pod deletion indication information, Pod template update indication information, and replica rolling upgrade indication information; and change the current Pod information corresponding to the stateful service based on the configuration change information.
[0022] In some embodiments, when the configuration change information includes the Pod addition indication information, the naming unit is specifically configured to determine the names of M first Pods to be added based on the Pod addition indication information, where M is a positive integer; for each of the M first Pods, determine the first shard and the first replica where the first Pod is located based on the name of the first Pod; and add the first Pod in the first replica under the first shard.
[0023] In some embodiments, when the configuration change information includes the Pod deletion indication information, the naming unit is specifically configured to determine the naming of K second Pods to be deleted based on the Pod deletion indication information, where K is a positive integer; for each of the K second Pods, determine the second shard and the second replica where the second Pod is located based on the naming of the second Pod; and delete the second Pod under the second replica in the second shard.
[0024] In some embodiments, when the configuration change information includes the Pod addition indication information and the Pod deletion indication information, and the first Pod to be added indicated by the Pod addition indication information is the same Pod as the second Pod to be deleted indicated by the Pod deletion indication information, the step of adding the first Pod is skipped.
[0025] In some embodiments, when the configuration change information includes the Pod template update indication information, the naming unit is specifically configured to determine the naming of P third Pods whose templates are to be changed and the template configuration adjustment information corresponding to each of the P third Pods based on the Pod template update indication information, where P is a positive integer; for each of the P third Pods, determine the third shard and the third replica where the third Pod is located based on the naming of the third Pod; and adjust the template configuration of the third Pod in the third replica under the third shard based on the template configuration adjustment information corresponding to the third Pod, where the template configurations of the Pods corresponding to the stateful service are not completely the same.
[0026] In some embodiments, when the configuration change information includes the replica rolling upgrade indication information, the naming unit is specifically configured to determine the naming of Q fourth Pods to be upgraded based on the replica rolling upgrade indication information, where Q is a positive integer; for each of the Q fourth Pods, determine the fourth shard and the fourth replica where the fourth Pod is located based on the naming of the fourth Pod; create the fourth Pod under the fourth replica in the fourth shard, and after the creation of the fourth Pod is successful, delete the old Pod under the fourth replica in the fourth shard.
[0027] In some embodiments, the naming unit is specifically configured to obtain the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica; determine the length of the Pod naming range corresponding to each shard based on the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica; determine the shard where the Pod is located based on the naming of the Pod and the length of the Pod naming range; determine the replica where the Pod is located based on the naming of the Pod, the length of the Pod naming range, and the maximum number of co-existing Pods in each replica; wherein, if the Pod is the first Pod, the shard where the Pod is located is the first shard and the replica where the Pod is located is the first replica, if the Pod is the second Pod, the shard where the Pod is located is the second shard and the replica where the Pod is located is the second replica, if the Pod is the third Pod, the shard where the Pod is located is the third shard and the replica where the Pod is located is the third replica, if the Pod is the fourth Pod, the shard where the Pod is located is the fourth shard and the replica where the Pod is located is the fourth replica.
[0028] In some embodiments, the naming unit is specifically configured to floor the quotient of the naming of the Pod and the length of the Pod naming range to obtain the shard where the Pod is located.
[0029] In some embodiments, the naming unit is specifically configured to perform a remainder operation on the naming of the Pod and the length of the Pod naming range to obtain a remainder; floor the quotient of the remainder and the maximum number of co-existing Pods in each replica to obtain the replica where the Pod is located.
[0030] In a third aspect, an electronic device is provided, including a processor and a memory. The memory is used to store a computer program, and the processor is used to call and run the computer program stored in the memory to execute the methods in the first aspect and its various implementation manners above.
[0031] In a fourth aspect, a chip is provided for implementing the methods in any one of the first aspects or its various implementation manners above. Specifically, the chip includes: a processor, configured to call and run a computer program from a memory, so that a device installed with the chip executes the methods in the first aspect and its various implementation manners above.
[0032] In a fifth aspect, a computer-readable storage medium is provided for storing a computer program, and the computer program causes a computer to execute the methods in the first aspect and its various implementation manners above.
[0033] In a sixth aspect, a computer program product is provided, including computer program instructions that cause a computer to execute the methods in the first aspect and its various implementation manners described above.
[0034] In a seventh aspect, a computer program is provided, which, when running on a computer, causes the computer to execute the methods in the first aspect and its various implementation manners described above.
[0035] In summary, in the embodiments of the present application, the initial configuration information corresponding to the stateful service is obtained, and the initial configuration information includes Pod sharding information and Pod replica information. Then, based on the Pod sharding information and Pod replica information included in the initial configuration information, N shards corresponding to the stateful service are determined, and the corresponding number of Pods are created under each replica of each shard. At the same time, based on the Pod sharding information and Pod replica information, the Pod naming range corresponding to each of the N shards is determined. In this way, for each of the N shards, for example, the i-th shard, the naming of each Pod under each replica in the i-th shard can be determined within the Pod naming range corresponding to the i-th shard. That is, in the embodiments of the present application, the Pods corresponding to the stateful service are grouped according to the Pod sharding information and Pod replica information, and the Pod naming range corresponding to each shard is determined, and then the Pods under each replica in the shard are named within the Pod naming range corresponding to the shard, so that the Pod naming is combined with the sharding information and replica information where the Pod is located, improving the rationality of Pod naming. In this way, subsequent independent operations can be performed on the Pods under any replica in any shard based on the Pod naming, fully enhancing the management of stateful services in the cloud native scenario, and helping stateful services such as databases, middleware, and consensus systems to be smoothly and stably containerized. Description of the Drawings
[0036] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for the description of the embodiments will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present invention, and those of ordinary skill in the art can obtain other drawings without creative efforts based on these drawings.
[0037] Figure 1 It is a schematic structural diagram of k8s;
[0038] Figure 2 It is a schematic diagram of deleting a pod in the related art;
[0039] Figure 3 It is a schematic diagram of an implementation environment related to the embodiments of the present application;
[0040] Figure 4Schematic flowchart of the management method for stateful services provided by an embodiment of the present application;
[0041] Figure 5 Schematic diagram of the correspondence between sss objects and sss controllers;
[0042] Figure 6 Example diagram of the division of shards, replicas, and Pods;
[0043] Figure 7 Example diagram of a Pod naming;
[0044] Figure 8 Another example diagram of a Pod naming;
[0045] Figure 9 Schematic flowchart of the management method for stateful services provided by an embodiment of the present application;
[0046] Figure 10 Schematic diagram of making changes to a Pod;
[0047] Figure 11 Schematic diagram of adding a new Pod;
[0048] Figure 12 Schematic diagram of deleting a Pod;
[0049] Figure 13A Schematic diagram of replica upgrade;
[0050] Figure 13B Another schematic diagram of replica upgrade;
[0051] Figure 14 Schematic block diagram of the management device for stateful services provided by an embodiment of the present application;
[0052] Figure 15 Schematic block diagram of the electronic device provided by an embodiment of the present application. Detailed implementation manners
[0053] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts shall fall within the protection scope of the present application.
[0054] It should be noted that the terms "first", "second", etc. in the description, claims and above-mentioned drawings of this application are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of this application described here can be implemented in an order other than those illustrated or described here. In the embodiments of the present invention, "B corresponding to A" means that B is associated with A. In one implementation, B can be determined according to A. However, it should also be understood that determining B according to A does not mean determining B only according to A, and B can also be determined according to A and / or other information. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or server comprising a series of steps or units does not have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices. In the description of this application, unless otherwise specified, "a plurality" means two or more than two.
[0055] The technical solution proposed in this application can be applied to technical fields such as cloud computing, cloud services, and databases, and is used to improve the management flexibility of stateful services.
[0056] In some embodiments, the technical solution of the embodiments of this application can be applied to the usage scenario of cloud-native clusters, which can fully enhance the management of stateful services in the cloud-native scenario and help the smooth and stable containerization of stateful services such as databases, middleware, and consensus systems.
[0057] The related technologies involved in the embodiments of this application are introduced below.
[0058] Cloud technology is the general term for network technology, information technology, integration technology, management platform technology, application technology, etc. based on the cloud computing business model. It can form a resource pool, be used as needed, and is flexible and convenient. Cloud computing technology will become an important support. The back-end services of the technical network system require a large amount of computing and storage resources, such as video websites, picture websites, and more portal websites. With the high development and application of the Internet industry, in the future, each item may have its own identification mark and needs to be transmitted to the back-end system for logical processing. Data at different levels will be processed separately, and various industry data requires a powerful system back-end support, which can only be achieved through cloud computing.
[0059] Cloud computing is a computing model that distributes computing tasks across a resource pool composed of a large number of computing devices, enabling various application systems to obtain computing power, storage space, and information services as needed. The network that provides resources is called the "cloud". The resources in the "cloud" seem to users to be infinitely expandable, can be obtained at any time, used on demand, expanded at any time, and paid according to usage.
[0060] As a basic capabilities provider of cloud computing, a cloud computing resource pool (abbreviated as cloud platform, generally called IaaS (Infrastructure as a Service) platform) will be established, and various types of virtual resources will be deployed in the resource pool for external customers to choose and use. The cloud computing resource pool mainly includes: computing devices (virtualized machines, including operating systems), storage devices, and network devices.
[0061] Kubernetes, abbreviated as k8s, is an abbreviation formed by replacing the 8 characters "ubernete" in the middle of the name with 8. It is an open-source tool used to manage containerized applications on multiple hosts in a cloud platform. The goal of Kubernetes is to make it simple and efficient to deploy containerized applications. Kubernetes provides a mechanism for application deployment, planning, updating, and maintenance.
[0062] As Figure 1 shown, a k8s cluster usually includes a master node and multiple worker nodes. A node can be regarded as a physical machine or a virtual machine.
[0063] The master node is used to manage and control the entire k8s cluster. The master node occupies an independent server.
[0064] The components running on the master node include:
[0065] apiserver: It is the unified entry of the k8s cluster, providing interface services in HTTP Rest. All operations such as addition and deletion of object resources are handled by apiserver and then handed over to Etcd for storage.
[0066] controller-manager (controller management): It is the control center of all resource objects in k8s, handling regular background tasks in the cluster. Exemplarily, one resource corresponds to one controller, and kube-controller-manager is used to control these controllers.
[0067] Schedule: Select a worker node for the newly created Pod according to the scheduling algorithm. It can be deployed arbitrarily, either on the same node or on different nodes.
[0068] Etcd: A distributed, consistent key-value store, mainly used for sharing configurations and service discovery, and storing cluster state data, such as information about objects like Pods and Services.
[0069] A worker node is a workload node in the K8S cluster. Each worker node will be assigned some workloads by the master node. When a worker node fails, the workloads on it will be automatically transferred by the master node to other worker nodes.
[0070] Components running on the worker node include:
[0071] Kubelet: It is the Agent of the master node on the worker node, closely collaborating with the master node to manage the life cycle of the containers running on this machine, responsible for tasks such as the creation and start / stop of the containers corresponding to the Pod, and realizing the basic functions of cluster management.
[0072] kube-proxy: It implements the Pod network proxy on the worker node, realizes the communication of k8s services, and maintains network rules and four-layer load balancing.
[0073] Docker (a container engine): Responsible for the creation and management of containers on this machine. As Figure 1 shown, multiple Pods can be included under one Docker.
[0074] A Pod is the smallest deployable computing unit that can be created and managed in Kubernetes and is a collection of containers.
[0075] As Figure 1 shown, one Pod can include one or more containers, and applications and services can run in the containers.
[0076] Services in k8s include stateless services and stateful services.
[0077] A stateful service refers to a service that needs to maintain the state of data to ensure reliability and consistency. In k8s, stateful services usually refer to services that require persistent data storage, such as database services, etc.
[0078] Managing stateful services on Kubernetes is a challenging task. On the one hand, these underlying capabilities are adapted to the Kubernetes environment to provide a mechanism for resource application / binding / release upward in the form of resource objects. On the other hand, the high-level stateful service management plane also needs to correctly use the declarative style interface of Kubernetes to associate service instance nodes (Pods) with underlying resources, realizing the management of stateful services. Under this dynamic binding ability, stateful services can be transformed from the Pets architecture to the Cattle architecture, improving the availability and stability of stateful services.
[0079] Pods are associated with these underlying resources with persistent state. From the perspective of management and control, the nodes formed by different Pods in a stateful service often have non-equivalence, and this non-equivalence may be perceivable to both the management and control end and the user end, and different Pods have different roles. For example, in a master / slave architecture MySQL cluster, the online service program connects to the Pod node with the master role to write data, while some background services connect to the Pods belonging to the slave role to read data for analysis.
[0080] The perceivable non-equivalence requires that Pods have a uniquely identifiable ID. At the same time, the lifecycle of a Pod is shorter than that of these underlying resources. When a Pod migrates to generate a new Pod object, the historical state needs to be associated with the newly created Pod, which requires that the ID of the stateful service Pod must also be stable, because only a stable ID can find the corresponding persistent resources in the underlying system.
[0081] Kubernetes has a built-in stateful service workload, StatefulSet. Kubernetes uses workloads to manage a group of Pods to reduce the complexity of managing Pods.
[0082] One of the core capabilities of StatefulSet is to provide unique and stable IDs, which are expressed through Pod naming.
[0083] For example, through the following description (spec), the StatefulSets workload will create a batch of Pods with fixed names in the cluster: `p-0, p-1, p-2`.
[0084]
[0085] In addition to providing a stable and unique ID mechanism for Pods, StatefulSets also assumes that these IDs are sequential and ordered, thereby providing scaling and rolling update capabilities (including an interval rolling update function). For example, when you need to reduce the number of Pods, modify the StatefulSet and reduce the `Replicas` field. StatefulSet will start from the largest ID and delete the Pods one by one. Figure 2 This shows the process of StatefulSet deleting Pods when the number of Replicas is adjusted from 4 to 2. First, the Pod with the largest ID named p-3 is deleted, and then the remaining Pod with the largest ID named p-2 is deleted.
[0086] In one example, a redis cluster with a "multi-shard + multi-copy + master / slave" architecture has the following requirements for Pod management:
[0087] 1. The process in the Pod needs to know which shard it belongs to, which is necessary for the continuity of detection data;
[0088] 2. Add or delete a shard;
[0089] 3. You can add or delete copies for any number of shards;
[0090] 4. There are non-equivalent configurations between Pods (for example: image, cpu, memory);
[0091] 5. Stable upgrade: To upgrade a copy (egimage), you need to add a new copy to the shard first, and then terminate the corresponding old copy after the new copy is stable.
[0092] To achieve the above functions, Pods need to be operated independently (add / delete / modify), but the StatefulSets workload provides continuous and ordered Pod naming, which is unreasonable and prevents users from operating any Pod, making the management of stateful services unsatisfactory. Therefore, in stateful services, how to reasonably name Pods to operate any independent Pod has become a technical problem that needs to be solved in this field.
[0093] To solve the above technical problems, an embodiment of the present application provides a new Pod controller (also referred to as a workload), which can achieve flexible management of stateful services. Specifically, obtain the initial configuration information corresponding to the stateful service, where the initial configuration information includes Pod sharding information and Pod replica information. Then, based on the Pod sharding information and Pod replica information included in the initial configuration information, determine N shards corresponding to the stateful service, and create corresponding numbers of Pods under each replica of each shard. At the same time, based on the Pod sharding information and Pod replica information, determine the Pod naming range corresponding to each of the N shards. In this way, for each of the N shards, for example, the i-th shard, the names of the Pods under each replica in the i-th shard can be determined within the Pod naming range corresponding to the i-th shard. That is, the embodiment of the present application groups the Pods corresponding to the stateful service according to the Pod sharding information and Pod replica information, determines the Pod naming range corresponding to each shard, and then names the Pods under each replica in the shard within the Pod naming range corresponding to the shard, so that the Pod naming is combined with the sharding information and replica information of the Pod's location. In this way, subsequent independent operations can be performed on the Pods under any replica in any shard based on the Pod naming, which fully enhances the management of stateful services in the cloud native scenario and can help the smooth and stable containerization of stateful services such as databases, middleware, and consensus systems.
[0094] The implementation environment of the embodiment of the present application will be introduced below.
[0095] Figure 3 FIG. is a schematic diagram of an implementation environment involved in an embodiment of the present application, including a terminal device 101, a first working node 102, and multiple second working nodes 103. As Figure 3 shown, the terminal device 101 is communicatively connected to the first working node 102, and the first working node 102 is communicatively connected to multiple second working nodes 103.
[0096] In the embodiment of the present application, the first working node 102 can be a physical node or a virtual node. A Pod controller is deployed on the first working node 102. In one example, the Pod controller can be referred to as a StateSliceSet (sss) controller. One or more Pods can be deployed on each of the multiple second working nodes 103. Optionally, one or more Pods can also be deployed on the first working node 102.
[0097] In a possible implementation manner of the embodiment of the present application, a user may send initial configuration information corresponding to a stateful service to a first working node 102 through a terminal device 101, where the initial configuration information includes Pod shard information and Pod replica information. The first working node 102 may create Pods in the first working node 102 and / or multiple second working nodes 103 based on the Pod shard information and Pod replica information in the initial configuration information sent by the terminal device 101, and name the created Pods. Specifically, a Pod controller in the first working node 102 determines N shards corresponding to the stateful service based on the Pod shard information and Pod replica information, and creates corresponding numbers of Pods under each replica of each shard, where N is a positive integer. Then, based on the Pod shard information and Pod replica information, it determines a Pod naming range corresponding to each of the N shards. In this way, for the i-th shard among the N shards, within the Pod naming range corresponding to the i-th shard, it determines the names of the Pods under each replica in the i-th shard. The names of the Pods in the i-th shard are not consecutive, and i is a positive integer less than or equal to N. In the embodiment of the present application, the Pods corresponding to the stateful service are grouped according to the Pod shard information and Pod replica information, and the Pod naming range corresponding to each shard is determined. Furthermore, within the Pod naming range corresponding to the shard, the Pods under each replica in the shard are named, so that the Pod naming is combined with the shard information and replica information where the Pod is located. In this way, subsequent independent operations can be performed on the Pods under any replica in any shard based on the Pod naming, which fully enhances the management of stateful services in the cloud native scenario and can help the smooth and stable containerization of stateful services such as databases, middleware, and consensus systems.
[0098] In some embodiments, after the second working node 102 of the embodiment of the present application determines the names of the Pods under each replica in the i-th shard within the Pod naming range corresponding to the i-th shard through the Pod controller, it also obtains configuration change information corresponding to the stateful service. The configuration change information includes at least one of Pod addition indication information, Pod deletion indication information, Pod template update indication information, and replica rolling upgrade indication information. Based on the configuration change information, it changes the current Pod information corresponding to the stateful service. For example, adding a specified Pod, deleting a specified Pod, or updating the template of a specified Pod, or performing a rolling upgrade on a specified Pod replica, etc., thereby realizing the effective management of the Pods corresponding to the stateful service.
[0099] In some embodiments, the second working node 102 and / or the third working node 103 involved in the embodiments of the present application may be one or more servers. When there are multiple servers, at least two servers are used to provide different services, and / or at least two servers are used to provide the same service, such as providing the same service in a load balancing manner. The embodiments of the present application do not limit this. Among them, the above servers may be independent physical servers, or server clusters or distributed systems composed of multiple physical servers, or cloud servers that provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The second working node 102 and / or the third working node 103 may also become nodes of the blockchain.
[0100] In some embodiments, the terminal device 101 may be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited thereto. The terminal and the server may be directly or indirectly connected through wired or wireless communication methods, and the present application does not limit this here.
[0101] It should be noted that the implementation environment of the embodiments of the present application includes but is not limited to Figure 3 as shown.
[0102] The technical solutions of the embodiments of the present application will be described in detail below through some embodiments. These several embodiments below can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.
[0103] Figure 4 It is a schematic flowchart of a method for managing a stateful service provided by an embodiment of the present application. The method for managing a stateful service provided by the embodiments of the present application can be completed by a device with management functions, such as a management device for stateful services. In one example, the management device for stateful services may be a working node, such as Figure 3 the second working node in, or a part of the second working node. In one example, the management device for stateful services may be a Pod controller in the second working node, used to configure and manage the Pod corresponding to the stateful service. For the convenience of description, the following will be described by taking the execution subject as the Pod controller as an example.
[0104] As Figure 4 shown, the method for managing a stateful service in the embodiments of the present application includes the following steps:
[0105] S101. Obtain the initial configuration information corresponding to the stateful service.
[0106] Among them, the initial configuration information includes Pod sharding information and Pod replica information.
[0107] A stateful service refers to a service that needs to maintain the state of data to ensure reliability and consistency, such as saving the user's login session, shopping cart information, etc. A stateful service needs to use a shared data storage to store and manage the state information.
[0108] In the embodiments of the present application, the stateful service can be any stateful service such as a database service, a message queue service, etc.
[0109] In some embodiments, the stateful services under a stateful service instance can be divided into one or more stateful services according to functions. For example, they can be divided into a database service, a traffic statistics service, etc. Each of these multiple stateful services corresponds to a group of Pods. The embodiments of the present application can create a group of Pods for each stateful service, perform sharding and replica division for this group of Pods, and then determine the naming of each Pod in this group of Pods based on the Pod sharding information and Pod replica information, so as to obtain the unique name of each Pod in this group of Pods corresponding to the stateful service. For example, assuming that the stateful service in the embodiments of the present application is a database service, the Pod manager creates a group of Pods for the database service and names each Pod in this group of Pods corresponding to the database service by adopting the naming method provided by the embodiments of the present application.
[0110] As can be seen from the above, the stateful service in the embodiments of the present application can be understood as a stateful service under a stateful service instance, such as a database service. Before the cluster creates a group of Pods for the database service, the Pod controller first obtains the initial configuration information corresponding to the stateful service, and the initial configuration information is used to indicate the Pod information corresponding to the stateful service, such as including Pod sharding information and Pod replica information.
[0111] The embodiments of the present application do not limit the specific content of the Pod sharding information. For example, it can include information such as a preset number of shards, the maximum number of replicas included in each shard, the default number of replicas of each shard, etc.
[0112] The embodiments of the present application do not limit the specific content of the Pod replica information. For example, it can include information such as the maximum number of co-existing Pods in each replica, the default number of Pods in each replica, etc.
[0113] The embodiments of the present application do not limit the specific acquisition method for the Pod controller to obtain the initial configuration information corresponding to the stateful service.
[0114] In a possible implementation, the user generates the initial configuration information corresponding to the stateful service and sends the initial configuration information to the Pod controller. For example, the user sends the initial configuration information to the worker node where the Pod controller is located through a terminal device, so that the Pod controller can pull the initial configuration from the worker node.
[0115] In a possible implementation, the user inputs the requirement information corresponding to the stateful service. For example, the user inputs the preset number of shards and the number of replicas. After the Pod controller obtains the user's requirement information, based on the requirement information, it generates the initial configuration information corresponding to the stateful service.
[0116] In one example, the Pod controller of the embodiment of the present application may be a StateSliceSet (state slice set) controller, abbreviated as the sss controller. That is to say, based on the operation mode of the operator in the embodiment of the present application, a custom resource (Custom Resource, abbreviated as CR) of StateSliceSet is newly added in Kubernetes. As Figure 5 shown, the above initial configuration information can be understood as an sss object, and the sss controller monitors the sss object, and then obtains the initial configuration information corresponding to the stateful service.
[0117] In one example, the initial configuration information corresponding to the stateful service is as follows:
[0118]
[0119]
[0120] In this example, the Pod shard information included in the initial configuration information corresponding to the stateful service may include: the number of shards in the cluster (for example, 3), the default number of replicas per shard (for example, 2), and the maximum number of replicas per shard (for example, 5). The replica information includes: the maximum number of Pods coexisting in each replica (for example, 2), and the default number of Pods in each replica (for example, 1). In this example, the default number of Pods in each replica can be omitted and defaults to 1. Optionally, the default number of replicas per shard can also be omitted, for example, it defaults to 2. That is to say, the initial configuration information of the embodiment of the present application may include the number of shards in the group, the maximum number of replicas per shard, and the maximum number of Pods coexisting in each replica, while the default number of replicas per shard and the default number of Pods in each replica can be omitted.
[0121] It should be noted that the specific values in the above initial configuration information, such as the number of shards in the cluster is 3, the default number of replicas per shard is 2, etc., are all examples, and other values may also be used. The embodiment of the present application does not limit this.
[0122] In an embodiment of the present application, after the Pod controller obtains the initial configuration information corresponding to the stateful service, it executes the steps of S102 as follows.
[0123] S102: Based on the Pod sharding information and the Pod replica information, determine N shards corresponding to the stateful service, and create corresponding numbers of Pods under each replica of each shard.
[0124] Where N is a positive integer.
[0125] In an embodiment of the present application, after the Pod controller obtains the initial configuration information corresponding to the stateful service, it can determine N shards corresponding to the stateful service based on the Pod sharding information and the Pod replica information included in the initial configuration information, determine the number of replicas included in each of the N shards, and the number of Pods included under each replica. In this way, based on the number of replicas included in each of the N shards and the number of Pods included under each replica, corresponding numbers of Pods can be created under the replicas of each of the N shards.
[0126] In one example, assume that the initial state information corresponding to the stateful service includes a preset number of shards, the default number of replicas for each shard, and the default number of Pods for each replica. Alternatively, the initial state information includes a preset number of shards and does not include at least one of the default number of replicas for each shard and the default number of Pods for each replica. At this time, the Pod controller can obtain the default number of replicas for each shard and the default number of Pods for each replica based on the default values corresponding to at least one of the default number of replicas for each shard and the default number of Pods for each replica. In this way, the Pod controller creates Pods for the stateful service based on the preset number of shards, the default number of replicas for each shard, and the default number of Pods for each replica, and performs sharding on the Pods.
[0127] For example, assume that the preset number of shards included in the initial configuration information corresponding to the stateful service is 2, the default number of replicas for each shard is 2, and the default number of Pods for each replica is 1. Based on this information, a sharding, replica, and Pod partitioning example diagram as shown in Figure 6 can be obtained, that is, it includes 2 shards s0 and s1. Under shard s0, there are 2 replicas denoted as s0r0 and s0r1 respectively. Under shard s1, there are 2 replicas denoted as s1r0 and s1r1 respectively. Each replica includes one Pod. In this way, the Pod controller can create corresponding numbers of Pods under each replica in each shard based on the Figure 6 structure shown. For example, create one Pod under each of the replicas s0r0 and s0r1 in shard s0, and create one Pod under each of the replicas s1r0 and s1r1 in shard s1.
[0128] In some embodiments, the initial configuration information further includes Pod specifications (CPU, memory, disk, etc.), image information, environment variables, startup parameters, container information of the Pod (starting container group and running container group), and differential configuration, etc. The Pod controller can create a Pod based on these parameters.
[0129] In some embodiments, the Pod controller of the embodiment of the present application can first determine the total number of Pods corresponding to the stateful service based on the preset number of shards, the default number of replicas for each shard, and the default number of Pods for each replica, and then create the total number of Pods. Then, based on the Figure 6 partitioning structure of shards, replicas, and Pods shown above, allocate the created Pods to the replicas of the corresponding shards. For example, allocate one created Pod to each replica in each shard.
[0130] In some embodiments, if there are Pods in the cluster, the Pod controller can delete the existing Pods and then recreate the Pods. Alternatively, the Pod controller updates the existing Pods. For example, based on the Pod configuration information included in the initial configuration information, update the configuration of the existing Pods. For example, update at least one of the configurations such as annotation, labels, toleration, and image information of the existing Pods.
[0131] In some embodiments, there are non - peer - to - peer configurations among the Pods created in the embodiment of the present application. For example, the template configuration resources such as image, CPU, and memory of at least two of the created Pods are non - peer - to - peer (i.e., different).
[0132] Based on the Pod shard information and Pod replica information, the Pod controller determines N shards corresponding to the stateful service, and after creating the corresponding number of Pods under each replica of each shard, executes the following step S103.
[0133] S103: Based on the Pod shard information and Pod replica information, determine the Pod naming range corresponding to each of the N shards.
[0134] It should be noted that in the embodiments of the present application, after the Pod controller determines the N shards corresponding to the stateful service, it can first create the corresponding number of Pods under each replica of each shard, and then determine the Pod naming range corresponding to each shard among the N shards based on the Pod shard information and the Pod replica information. Alternatively, after the Pod controller determines the N shards corresponding to the stateful service, it first determines the Pod naming range corresponding to each shard among the N shards based on the Pod shard information and the Pod replica information, and then creates the corresponding number of Pods under each replica of each shard. Alternatively, after the Pod controller determines the N shards corresponding to the stateful service, while creating the corresponding number of Pods under each replica of each shard, it determines the Pod naming range corresponding to each shard among the N shards based on the Pod shard information and the Pod replica information.
[0135] In the embodiments of the present application, after the Pod controller determines the N shards corresponding to the stateful service, it can determine the Pod naming range corresponding to each shard among the N shards based on the Pod shard information and the Pod replica information. That is to say, in the embodiments of the present application, there is a Pod naming range corresponding to each shard among the N shards. In this way, the naming of each Pod under the shard can be determined based on the Pod naming range corresponding to the shard, so that the naming of the Pod is related to the shard and replica to which the Pod belongs. In this way, in the subsequent process, the shard and replica where the Pod is located can be determined based on the naming of the Pod, and then independent operations such as deletion and update of the specified Pod can be realized, and then the effective management of the Pods corresponding to the stateful service can be realized, which can fully enhance the management of the stateful service in the cloud native scenario and help the stateful services such as databases, middleware, and consensus systems to be smoothly and stably containerized.
[0136] The following introduces the specific process by which the Pod controller determines the Pod naming range corresponding to each shard among the N shards based on the Pod shard information and the Pod replica information.
[0137] In the embodiments of the present application, the Pod naming can be understood as the unique identifier of the Pod, and is called PodID in some embodiments. The Pod naming range can be understood as an identifier range or an ID range or an ID segment. In the embodiments of the present application, the Pod naming ranges corresponding to different shards among the N shards are different and there is no intersection. For example, the Pod naming range corresponding to shard 1 is from 0 to 99, the Pod naming range corresponding to shard 2 is from 100 to 199, and the Pod naming range corresponding to shard 3 is from 200 to 299.
[0138] In some examples, the lengths of the Pod naming ranges corresponding to each of the N shards are the same. For example, the length of the Pod naming range corresponding to each of the N shards is 100. Exemplarily, N = 3, the Pod naming range corresponding to shard 1 is from 0 to 99, the Pod naming range corresponding to shard 2 is from 100 to 199, and the Pod naming range corresponding to shard 3 is from 200 to 299.
[0139] In some examples, the lengths of the Pod naming ranges corresponding to each of the N shards are not the same. For example, N = 3, the Pod naming range corresponding to shard 1 is from 0 to 99, its length is 100, the Pod naming range corresponding to shard 2 is from 100 to 299, its length is 200, and the Pod naming range corresponding to shard 3 is from 300 to 379, its length is 80.
[0140] In some examples, the lengths of the Pod naming ranges corresponding to some of the N shards are the same, and the lengths of the shards corresponding to some other shards are not the same. For example, N = 4, the length of the Pod naming range corresponding to shard 1 is 100, the length of the naming range corresponding to shard 2 is 100, the length of the Pod naming range corresponding to shard 3 is 200, and the length of the Pod naming range corresponding to shard 4 is 300.
[0141] In some examples, the Pod naming ranges corresponding to each of the N shards are continuous. For example, the end point of the Pod naming range corresponding to shard 1 is continuous with the start point of the Pod naming range corresponding to shard 2.
[0142] In the embodiments of the present application, for each of the N shards, the length of the Pod naming range corresponding to this shard is greater than the number of Pods under this shard. For example, when there are 10 Pods under this shard, the length of the Pod naming range corresponding to this shard is greater than 10, such as 20, 100, 200, etc. This can ensure that the Pod naming under this shard is not continuous, facilitating the addition of Pods to the replicas under this shard.
[0143] The embodiments of the present application do not limit the specific manner in which the Pod controller determines the Pod naming range corresponding to each of the N shards based on the Pod shard information and the Pod replica information.
[0144] In some embodiments, the Pod sharding information includes a preset number of shards N and the number of replicas under each shard. The Pod replica information includes the number of Pods included under each replica, where the number of replicas under each shard can be different, and the number of Pods included under each replica can also be different. In this way, for each of the N shards, based on the number of replicas under the shard and the number of Pods included in each replica under the shard, the Pod naming range corresponding to the shard is determined. For example, for shard 1 among the N shards, there are 2 replicas under shard 1. The first replica includes 1 Pod, and the second replica includes 2 Pods. Since the second replica includes more Pods, a longer Pod naming range can be allocated to the second replica. For example, a Pod naming range of 40 is allocated to the second replica. The first replica includes fewer Pods, so a shorter Pod naming range can be allocated to the first replica. For example, a Pod naming range of 10 is allocated to the first replica. In this way, the Pod naming range corresponding to shard 1 can be a Pod naming range with a length greater than or equal to 40 + 10 = 50.
[0145] In some embodiments, if the above-mentioned Pod sharding information includes a preset number of shards N and the maximum number of replicas included in each shard, the Pod replica information includes the maximum number of co-existing Pods in each replica, and the maximum number of replicas included in each shard is the same, and the maximum number of co-existing Pods in each replica is also the same, the above S103 includes the following steps of S103-A and S103-B:
[0146] S103-A: For the i-th shard, based on the preset number of shards N, determine the index of the i-th shard among the N shards;
[0147] S103-B: Based on the index of the i-th shard among the N shards, the maximum number of replicas included in each shard, and the maximum number of co-existing Pods in each replica, determine the Pod naming range corresponding to the i-th shard.
[0148] In the embodiments of the present application, the specific methods for determining the Pod naming range corresponding to each of the N shards are basically the same. For the convenience of description, the i-th shard among the N shards is taken as an example for illustration here.
[0149] When determining the Pod naming range corresponding to the i-th shard, first determine the index of the i-th shard among these N shards. In one example, the indexes of the N shards start from 0, as shown in Table 1:
[0150] Table 1
[0151] N shards Index of the shard The first shard 0 The second shard 1 …… …… The i-th shard i-1 …… …… The N-th shard N-1
[0152] As can be seen from Table 1 above, the index of the shards starts from 0. For example, the index of the first shard among N shards is 0, the index of the i-th shard is i - 1, and the index of the N-th shard is N - 1.
[0153] In some embodiments, the index of N shards can also start from numbers such as 1 or 2, and the embodiments of the present application do not limit this.
[0154] For the i-th shard among N shards, after determining the index of the i-th shard among N shards, based on this index, the maximum number of replicas included in each shard, and the maximum number of Pods coexisting in each replica, determine the Pod naming range corresponding to the i-th shard.
[0155] The embodiments of the present application do not limit the specific manner of determining the Pod naming range corresponding to the i-th shard based on the index of the i-th shard among N shards, the maximum number of replicas included in each shard, and the maximum number of Pods coexisting in each replica.
[0156] In some embodiments, based on any two or three of the index of the i-th shard among N shards, the maximum number of replicas included in each shard, and the maximum number of Pods coexisting in each replica, determine the length of the Pod naming range corresponding to the i-th shard. Then, multiply this length by the index of the i-th shard to determine the starting value of the Pod naming range corresponding to the i-th shard. For example, assume that the maximum number of replicas included in each shard is 5 and the maximum number of Pods coexisting in each replica is 2, and the index of the i-th shard among N shards is 1. Then the length of the Pod naming range corresponding to the i-th shard can be 5 + 2 + 1 = 8, and it can be determined that the Pod naming range corresponding to the i-th shard is from 8 to 15.
[0157] In some embodiments, the above S103 - B includes the following steps of S103 - B1 and S103 - B2:
[0158] S103 - B1: Based on the maximum number of replicas included in each shard and the maximum number of Pods coexisting in each replica, determine the length of the Pod naming range corresponding to each shard among N shards;
[0159] S103 - B2: Based on the length of the Pod naming range and the index of the i-th shard among N shards, determine the Pod naming range corresponding to the i-th shard.
[0160] In this implementation, when determining the Pod naming range corresponding to the i-th shard, first, based on the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica, determine the length of the Pod naming range corresponding to each of the N shards. For example, the product of the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica is determined as the length of the Pod naming range corresponding to each of the N shards.
[0161] Next, based on the length of the Pod naming range and the index of the i-th shard among the N shards, determine the Pod naming range corresponding to the i-th shard.
[0162] For example, the product of the length of the Pod naming range and the index of the i-th shard among the N shards is determined as the starting value of the Pod naming range corresponding to the i-th shard; the value obtained by subtracting 1 from the sum of the starting point of the Pod naming range corresponding to the i-th shard and the length of the Pod naming range is determined as the ending value of the Pod naming range corresponding to the i-th shard.
[0163] Illustrate with an example. Suppose the maximum number of replicas included in each shard is 5 and the maximum number of co-existing Pods in each replica is 2, and the index of the i-th shard among the N shards is 0. Then the length of the Pod naming range corresponding to the i-th shard can be 5 * 2 = 10, the starting value of the Pod naming range corresponding to the i-th shard is 0 of 10 * 0, and the ending value of the Pod naming range corresponding to the i-th shard is 0 + 10 - 1 = 9. Therefore, the Pod naming range corresponding to the i-th shard is from 0 to 9.
[0164] The specific process of determining the Pod naming range corresponding to the $i$-th shard among the $N$ shards is introduced above. Referring to the above method, the Pod naming range corresponding to each of the $N$ shards can be determined. For example, assume $N = 2$, the maximum number of replicas included in each shard is 100, and the maximum number of co-existing Pods in each replica is 2. The index of the first shard among the 2 shards is 0, and the index of the second shard among the 2 shards is 1. When determining the Pod naming range corresponding to the first shard, first, based on the maximum number of replicas 100 included in each shard and the maximum number of co-existing Pods 2 in each replica, determine the length of the Pod naming range corresponding to each of the 2 shards. For example, the product of the maximum number of replicas 100 included in each shard and the maximum number of co-existing Pods 2 in each replica, which is 200, is determined as the length of the Pod naming range corresponding to each of the 2 shards. Then, based on the length of the Pod naming range and the index 0 of the first shard among the 2 shards, determine the Pod naming range corresponding to the first shard. For example, the product of the index 0 of the first shard among the 2 shards and the length 200 of the Pod naming range (i.e., 0) is determined as the starting value of the Pod naming range corresponding to the first shard, and the value obtained by adding 200 to the starting value 0 of the Pod naming range corresponding to the first shard and then subtracting 1 (i.e., 199) is determined as the ending value of the Pod naming range corresponding to the first shard. In this way, the Pod naming range corresponding to the first shard can be obtained as 0 to 199. Similarly, for the second shard, based on the length of the Pod naming range and the index 1 of the second shard among the 2 shards, determine the Pod naming range corresponding to the second shard. For example, the product of the index 1 of the second shard among the 2 shards and the length 200 of the Pod naming range (i.e., 200) is determined as the starting value of the Pod naming range corresponding to the second shard, and the value obtained by adding 200 to the starting value 200 of the Pod naming range corresponding to the second shard and then subtracting 1 (i.e., 399) is determined as the ending value of the Pod naming range corresponding to the second shard. In this way, the Pod naming range corresponding to the second shard can be obtained as 200 to 399.
[0165] After the Pod controller determines the Pod naming range corresponding to each of the $N$ shards based on the above steps, it executes the following step S104.
[0166] S104: For the $i$-th shard among the $N$ shards, within the Pod naming range corresponding to the $i$-th shard, determine the names of the Pods under each replica in the $i$-th shard.
[0167] Among them, the naming of the Pods in the $i$-th shard is not continuous, and $i$ is a positive integer less than or equal to $N$.
[0168] In the embodiment of the present application, based on the above steps, the Pod naming range corresponding to each of the N shards is determined. Then, based on the Pod naming range corresponding to each shard, the Pods under each shard are named to obtain the unique identifier of each Pod. Among them, for each of the N shards, within the Pod naming range corresponding to the shard, the specific method for determining the names of the Pods under each replica in the shard is basically the same. For the convenience of description, the i-th shard among the N shards is taken as an example for illustration.
[0169] For the i-th shard, after determining the Pod naming range corresponding to the i-th shard based on the above steps, within the Pod naming range corresponding to the i-th shard, the Pods under the i-th shard are named. That is to say, the names of the Pods under the i-th shard are all within the Pod naming range corresponding to the i-th shard. For example, when the Pod naming range corresponding to the i-th shard is from 0 to 99, the names of the Pods under the i-th shard are the values from 0 to 99.
[0170] The embodiment of the present application does not limit the specific method for the Pod controller to determine the names of the Pods under each replica in the i-th shard within the Pod naming range corresponding to the i-th shard.
[0171] In some embodiments, based on the above steps, the Pod controller determines the number of replicas included in the i-th shard and the number of Pods included in each replica, creates the corresponding number of Pods under each replica, and after determining the Pod naming range corresponding to the i-th shard, can divide the Pod naming range corresponding to the i-th shard based on the number of replicas included in the i-th shard. For example, based on the number of replicas, evenly divide the Pod naming range corresponding to the i-th shard to obtain the named sub-ranges corresponding to each replica under the i-th shard. For each replica, within the named sub-range corresponding to the replica, name the Pods under the replica. For example, assume that the Pod naming range corresponding to the i-th shard is from 0 to 99, and the i-th shard includes 2 replicas. In this way, evenly divide the Pod naming range from 0 to 99 corresponding to the i-th shard into two named sub-ranges, namely the named sub-range from 0 to 49 corresponding to replica 1 and the named sub-range from 50 to 99 corresponding to replica 2. In this way, within the named sub-range from 0 to 49, determine the naming of the Pods under replica 1. For example, if there is 1 Pod under replica 1, then 0 can be determined as the naming of the Pod, or any value from 0 to 99 can be determined as the naming of the Pod. Similarly, within the named sub-range from 50 to 99, determine the naming of the Pods under replica 2. For example, if there is 1 Pod under replica 2, then 50 can be determined as the naming of the Pod, or any value from 50 to 99 can be determined as the naming of the Pod. The above is an introduction to the process of evenly dividing the Pod naming range corresponding to the i-th shard based on the number of replicas included in the i-th shard to obtain the named sub-ranges corresponding to each replica under the i-th shard, and then naming the Pods under each replica within the named sub-ranges corresponding to each replica. In some embodiments, based on the number of replicas included in the i-th shard and the number of Pods included in each replica, non-uniformly divide the Pod naming range corresponding to the i-th shard. For example, divide more named sub-ranges for replicas with more Pods and fewer named sub-ranges for replicas with fewer Pods, and then name the Pods under each replica within the named sub-ranges corresponding to each replica.
[0172] In some embodiments, the above S104 includes the following steps of S104-A and S104-B:
[0173] S104-A. For the j-th Pod in the i-th shard, determine the replica index of the k-th replica where the j-th Pod is located in the i-th shard, where both k and j are positive integers;
[0174] S104-B. Based on the replica index of the k-th replica and the Pod naming range corresponding to the i-th shard, determine the naming of the j-th Pod.
[0175] In the embodiments of the present application, the specific manner of determining the name of each Pod in the i-th shard is basically the same. For the convenience of description, the j-th Pod in the i-th shard is taken as an example for illustration here.
[0176] When the Pod controller determines the name of the j-th Pod in the i-th shard, it first determines the replica index of the replica where the j-th Pod is located in the i-th shard. For example, if the replica where the j-th Pod is located is the k-th replica in the i-th shard, and the i-th shard includes m replicas, then determine the replica index of the k-th replica among the m replicas in the i-th shard.
[0177] In some examples, the replica index under the shard starts from 0. Of course, it can also start from other values such as 1, 2, etc., and the embodiments of the present application do not limit this.
[0178] Illustrate by way of example, as Figure 6 shown, assume that the stateful service corresponds to 2 shards, that is, N = 2, which are respectively denoted as s0 and s1. Each of these 2 shards includes 2 replicas. The 2 replicas under shard s0 are denoted as s0r0 and s0r1, and the 2 replicas under s1 are denoted as s1r0 and s1r1. There is 1 Pod under each of the replicas s0r0, s0r1, and s1r0, and there are 2 Pods under the replica s1r1. Assume that the i-th shard is shard s0, and the j-th Pod is a Pod under the replica s0r1. As Figure 7 shown, the replica s0r1 where the j-th Pod is located is the 2nd replica among the 2 replicas included in shard s0, and its replica index is 1 (of course, it can also be other values. For example, when the replica index starts from 1, the replica index of s0r1 is 2). Assume that the i-th shard is shard s1, and when the j-th Pod is the first Pod under the replica s1r1, then the replica s1r0 where the j-th Pod is located is the 1st replica among the 2 replicas included in shard s1, and its replica index is 0 (of course, it can also be other values. For example, when the replica index starts from 1, the replica index of s1r0 is 1).
[0179] After the Pod control determines the replica index of the k-th replica where the j-th Pod is located in the i-th shard, it executes the steps of the above S104-B pair, and determines the name of the j-th Pod based on the replica index of the k-th replica and the Pod naming range corresponding to the i-th shard.
[0180] The embodiments of the present application do not limit the specific manner of determining the name of the j-th Pod based on the replica index of the k-th replica and the Pod naming range corresponding to the i-th shard.
[0181] In a possible implementation, the Pod controller divides the Pod naming range corresponding to the i-th shard into multiple named sub-ranges based on the number of replicas included in the i-th shard. For example, if the Pod naming range corresponding to the i-th shard is from 0 to 99 and the i-th shard includes 2 replicas, then the Pod naming range from 0 to 99 can be divided into 2 named sub-ranges, that is, the named sub-range from 0 to 49 corresponding to the first replica under the i-th shard and the named sub-range from 50 to 99 corresponding to the second replica. Then, based on the replica index of the k-th replica where the j-th Pod is located, the naming of the j-th Pod is determined. For example, if the j-th Pod is a Pod under the second replica, the replica index of the second replica is 1, and the named sub-range corresponding to the second replica is from 50 to 99. Thus, based on the replica index 1 of the second replica and the named sub-range from 50 to 99 corresponding to the second replica, the naming of the j-th Pod is determined. For example, if the j-th Pod is the first Pod in the second replica, then the sum value (i.e., 51) of the starting value 50 of the named sub-range corresponding to the second replica and the replica index 1 of the second replica is determined as the naming of the j-th Pod. If the j-th Pod is the second Pod in the second replica, then the value obtained by adding the sum value of the starting value 50 of the named sub-range corresponding to the second replica and the replica index 1 of the second replica and a preset value (such as 1) (such as 52) is determined as the naming of the j-th Pod.
[0182] In a possible implementation, the above S104-B includes the following steps of S104-B1 to S104-B3:
[0183] S104-B1. Multiply the replica index of the k-th replica by the maximum number of Pods coexisting in each replica to obtain a first product;
[0184] S104-B2. Determine the naming of the first Pod in the k-th replica as the sum value of the starting value of the Pod naming range corresponding to the i-th shard and the first product;
[0185] S104-B3. Based on the index of the j-th Pod in the k-th replica and the naming of the first Pod in the k-th replica, determine the naming of the j-th Pod.
[0186] In this implementation, the Pod controller determines the replica index of the k-th replica where the j-th Pod in the i-th shard is located, and then based on the replica index of the k-th replica and the Pod naming range corresponding to the i-th shard, determines the naming of the first Pod in the k-th replica. Specifically, multiply the replica index of the k-th replica by the maximum number of Pods coexisting in each replica to obtain a first product, and determine the sum value of the starting value of the Pod naming range corresponding to the i-th shard and the first product as the naming of the first Pod in the k-th replica.
[0187] In one example, the Pod controller can determine the name of the first Pod in the k-th replica where the j-th Pod in the i-th shard is located through the following formula (1):
[0188] ID = (slots * interval) * a + interval * b (1)
[0189] Where ID is the name of the first Pod in the k-th replica where the j-th Pod in the i-th shard is located, slots is the maximum number of replicas included in each shard, interval is the maximum number of co-existing Pods in each replica, a is the index of the i-th shard among N shards, and b is the replica index of the k-th replica in the i-th shard.
[0190] For example, assume that the maximum number of replicas slots included in each shard is 100, the maximum number of co-existing Pods interval in each replica is 2. Assume that the i-th shard is the 2nd shard among N shards, its shard index is 1, and the j-th Pod is the first replica under the 2nd shard, and its replica index is 0. In this way, (slots * interval) * 1 + interval * 0 = (100 * 2) * 1 + 2 * 0 = 200 can be determined as the name of the first Pod in the first replica under the 2nd shard.
[0191] Next, based on the index of the j-th Pod in the k-th replica and the name of the first Pod in the k-th replica, determine the name of the j-th Pod.
[0192] For example, if the j-th Pod is the first Pod in the k-th replica, then determine the name of the first Pod in the k-th replica as the name of the j-th Pod.
[0193] For another example, if the j-th Pod is not the first Pod in the k-th replica, then determine the sum of the index of the j-th Pod in the k-th replica and the name of the first Pod in the k-th replica as the name of the j-th Pod.
[0194] To further illustrate the technical solution of the embodiments of the present application, the following several examples are used for illustration.
[0195] Example 1, the initial configuration information corresponding to the stateful service includes the following code:
[0196]
[0197] In this example, the number of shards N corresponding to the stateful service is 2. The maximum number of replicas slots included in each shard is 100, the default number of replicas for each shard is 2, the maximum number of co-existing Pods interval in each replica is 2, and the default number of Pods for each replica is 1. Based on the above information, the corresponding relationships among the shards, replicas, and Pods of the stateful service can be obtained as Figure 7 shown, that is, the stateful service corresponds to 2 shards, namely shard s0 and shard s1. Shard s0 includes 2 replicas, namely replica s0r0 and replica s0r1, and shard s1 includes 2 replicas, namely replica s1r0 and s1r1. By default, each replica includes 1 Pod.
[0198] Based on the method shown in the above steps, the Pod controller names each Pod under each replica in shards s0 and s1.
[0199] Specifically, for shard s0, first, based on the maximum number of replicas 100 included in each shard and the maximum number of co-existing Pods 2 in each replica, determine the length of the Pod naming interval corresponding to shard s0. For example, multiply the length of the Pod naming interval (i.e., 200) by the index of shard s0 in these 2 shards (e.g., 0) to determine the starting value of the Pod naming interval corresponding to shard s0, which is 0. Subtract 1 from the sum of the starting point (e.g., 0) of the Pod naming interval corresponding to shard s0 and the length of the Pod naming interval (200) to determine the ending value of the Pod naming interval corresponding to shard s0, which is 199. Then, name the 2 Pods under shard s0 within the Pod naming interval 0 to 199 corresponding to shard s0. For example, for the first Pod in the first replica s0r0 of shard s0, multiply the replica index 0 of the first replica s0r0 by the maximum number of co-existing Pods 2 in each replica to get the first product 0. Add the starting value 0 of the Pod naming interval corresponding to shard s0 to the first product 0 to determine the name of the first Pod in the first replica s0r0, which is P-0. For the first Pod in the second replica s0r1 of shard s0, multiply the replica index 1 of the second replica s0r1 by the maximum number of co-existing Pods 2 in each replica to get the first product 2. Add the starting value 0 of the Pod naming interval corresponding to shard s0 to the first product 2 to determine the name of the first Pod in the second replica s0r1, which is P-2.
[0200] For shard s1, first, based on the maximum number of replicas 100 included in each shard and the maximum number of Pods coexisting in each replica, which is 2, determine the length of the Pod naming range corresponding to shard s1. For example, multiply the length of the Pod naming range (i.e., 200) by the index of shard s1 among these 2 shards (e.g., 1) to determine the starting value of the Pod naming range corresponding to shard s1, which is 200. Subtract 1 from the sum of the starting point (e.g., 200) of the Pod naming range corresponding to shard s1 and the length of the Pod naming range (200) to determine the ending value of the Pod naming range corresponding to shard s1, which is 399. Then, within the Pod naming range 200 to 399 corresponding to shard s1, name the 2 Pods under shard s1. For example, for the first Pod in the first replica s1r0 of shard s1, multiply the replica index 0 of the first replica s1r0 by the maximum number of Pods coexisting in each replica, which is 2, to get the first product 0. Add the sum of the starting value 200 of the Pod naming range corresponding to shard s1 and the first product 0 to determine the name of the first Pod in the first replica s1r0, which is P-200. For the first Pod in the second replica s1r1 of shard s1, multiply the replica index 1 of the second replica s1r1 by the maximum number of Pods coexisting in each replica, which is 2, to get the first product 2. Add the sum of the starting value 200 of the Pod naming range corresponding to shard s1 and the first product 2 to determine the name of the first Pod in the second replica s1r1, which is P-202.
[0201] As Figure 7 shown, in the embodiment of the present application, 2 shards are created, each shard contains 2 replicas, and each shard can accommodate up to 100 replicas at most. In this way, the Pod controller will generate a total of 4 Pods: `p-0, p-2, p-200, p-202`. Among them, `p-0, p-2` belong to the first shard; `p-200, p-202` belong to the second shard.
[0202] In the embodiment of the present application, the Pod controller reserves a part of the IDs according to the `slots` field for adding replicas when expanding the shard. Figure 7 Among them, the Pods created by the Pod controller for the second shard are `p-200, p-202`, and the even numbers between `p-4` and `p-198` are reserved for the first shard. In this way, if the first shard needs to be expanded in the future, multiple replicas such as `p-4, p-6,..., p-198` can be added to the first shard in sequence.
[0203] Example 2, the initial configuration information corresponding to the stateful service includes the following code shown:
[0204]
[0205]
[0206] In this example, the number of shards N corresponding to the stateful service is 2, the maximum number of replicas slots included in each shard is 5, the default number of replicas for each shard is 2, the maximum number of co-existing Pods interval in each replica is 2, and the default number of Pods for each replica is 1. Based on the above information, the corresponding relationships between the shards, replicas, and Pods of the stateful service can be obtained as Figure 8 shown, that is, the stateful service corresponds to 2 shards, namely shard s0, shard s1, and shard s3. Shard s0 includes 2 replicas, namely replica s0r0 and replica s0r1. Shard s1 includes 2 replicas, namely replica s1r0 and s1r1. Shard s2 includes 2 replicas, namely replica s2r0 and s2r1. By default, each replica includes 1 Pod.
[0207] Based on the method shown in the above steps, the Pod controller names each Pod under each replica in shard s0, shard s1, and shard s3.
[0208] Specifically, for shard s0, first, based on the maximum number of replicas 5 included in each shard and the maximum number of co-existing Pods 2 in each replica, determine the length of the Pod naming interval corresponding to shard s0. For example, multiply the maximum number of replicas 5 included in each shard by the maximum number of co-existing Pods 2 in each replica (i.e., 10) to determine the length of the Pod naming interval corresponding to shard s0. Then, multiply the length of the Pod naming interval (i.e., 10) by the index of shard s0 among these 3 shards (e.g., 0) to determine the starting value of the Pod naming interval corresponding to shard s0, which is 0. Subtract 1 from the sum of the starting point (e.g., 0) of the Pod naming interval corresponding to shard s0 and the length of the Pod naming interval (10) to determine the ending value of the Pod naming interval corresponding to shard s0, which is 9. Then, in the Pod naming interval 0 to 9 corresponding to shard s0, name the 2 Pods under shard s0. For example, for the first Pod in the first replica s0r0 of shard s0, multiply the replica index 0 of the first replica s0r0 by the maximum number of co-existing Pods 2 in each replica to get the first product 0. Add the starting value 0 of the Pod naming interval corresponding to shard s0 to the first product 0 to determine the name of the first Pod in the first replica s0r0 of shard s0, which is P-0. For the first Pod in the second replica s0r1 of shard s0, multiply the replica index 1 of the second replica s0r1 by the maximum number of co-existing Pods 2 in each replica to get the first product 2. Add the starting value 0 of the Pod naming interval corresponding to shard s0 to the first product 2 to determine the name of the first Pod in the second replica s0r1 of shard s0, which is P-2.
[0209] For shard s1, first, based on the maximum number of replicas 5 included in each shard and the maximum number of co-existing Pods 2 in each replica, determine the length of the Pod naming range corresponding to shard s1. For example, multiply the maximum number of replicas 5 included in each shard by the maximum number of co-existing Pods 2 in each replica (i.e., 10) to determine the length of the Pod naming range corresponding to shard s1. Then, multiply the length of the Pod naming range (i.e., 10) by the index of shard s1 among these 3 shards (e.g., 1) to determine the starting value of the Pod naming range corresponding to shard s1, which is 10. Subtract 1 from the sum of the starting point (e.g., 10) of the Pod naming range corresponding to shard s1 and the length of the Pod naming range (10) to determine the ending value of the Pod naming range corresponding to shard s1, which is 19. Then, name the 2 Pods under shard s1 within the Pod naming range 10 to 19 corresponding to shard s1. For example, for the first Pod in the first replica s1r0 of shard s1, multiply the replica index 0 of the first replica s1r0 by the maximum number of co-existing Pods 2 in each replica to get the first product 0, and determine the name of the first Pod in the first replica s1r0 as the sum of the starting value 10 of the Pod naming range corresponding to shard s1 and the first product 0, which is P-10. For the first Pod in the second replica s1r1 of shard s1, multiply the replica index 1 of the second replica s1r1 by the maximum number of co-existing Pods 2 in each replica to get the first product 2, and determine the name of the first Pod in the second replica s1r1 as the sum of the starting value 10 of the Pod naming range corresponding to shard s1 and the first product 2, which is P-12.
[0210] For shard s2, first, based on the maximum number of replicas 5 included in each shard and the maximum number of co-existing Pods 2 in each replica, determine the length of the Pod naming range corresponding to shard s2. For example, multiply the maximum number of replicas 5 included in each shard and the maximum number of co-existing Pods 2 in each replica (i.e., 10) to determine the length of the Pod naming range corresponding to shard s2. Next, multiply the length of the Pod naming range (i.e., 10) by the index of shard s2 among these 3 shards (e.g., 2) to determine the starting value of the Pod naming range corresponding to shard s2, which is 20. Subtract 1 from the sum of the starting point (e.g., 20) of the Pod naming range corresponding to shard s2 and the length of the Pod naming range (10) to determine the ending value of the Pod naming range corresponding to shard s2, which is 29. Then, within the Pod naming range 20 to 29 corresponding to shard s2, name the 2 Pods under shard s2. For example, for the first Pod in the first replica s2r0 of shard s2, multiply the replica index 0 of the first replica s2r0 by the maximum number of co-existing Pods 2 in each replica to get the first product 0, and determine the name of the first Pod in the first replica s2r0 as the sum of the starting value 20 of the Pod naming range corresponding to shard s2 and the first product 0, which is P-20. For the first Pod in the second replica s2r1 of shard s2, multiply the replica index 1 of the second replica s2r1 by the maximum number of co-existing Pods 2 in each replica to get the first product 2, and determine the name of the first Pod in the second replica s2r1 as the sum of the starting value 20 of the Pod naming range corresponding to shard s2 and the first product 2, which is P-22.
[0211] As Figure 8 shown, in the embodiment of the present application, 3 shards are created, each shard contains 2 replicas, and each shard can accommodate up to 10 replicas at most. In this way, the Pod controller will generate a total of 6 Pods: `p-0, p-2, p-10, p-12, p-20, p-22`. Among them, `p-0, p-2` belong to the first shard; `p-10, p-12` belong to the second shard; `p-20, p-22` belong to the third shard.
[0212] In the embodiment of the present application, the Pod controller reserves a part of the IDs according to the `slots` field for adding replicas when expanding the shards. Figure 8 In it, the Pods created by the Pod controller for the second shard are `p-10, p-12`, and the even numbers between `p-4` and `p-8` are reserved for the first shard. In this way, in the future, if the first shard needs to be expanded, three replicas `p-4, p-6, p-8` can be added to the first shard in sequence.
[0213] The management method for stateful services provided by the embodiments of this application can achieve flexible management of stateful services. Specifically, obtain the initial configuration information corresponding to the stateful service, where the initial configuration information includes Pod sharding information and Pod replica information. Then, based on the Pod sharding information and Pod replica information included in the initial configuration information, determine N shards corresponding to the stateful service, and create corresponding numbers of Pods under each replica of each shard. At the same time, based on the Pod sharding information and Pod replica information, determine the Pod naming range corresponding to each of the N shards. In this way, for each of the N shards, for example, the i-th shard, within the Pod naming range corresponding to the i-th shard, determine the names of the Pods under each replica in the i-th shard, where the names of the Pods in each shard are not consecutive. That is, the embodiments of this application group the Pods corresponding to the stateful service according to the Pod sharding information and Pod replica information, and determine the Pod naming range corresponding to each shard, and then name the Pods under each replica in the shard within the Pod naming range corresponding to the shard, so that the Pod naming is combined with the sharding information and replica information where the Pod is located. In this way, subsequent independent operations can be performed on the Pods under any replica in any shard based on the Pod naming, which fully enhances the management of stateful services in the cloud-native scenario and can help the smooth and stable containerization of stateful services such as databases, middleware, and consensus systems.
[0214] The above text introduces the specific method for determining unique names for the Pods under stateful services in stateful service management. Based on the above naming, the management method for stateful services in the embodiments of this application further includes Figure 9 the scheme shown.
[0215] Figure 9 It is a schematic flowchart of the management method for stateful services provided by an embodiment of this application. Figure 9 The management method for stateful services shown can be understood as a process of changing the Pods corresponding to the stateful service created above.
[0216] As Figure 9 shown, the management method for stateful services in the embodiments of this application includes:
[0217] S201. Obtain the initial configuration information corresponding to the stateful service.
[0218] Among them, the initial configuration information includes Pod sharding information and Pod replica information.
[0219] For the specific implementation process of the above S201, refer to the relevant description of the above S101, and details are not elaborated here.
[0220] S202. Determine the N shards corresponding to the stateful service based on the Pod shard information and the Pod replica information, and create the corresponding number of Pods under each replica of each shard.
[0221] Wherein, N is a positive integer.
[0222] For the specific implementation process of the above S202, refer to the relevant description of the above S102, and details are not described herein again.
[0223] S203. Determine the Pod naming range corresponding to each of the N shards based on the Pod shard information and the Pod replica information.
[0224] For the specific implementation process of the above S203, refer to the relevant description of the above S103, and details are not described herein again.
[0225] S204. For the i-th shard among the N shards, determine the names of the Pods under each replica in the i-th shard within the Pod naming range corresponding to the i-th shard, where i is a positive integer less than or equal to N.
[0226] For the specific implementation process of the above S204, refer to the relevant description of the above S104, and details are not described herein again.
[0227] The above S201 to S204 can be understood as the specific process of creating the corresponding number of Pods under the replicas in the N shards corresponding to the stateful service based on the initial configuration information corresponding to the stateful service and naming these Pods.
[0228] As can be seen from the above embodiments, the embodiments of the present application group the Pods corresponding to the stateful service according to the Pod shard information and the Pod replica information, determine the Pod naming range corresponding to each shard, and then name the Pods under each replica in the shard within the Pod naming range corresponding to the shard, so that the Pod naming is combined with the shard information and replica information where the Pod is located, so that subsequent independent operations can be performed on the Pods under any replica in any shard based on the Pod naming.
[0229] S205. Obtain the configuration change information corresponding to the stateful service.
[0230] Wherein, the configuration change information includes at least one of Pod addition indication information, Pod deletion indication information, Pod template update indication information, and replica rolling upgrade indication information.
[0231] The management method for the stateful service provided by the embodiments of the present application can be applied to a database cluster with multiple shards, multiple replicas, and a master-slave architecture.
[0232] There are the following requirements for the management of Pods in a database cluster with a multi - shard, multi - replica, master - slave architecture:
[0233] 1. The processes in the Pod need to be aware of which shard they belong to, which is necessary for detecting data continuity;
[0234] 2. Add or delete a shard;
[0235] 3. Add or delete replicas for any number of shards;
[0236] 4. There are non - peer configurations between Pods (such as: image, cpu, memory);
[0237] 5. Stable upgrade: When upgrading a certain replica (e.g., image), a new replica needs to be added to the shard first, and after the new replica is stable, a corresponding old replica is terminated.
[0238] To implement the above functions, independent operations (add / delete / modify) on Pods are required. After naming the Pods through the above naming method in the embodiments of this application, the processes in the Pods can perceive which shard they belong to based on the name of the Pod, and can also add or delete a shard as needed, and / or add or delete replicas for any number of shards, and / or perform non - peer configurations between Pods, and / or achieve stable upgrade of replicas.
[0239] Specifically, in the embodiments of this application, the Pod controller can obtain the configuration change information corresponding to the stateful service. The embodiments of this application do not limit the specific manner in which the Pod controller obtains the configuration change information corresponding to the stateful service.
[0240] In a possible implementation, the user directly inputs the configuration change information corresponding to the stateful service. For example, the user inputs to add a shard or add replicas under one or several shards, or the user inputs that the shards and replicas corresponding to the stateful service are changed to specific values, etc.
[0241] For example, if the user instructs to adjust the number of shards of the stateful service to N1 and the number of replicas to M1, then compare the shard number N1 and the replica number M1 with the current shard number and replica number to determine whether to add or delete shards, or add or delete replicas, etc. For example, the current Pods corresponding to the stateful service are as Figure 8As shown, it includes 3 shards, each shard includes 2 replicas, and each replica includes a Pod. Suppose the user instructs to adjust the number of shards corresponding to the stateful service to 2 and each shard includes 2 replicas, then it can be determined that the configuration change information indicates that the Pods under one shard will be deleted. Suppose the user instructs to adjust the number of shards corresponding to the stateful service to 3 and each shard includes 3 replicas, then it can be determined that the configuration change information indicates that one replica and one Pod will be added under each shard.
[0242] In a possible implementation manner, the Pod controller can automatically generate the configuration change information corresponding to the stateful service based on the running state of the current cluster. For example, when detecting that a certain Pod fails or goes offline, then delete the Pod, or when the load of the Pods in a certain shard is high, a new Pod can be created, etc.
[0243] In the embodiment of the present application, the configuration change information corresponding to the stateful service includes at least one of Pod addition indication information, Pod deletion indication information, Pod template update indication information, and replica rolling upgrade indication information.
[0244] In some embodiments, the configuration change information includes any one of Pod addition indication information, Pod deletion indication information, Pod template update indication information, and replica rolling upgrade indication information. For example, the configuration change information includes Pod addition indication information, and the Pod addition indication information is used to indicate the addition of a specific one or several Pods.
[0245] In some embodiments, the configuration change information includes any two of Pod addition indication information, Pod deletion indication information, Pod template update indication information, and replica rolling upgrade indication information. For example, the configuration change information includes Pod addition indication information and Pod deletion indication information, and the Pod deletion indication information is used to delete a specific one or several Pods.
[0246] In some embodiments, the configuration change information includes any three of Pod addition indication information, Pod deletion indication information, Pod template update indication information, and replica rolling upgrade indication information. For example, the configuration change information includes Pod addition indication information, Pod deletion indication information, and Pod template update indication information, and the Pod template update indication information is used to update the template resource information of a specific one or several Pods.
[0247] In some embodiments, the configuration change information includes all of Pod addition indication information, Pod deletion indication information, Pod template update indication information, and replica rolling upgrade indication information. Among them, the replica rolling upgrade indication information is used to perform rolling upgrade on the Pods in a specific replica.
[0248] S206. Change the Pod information currently corresponding to the stateful service based on the configuration change information.
[0249] In the embodiment of the present application, after the Pod controller obtains the configuration change information corresponding to the stateful service, it then changes the Pod information currently corresponding to the stateful service based on at least one of the Pod addition indication information, Pod deletion indication information, Pod template update indication information, and replica rolling upgrade indication information included in the configuration change information. For example, based on the Pod addition indication information, specific Pods are added in the current cluster, or based on the Pod deletion indication information, specific Pods are deleted in the current cluster, etc.
[0250] In one example, assume that the Pod controller in the embodiment of the present application is the sss controller, and the configuration change information corresponding to the stateful service is presented in the form of an sss object. Thus, as Figure 10 shown, the sss controller monitors the sss object. After the change (creation / updating / deletion) of the sss object is completed, the sss controller observes the change of the sss object, obtains the configuration change information, and tunes the currently existing Pods according to the finally expected state described in the configuration change information, including at least one of the following:
[0251] Add specified Pod: For the creation scenario, create Pods that did not exist before. For the reconstruction scenario (such as specification changes, etc.), after the Pods are deleted, they will be re-created;
[0252] Update specified Pod: For all change scenarios that do not require Pod reconstruction, the Pods need to be updated, including but not limited to: annotations, labels, tolerations, image information, etc.;
[0253] Delete specified Pod: These Pods may be the Pods that are truly expected to be deleted, or may be the Pods that need to be reconstructed (after reconstruction, some updates can take effect, such as: specification configuration, etc.).
[0254] As can be seen from the above, in the embodiments of the present application, the configuration change information corresponding to the stateful service includes one or more of the Pod addition indication information, Pod deletion indication information, Pod template update indication information, and replica rolling upgrade indication information. The following describes the specific process of changing the current Pod information corresponding to the stateful service when any one of the Pod addition indication information, Pod deletion indication information, Pod template update indication information, and replica rolling upgrade indication information included in the configuration change information. If there are multiple of the Pod addition indication information, Pod deletion indication information, Pod template update indication information, and replica rolling upgrade indication information included in the configuration change information, then the change to the current Pod information corresponding to the stateful service can be the superposition of these multiple ones.
[0255] Case 1, if the configuration change information includes the Pod addition indication information, then step S206 includes the following steps:
[0256] S206-A1: Based on the Pod addition indication information, determine the names of the M first Pods to be added, where M is a positive integer;
[0257] S206-A2: For each of the M first Pods, based on the name of the first Pod, determine the first shard and the first replica where the first Pod is located;
[0258] S206-A3: Add the first Pod in the first replica under the first shard.
[0259] Among them, the Pod addition indication information is used to indicate the addition of a specific one or several Pods. The embodiments of the present application do not limit the specific manifestation form of the Pod addition indication information.
[0260] In one example, the Pod addition indication information includes the names of the M first Pods to be added. For example, the Pod addition indication information includes an `extras` field, and the `extras` field includes an array composed of Pod IDs, indicating the list of Pods to be added.
[0261] Exemplarily, the configuration change information corresponding to the stateful service is as follows:
[0262]
[0263] As shown above, the configuration change information includes the Pod addition indication information, and the Pod addition indication information indicates that on the basis of the default shard (for example, 3) and replica (for example, 2), add the Pod `p-1`. It can be seen that the Pod addition indication information includes the name of the 1 first Pod to be added (that is, the Pod `p-1`).
[0264] In one example, the Pod addition indication information is used to indicate adding a replica under a certain shard. Based on the above naming rules, the naming of the Pod under the to-be-added replica can be determined. For example, as Figure 8 shown, assume adding a replica under the first shard. In this way, the first shard includes 3 replicas, and each replica includes a Pod. Among them, the naming of the Pod under the first replica is p-0, and the naming of the Pod under the second replica is p-2. Then, the naming of the to-be-added Pod under the third replica is p-3. In this way, the naming of the to-be-added Pod can be obtained.
[0265] In the embodiments of the present application, after the Pod controller determines the naming of the M first Pods to be added based on the Pod addition indication information, based on the naming of these M first Pods, it determines the shard and replica where each of these M first Pods is located, and then adds the corresponding first Pod under the corresponding shard and replica.
[0266] In the embodiments of the present application, for each of the M first Pods, the specific method of determining the shard and replica where the first Pod is located based on the naming of the first Pod is basically the same. For the convenience of representation, one first Pod is used as an example for description here.
[0267] In the embodiments of the present application, for the convenience of description, the shard where the first Pod is located is denoted as the first shard, and the replica where the first Pod is located is denoted as the first replica.
[0268] As can be seen from the above, in the embodiments of the present application, when naming a Pod, the naming is based on the shard information and replica information where the Pod is located. In this way, when the naming of the first Pod is known, the shard and replica where the first Pod is located can be deduced by the reverse process of the naming.
[0269] In one example, based on the naming of the first Pod, determining the first shard and the first replica where the first Pod is located includes the following steps:
[0270] Step 11: Obtain the maximum number of replicas included in each shard and the maximum number of coexisting Pods in each replica;
[0271] Step 12: Based on the maximum number of replicas included in each shard and the maximum number of coexisting Pods in each replica, determine the length of the Pod naming interval corresponding to each shard;
[0272] Step 13: Based on the naming of the first Pod and the length of the Pod naming interval, determine the first shard where the first Pod is located;
[0273] Step 14: Determine the first replica where the first Pod is located based on the name of the first Pod, the length of the Pod naming range, and the maximum number of co-existing Pods in each replica.
[0274] In this implementation, when the Pod controller determines the first shard and the first replica where the first Pod is located, it first obtains the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica. For example, it obtains the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica from the configuration change information, or obtains the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica from the initial configuration information. Then, based on the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica, it determines the length of the Pod naming range corresponding to each shard. For example, it determines the product of the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica as the length of the Pod naming range corresponding to each shard. In this way, it can determine the first shard where the first Pod is located based on the name of the first Pod and the length of the Pod naming range. For example, it performs a floor operation on the quotient of the name of the first Pod and the length of the Pod naming range to obtain the first shard where the first Pod is located.
[0275] Exemplarily, according to the following formula (2), determine the first shard where the first Pod is located:
[0276] ShardID = PodID / (Slots * Interval) (2)
[0277] Where ShardID is the index of the first shard where the first Pod is located, PodID is the name of the first Pod, Slots is the maximum number of replicas included in each shard, Interval is the maximum number of co-existing Pods in each replica, Slots * Interval is the length of the Pod naming range, and " / " performs a floor operation on the quotient.
[0278] At the same time, based on the name of the first Pod, the length of the Pod naming range, and the maximum number of co-existing Pods in each replica, it can determine the first replica where the Pod is located. For example, it performs a remainder operation on the name of the first Pod and the length of the Pod naming range to obtain the remainder; it performs a floor operation on the quotient of the remainder and the maximum number of co-existing Pods in each replica to obtain the first replica where the first Pod is located.
[0279] Exemplarily, according to the following formula (3), determine the first replica where the first Pod is located:
[0280] ReplicaID = PodID % (Slots * Interval)) / Interval (3)
[0281] Among them, ReplicaID is the index of the first replica where the first Pod is located, PodID is the name of the first Pod, Slots is the maximum number of replicas included in each shard, Interval is the maximum number of co-existing Pods in each replica, Slots * Interval is the length of the Pod name range, and "%" is the modulo operation.
[0282] Referring to the above method, based on the names of the M first Pods, the first shard and the first replica where each of the M first Pods is located can be determined, and then the first Pod can be added under the corresponding first shard and first replica.
[0283] For example, assume that the name of the first Pod is p-1, Slots is 5, and Interval is 2. Then the current Pods corresponding to the stateful service are as follows Figure 8 shown. Based on the above method, it can be determined that the first shard where the first Pod is located is the first shard, that is, shard s0, and the first replica where it is located is the first replica, that is, s0r0. Thus, as Figure 11 shown, create the first Pod named p-1 under the replica s0r0 of shard s0. At this time, the list of Pods included in the cluster is: `p-0, p-1, p-2, p-10, p-12, p-20, p-22`.
[0284] Case 2, if the configuration change information includes Pod deletion indication information, then S206 includes the following steps:
[0285] S206-B1: Based on the Pod deletion indication information, determine the names of the K second Pods to be deleted, where K is a positive integer;
[0286] S206-B2: For each of the K second Pods, based on the name of the second Pod, determine the second shard and the second replica where the second Pod is located;
[0287] S206-B3: Delete the second Pod under the second replica in the second shard.
[0288] Among them, the Pod deletion indication information is used to indicate the deletion of a specific one or several Pods. The specific manifestation form of the Pod deletion indication information in the embodiments of this application is not limited.
[0289] In one example, the Pod deletion indication information includes the names of the K second Pods to be deleted. For example, the Pod deletion indication information includes a `suppressions` field, and the `suppressions` field includes an array composed of Pod IDs, indicating the list of Pods to be deleted.
[0290] Exemplarily, the configuration change information corresponding to the stateful service is as follows:
[0291]
[0292] As shown above, the configuration change information includes a Pod deletion indication message. The Pod deletion indication message indicates that, based on the default shards (e.g., 3) and replicas (e.g., 2), Pod `p-0` is to be deleted. Thus, it can be seen that the Pod deletion indication message includes the name of the one second Pod to be deleted (i.e., Pod `p-0`).
[0293] In one example, the Pod deletion indication message is used to indicate the deletion of a certain replica under a certain shard. In this way, based on the above naming rules, the name of the Pod under the replica to be deleted can be determined. For example, as Figure 8 shown, assuming that the first replica under the second shard is to be deleted, and this first replica includes a Pod named p-0, then the Pod named p-0 is determined as the second Pod to be deleted.
[0294] In the embodiments of the present application, after the Pod controller determines the names of the K second Pods to be deleted based on the Pod deletion indication message, based on the names of these K second Pods, it determines the shard and replica where each of these K second Pods is located, and then deletes the corresponding second Pods under the corresponding shards and replicas.
[0295] In the embodiments of the present application, for each of the K second Pods, the specific method of determining the shard and replica where the second Pod is located based on the name of the second Pod is basically the same. For the sake of convenience of representation, one second Pod is taken as an example for illustration here.
[0296] In the embodiments of the present application, for the sake of convenience of description, the shard where the second Pod is located is denoted as the second shard, and the replica where the second Pod is located is denoted as the second replica.
[0297] As can be seen from the above, in the embodiments of the present application, when naming the Pod, the naming is based on the shard information and replica information where the Pod is located. In this way, when the name of the second Pod is known, the shard and replica where the second Pod is located can be deduced by the reverse process of the naming.
[0298] In one example, based on the name of the second Pod, determining the second shard and second replica where the second Pod is located includes the following steps:
[0299] Step 21: Obtain the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica;
[0300] Step 22: Determine the length of the Pod naming range corresponding to each shard based on the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica.
[0301] Step 23: Determine the second shard where the second Pod is located based on the name of the second Pod and the length of the Pod naming range.
[0302] Step 24: Determine the second replica where the Pod is located based on the name of the second Pod, the length of the Pod naming range, and the maximum number of co-existing Pods in each replica.
[0303] Among them, for the specific processes of Step 21 to Step 24, the specific descriptions of the above Step 11 to Step 14 can be referred to. Only need to understand the first Pod in Step 11 to Step 14 as the second Pod, and will not be elaborated here.
[0304] For example, assume that the name of the second Pod is p-0, Slots is 5, and Interval is 2. Then the Pods currently corresponding to the stateful service are as Figure 8 shown. Based on the above method, it can be determined that the second shard where the second Pod is located is the second shard, that is, shard s0, and the second replica where it is located is the second replica, that is, s0r0. Thus, as Figure 12 shown, delete the second Pod named p-0 under the replica s0r0 of shard s0. At this time, the list of Pods included in the cluster is: `p-2, p-10, p-12, p-20, p-22`.
[0305] In some embodiments, the priority of the Pod deletion indication information is higher than that of the Pod addition indication information. If the configuration change information includes the Pod addition indication information and the Pod deletion indication information, and the first Pod to be added indicated by the Pod addition indication information and the second Pod to be deleted indicated by the Pod deletion indication information are the same Pod, then skip the step of adding the first Pod. For example, extras: [1, 3], suppressions: [0, 1], that is, the names of the first Pods to be added are p-1 and p-3, and the names of the second Pods to be deleted are p-0 and p-1. At this time, when adding the first Pod, only add the Pod named p-3, and do not add the Pod named p-1.
[0306] Case 3: If the configuration change information includes the Pod template update indication information, then the above S206 includes the following steps:
[0307] S206-C1. Based on the Pod template update indication information, determine the names of the P third Pods whose templates are to be changed and the template configuration adjustment information corresponding to each of the P third Pods, where P is a positive integer;
[0308] S206-C2. For each of the P third Pods, based on the name of the third Pod, determine the third shard and the third replica where the third Pod is located;
[0309] S206-C3. Based on the template configuration adjustment information corresponding to the third Pod, adjust the template configuration of the third Pod in the third replica under the third shard, where the template configurations of the Pods corresponding to the stateful service are not completely the same.
[0310] In the embodiments of the present application, at least two of the Pods corresponding to the stateful service can have different template configurations to maintain non - equivalent configurations. The non - equivalent configurations include at least one of the following non - equivalences:
[0311] Resource cpu, memory;
[0312] volume(pvc)size(container specification);
[0313] image(image address of the container);
[0314] Pod labels&annotations;
[0315] pvc labels&annotations.
[0316] Among them, label is a key - value pair of key = value, and Label defines the metadata of the Kubernetes object. Annotation is the "additional" information arbitrarily defined by the user. Similar to Label, Annotation is also defined in the form of key / value key - value pairs.
[0317] In the embodiments of the present application, the template resources of a specific one or several Pods can be indicated to be adjusted through the Pod template update indication information. The specific manifestation form of the Pod template update indication information in the embodiments of the present application is not limited.
[0318] In one example, the Pod template update indication information includes the names of P third Pods whose templates are to be updated. For example, the Pod template update indication information includes an ordinals field, and the ordinals field includes an array composed of Pod IDs, recording which Pods apply this configuration. Optionally, a mixture field is included in partial, and partial is used to describe different template configurations. In one example, the same Pod name will only appear once in mixture, and configurations like `[{ordinals:"0"},{ordinals:"0,2}]` are not allowed.
[0319] Exemplarily, the configuration change information corresponding to the stateful service is as follows:
[0320]
[0321] As shown above, the configuration change information includes Pod template update indication information. The Pod template update indication information indicates that the configurations of 2 Pods, p-0 and p-2, and the associated PVCs are to be adjusted as follows: the cpu and mem resource requirements are adjusted to 1G and 2G respectively, and the upper limits are adjusted to 2G and 4G; the image is adjusted to xxx:v1; the pvc capacity is adjusted to 20G. At the same time, it is indicated that the images of 2 Pods, p-4 and p-6, are adjusted to xxx:v2. In this example, the names of the third Pods whose templates are to be adjusted and the template configuration adjustment information corresponding to each third Pod can be directly obtained.
[0322] In the embodiment of the present application, after the Pod controller determines the names of P third Pods whose templates are to be changed based on the Pod template update indication information, based on the names of these P third Pods, it determines the shards and replicas where each of these P third Pods is located, and then adjusts the templates of the third Pods under the corresponding shards and replicas.
[0323] In the embodiment of the present application, for each of the P third Pods, the specific method of determining the shard and replica where the third Pod is located based on the name of the third Pod is basically the same. For the convenience of representation, one third Pod is taken as an example for description here.
[0324] In the embodiment of the present application, for the convenience of description, the shard where the third Pod is located is denoted as the third shard, and the replica where the third Pod is located is denoted as the third replica.
[0325] As can be seen from the above, in the embodiment of the present application, when naming the Pod, it is named based on the shard information and replica information where the Pod is located. In this way, when the name of the third Pod is known, the shard and replica where the third Pod is located can be deduced by the reverse process of the naming.
[0326] In one example, based on the naming of the third Pod, determining the third shard and the third replica where the third Pod is located includes the following steps:
[0327] Step 31: Obtain the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica;
[0328] Step 32: Based on the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica, determine the length of the Pod naming range corresponding to each shard;
[0329] Step 33: Based on the naming of the third Pod and the length of the Pod naming range, determine the third shard where the third Pod is located;
[0330] Step 34: Based on the naming of the third Pod, the length of the Pod naming range, and the maximum number of co-existing Pods in each replica, determine the third replica where the Pod is located.
[0331] Among them, for the specific processes of Step 31 to Step 34, reference can be made to the specific descriptions of the above Step 11 to Step 14, only by understanding the first Pod in Step 11 to Step 14 as the third Pod, which will not be elaborated here.
[0332] Based on the above steps, for each of the P third Pods, determine the third shard and the third replica where it is located, and then based on the template configuration adjustment information corresponding to the third Pod, adjust the template configuration of the third Pod in the third replica under the third shard. For example, for the third Pod named p-0, based on the above steps, it is determined that the third shard where the third Pod named p-0 is located is the first shard, and the third replica where it is located is the first replica. Furthermore, adjust the template configuration of the third Pod p-0 under the first replica of the current first shard to: the cpu and mem resource requirements are adjusted to 1G and 2G respectively, and the upper limits are adjusted to 2G and 4G; the image is adjusted to xxx:v1; the pvc capacity is adjusted to 20G.
[0333] In the embodiment of the present application, in a stateful service, non-peer Pod configurations are required. Therefore, in the embodiment of the present application, the template configurations of the Pods corresponding to the stateful service are not completely the same, thus realizing non-peer configurations of the Pods.
[0334] Case 4, if the configuration change information includes replica rolling upgrade indication information, then the above S206 includes the following steps:
[0335] S206-D1: Based on the replica rolling upgrade indication information, determine the naming of the Q fourth Pods to be upgraded, where Q is a positive integer;
[0336] S206-D2. For each of the Q fourth Pods, determine the fourth shard and the fourth replica where the fourth Pod is located based on the naming of the fourth Pod.
[0337] S206-D3. Create the fourth Pod under the fourth replica in the fourth shard, and after the successful creation of the fourth Pod, delete the old Pod under the fourth replica in the fourth shard.
[0338] In the embodiments of the present application, the IDs of the Pods in each shard are not consecutive, and the missing names such as `p-1` are reserved for the replicas for rolling upgrades.
[0339] In the embodiments of the present application, the replica rolling upgrade indication information is used to indicate the upgrade of a specific one or several replicas. The embodiments of the present application do not limit the specific manifestation form of the P replica rolling upgrade indication information.
[0340] In one example, the replica rolling upgrade indication information includes the naming of the Q fourth Pods to be upgraded. For example, the replica rolling upgrade indication information includes a primedReplicas field, and the primedReplicas field includes an array composed of PodIDs, recording the IDs of the Pods to be upgraded.
[0341] Exemplarily, the configuration change information corresponding to the stateful service is as follows:
[0342]
[0343] As shown above, the configuration change information includes replica rolling upgrade indication information, and the replica rolling upgrade indication information upgrades the fourth replica where the Pod named p-1 is located.
[0344] In the embodiments of the present application, after the Pod controller determines the naming of the Q fourth Pods to be upgraded based on the replica rolling upgrade indication information, based on the naming of these Q fourth Pods, determine the shard and replica where each of these Q fourth Pods is located, and then upgrade the fourth Pod under the corresponding shard and replica.
[0345] In the embodiments of the present application, for each of the Q fourth Pods, the specific method of determining the shard and replica where the fourth Pod is located based on the naming of the fourth Pod is basically the same. For the sake of easy representation, one fourth Pod is taken as an example for illustration.
[0346] In the embodiments of the present application, for the sake of easy description, the shard where the fourth Pod is located is denoted as the fourth shard, and the replica where the fourth Pod is located is denoted as the fourth replica.
[0347] As can be seen from the above, in the embodiment of the present application, when naming a Pod, the naming is based on the shard information and replica information where the Pod is located. In this way, when the name of the fourth Pod is known, the shard and replica where the fourth Pod is located can be deduced through the reverse process of naming.
[0348] In one example, based on the name of the fourth Pod, determining the fourth shard and the fourth replica where the fourth Pod is located includes the following steps:
[0349] Step 41: Obtain the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica;
[0350] Step 42: Based on the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica, determine the length of the Pod naming interval corresponding to each shard;
[0351] Step 43: Based on the name of the fourth Pod and the length of the Pod naming interval, determine the fourth shard where the fourth Pod is located;
[0352] Step 44: Based on the name of the fourth Pod, the length of the Pod naming interval, and the maximum number of co-existing Pods in each replica, determine the fourth replica where the Pod is located.
[0353] Among them, for the specific processes of Step 41 to Step 44, reference can be made to the specific descriptions of Step 11 to Step 14 above, only by understanding the first Pod in Step 11 to Step 14 as the fourth Pod, which will not be elaborated here.
[0354] Based on the above steps, the fourth shard and the fourth replica where each of the Q fourth Pods is located are determined. For each of the Q fourth Pods, under the fourth replica of the fourth shard where the fourth Pod is located, create the fourth Pod, and after the creation of the fourth Pod is completed, delete the old Pod under the fourth replica of the fourth shard.
[0355] For example, assume that the name of the fourth Pod is p-1, Slots is 5, and Interval is 2, then the currently corresponding Pods of the stateful service are as Figure 8 shown. Based on the above method, it can be determined that the fourth shard where the fourth Pod is located is the fourth shard, that is, shard s0, and the fourth replica where it is located is the fourth replica, that is, s0r0 (subsequently represented by R-0). In this way, as Figure 13AAs shown, in the replica s0r0 of the shard s0, a fourth Pod named p-1 is newly created based on the upgraded relevant information. In the embodiment of the present application, to improve the stability of the cluster, when the fourth Pod is not yet completed, the Pod named p-0 is not deleted. After detecting that the fourth Pod named p-1 is created, the old Pod named p-0 in the replica R-0 of the shard s0 is deleted, thereby realizing the rolling upgrade of the replica R-0 of the shard s0. In some embodiments, after migrating the data on p-0 to p-1, p-0 can also be deleted.
[0356] In some embodiments, when upgrading replicas, the upgrade can be performed replica by replica. For example Figure 13B As shown, when upgrading the replica R-0, the upgrade of the replica R-1 is paused to improve the upgrade speed of the replica.
[0357] As can be seen from the above, in the embodiment of the present application, as long as the Pod name and the size of the segment (interval, slots) are known, the shard and replica to which the Pod belongs can be calculated, without explicitly maintaining the mapping table between the Pod and the shard, thereby improving the management effect of the stateful service.
[0358] In some embodiments, for each description in the configuration change information, there are the following constraints: The Pod in `primedReplicas` must exist, and a Pod cannot be in both `suppressions (deletion)` and `primedReplicas` at the same time; The `slots` and `interval` fields are read-only and cannot be modified after creation; `extras`, `suppressions`, and `primedReplicas` can only operate on Pods within the `shards` range, and cannot add shards through `extras` or reduce shards through `suppressions`; If `suppressions` specifies the deletion of all Pods (including the Pods specified by `extras`), it will be converted to `replicas:0`, and `extras:[]` will be cleared.
[0359] As can be seen from the above, the control method of the stateful service provided by the embodiment of the present application can realize stable and unique IDs and network IDs, group Pods by shard / replica, arbitrarily add or delete specified Pods, non-peer Pod configurations, and stable changes, thereby realizing the effective management of the stateful service.
[0360] The management method of the stateful service provided by the embodiment of the present application groups the Pods corresponding to the stateful service according to the Pod sharding information and the Pod replica information, determines the Pod naming range corresponding to each shard, and then names the Pods under each replica in the shard within the Pod naming range corresponding to the shard, so that the Pod naming is combined with the sharding information and replica information where the Pod is located. In this way, the configuration change information corresponding to the stateful service can be obtained subsequently, and based on the Pod naming to be changed indicated by the configuration change information, the shard and replica where the Pod to be changed is located can be determined, and then the Pods under the shard and replica can be changed (such as adding, deleting or updating, etc.). Furthermore, independent operations can be performed on the Pods under any replica in any shard based on the Pod naming, which fully enhances the management of the stateful service in the cloud native scenario and can help the stateful services such as databases, middleware, and consensus systems to be smoothly and stably containerized.
[0361] As described above in conjunction with Figures 4 to 13B , the embodiment of the management method of the stateful service of the present application is described in detail. Below in conjunction with Figure 14 , the device embodiment of the present application is described in detail.
[0362] Figure 14 FIG. is a schematic block diagram of a management device for a stateful service provided by an embodiment of the present application. The device 10 may be the above-mentioned Pod controller or a part of the Pod controller.
[0363] As Figure 14 shown, the management device 10 for the stateful service includes:
[0364] An obtaining unit 11, configured to obtain initial configuration information corresponding to the stateful service, where the initial configuration information includes Pod sharding information and Pod replica information;
[0365] A creating unit 12, configured to determine N shards corresponding to the stateful service based on the Pod sharding information and the Pod replica information, and create a corresponding number of Pods under each replica of each shard, where N is a positive integer;
[0366] An interval determining unit 13, configured to determine the Pod naming range corresponding to each of the N shards based on the Pod sharding information and the Pod replica information;
[0367] A naming unit 14, configured to, for the i-th shard among the N shards, determine the naming of each Pod under each replica in the i-th shard within the Pod naming range corresponding to the i-th shard, where i is a positive integer less than or equal to N.
[0368] In some embodiments, the Pod shard information further includes a preset number of shards and the maximum number of replicas included in each shard, and the Pod replica information includes the maximum number of co-existing Pods in each replica; the interval determination unit 13 is specifically configured to, for the i-th shard, determine the index of the i-th shard among the N shards based on the preset number of shards; and determine the Pod naming interval corresponding to the i-th shard based on the index of the i-th shard among the N shards, the maximum number of replicas included in each shard, and the maximum number of co-existing Pods in each replica.
[0369] In some embodiments, the interval determination unit 13 is specifically configured to determine the length of the Pod naming interval corresponding to each of the N shards based on the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica; and determine the Pod naming interval corresponding to the i-th shard based on the length of the Pod naming interval and the index of the i-th shard among the N shards.
[0370] In some embodiments, the interval determination unit 13 is specifically configured to determine the starting value of the Pod naming interval corresponding to the i-th shard as the product of the length of the Pod naming interval and the index of the i-th shard among the N shards; and determine the ending value of the Pod naming interval corresponding to the i-th shard as the value obtained by subtracting 1 from the sum of the starting point of the Pod naming interval corresponding to the i-th shard and the length of the Pod naming interval.
[0371] In some embodiments, the naming unit 14 is specifically configured to, for the j-th Pod in the i-th shard, determine the replica index of the k-th replica where the j-th Pod is located among the replicas in the i-th shard, where both k and j are positive integers; and determine the name of the j-th Pod based on the replica index of the k-th replica and the Pod naming interval corresponding to the i-th shard.
[0372] In some embodiments, the naming unit 14 is specifically configured to multiply the replica index of the k-th replica by the maximum number of co-existing Pods in each replica to obtain a first product; determine the name of the first Pod in the k-th replica as the sum of the starting value of the Pod naming interval corresponding to the i-th shard and the first product; and determine the name of the j-th Pod based on the index of the j-th Pod in the k-th replica and the name of the first Pod in the k-th replica.
[0373] In some embodiments, the naming unit 14 is specifically configured to, if the j-th Pod is the first Pod in the k-th replica, determine the name of the first Pod as the name of the j-th Pod; if the j-th Pod is not the first Pod in the k-th replica, determine the sum of the index of the j-th Pod in the k-th replica and the name of the first Pod as the name of the j-th Pod.
[0374] In some embodiments, after determining the names of the Pods under each replica of the i-th shard within the Pod naming range corresponding to the i-th shard, the naming unit 14 is further configured to obtain the configuration change information corresponding to the stateful service, where the configuration change information includes at least one of Pod addition indication information, Pod deletion indication information, Pod template update indication information, and replica rolling upgrade indication information; and change the current Pod information corresponding to the stateful service based on the configuration change information.
[0375] In some embodiments, when the configuration change information includes the Pod addition indication information, the naming unit 14 is specifically configured to determine the names of M first Pods to be added based on the Pod addition indication information, where M is a positive integer; for each of the M first Pods, determine the first shard and the first replica where the first Pod is located based on the name of the first Pod; and add the first Pod in the first replica under the first shard.
[0376] In some embodiments, when the configuration change information includes the Pod deletion indication information, the naming unit 14 is specifically configured to determine the names of K second Pods to be deleted based on the Pod deletion indication information, where K is a positive integer; for each of the K second Pods, determine the second shard and the second replica where the second Pod is located based on the name of the second Pod; and delete the second Pod under the second replica in the second shard.
[0377] In some embodiments, when the configuration change information includes the Pod addition indication information and the Pod deletion indication information, and the first Pod to be added indicated by the Pod addition indication information is the same as the second Pod to be deleted indicated by the Pod deletion indication information, the step of adding the first Pod is skipped.
[0378] In some embodiments, when the configuration change information includes the Pod template update indication information, the naming unit 14 is specifically configured to, based on the Pod template update indication information, determine the naming of P third Pods whose templates are to be changed and the template configuration adjustment information corresponding to each of the P third Pods, where P is a positive integer; for each of the P third Pods, based on the naming of the third Pod, determine the third shard and the third replica where the third Pod is located; based on the template configuration adjustment information corresponding to the third Pod, adjust the template configuration of the third Pod in the third replica under the third shard, where the template configurations of the Pods corresponding to the stateful service are not completely the same.
[0379] In some embodiments, when the configuration change information includes the replica rolling upgrade indication information, the naming unit 14 is specifically configured to, based on the replica rolling upgrade indication information, determine the naming of Q fourth Pods to be upgraded, where Q is a positive integer; for each of the Q fourth Pods, based on the naming of the fourth Pod, determine the fourth shard and the fourth replica where the fourth Pod is located; create the fourth Pod under the fourth replica in the fourth shard, and after the creation of the fourth Pod is successful, delete the old Pod under the fourth replica in the fourth shard.
[0380] In some embodiments, the naming unit 14 is specifically configured to obtain the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica; based on the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica, determine the length of the Pod naming interval corresponding to each shard; based on the naming of the Pod and the length of the Pod naming interval, determine the shard where the Pod is located; based on the naming of the Pod, the length of the Pod naming interval, and the maximum number of co-existing Pods in each replica, determine the replica where the Pod is located; where, if the Pod is the first Pod, the shard where the Pod is located is the first shard and the replica where the Pod is located is the first replica, if the Pod is the second Pod, the shard where the Pod is located is the second shard and the replica where the Pod is located is the second replica, if the Pod is the third Pod, the shard where the Pod is located is the third shard and the replica where the Pod is located is the third replica, if the Pod is the fourth Pod, the shard where the Pod is located is the fourth shard and the replica where the Pod is located is the fourth replica.
[0381] In some embodiments, the naming unit 14 is specifically configured to round down the quotient of the naming of the Pod and the length of the Pod naming interval to obtain the shard where the Pod is located.
[0382] In some embodiments, the naming unit 14 is specifically configured to perform a modulo operation on the naming of the Pod and the length of the Pod naming range to obtain a remainder; perform a floor operation on the quotient of the remainder and the maximum number of co-existing Pods in each replica to obtain the replica where the Pod is located.
[0383] It should be understood that the device embodiments and the method embodiments can correspond to each other, and similar descriptions can refer to the method embodiments. To avoid repetition, it will not be elaborated here. Specifically, Figure 14 The device shown can execute the embodiments of the above method, and the foregoing and other operations and / or functions of each module in the device are respectively for implementing the method embodiments. For the sake of brevity, it will not be elaborated here.
[0384] The device of the embodiments of the present application has been described above from the perspective of functional modules in conjunction with the drawings. It should be understood that the functional modules can be implemented in the form of hardware, or in the form of instructions in software, or in a combination of hardware and software modules. Specifically, the steps of the method embodiments in the present application can be completed by the integrated logic circuit in the hardware in the processor and / or instructions in software. The steps of the method disclosed in conjunction with the embodiments of the present application can be directly embodied as being executed and completed by the hardware decoding processor, or executed and completed by a combination of the hardware and software modules in the decoding processor. Optionally, the software module can be located in a mature storage medium in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, an electrically erasable programmable memory, a register, etc. This storage medium is located in the memory, and the processor reads the information in the memory and combines its hardware to complete the steps in the above method embodiments.
[0385] Figure 15 is a schematic block diagram of an electronic device provided by an embodiment of the present application, Figure 15 The electronic device can be the above-mentioned working node.
[0386] Such as Figure 15 shown, the electronic device 30 may include:
[0387] A memory 31 and a processor 32. The memory 31 is used to store a computer program 33 and transmit the program code 33 to the processor 32. In other words, the processor 32 can call and run the computer program 33 from the memory 31 to implement the method in the embodiments of the present application.
[0388] For example, the processor 32 can be used to execute the steps in the above method according to the instructions in the computer program 33.
[0389] In some embodiments of the present application, the processor 32 may include, but is not limited to:
[0390] General-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field programmable gate arrays (FPGAs) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, and the like.
[0391] In some embodiments of the present application, the memory 31 includes, but is not limited to:
[0392] Volatile memory and / or non-volatile memory. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable ROM (PROM), an erasable programmable ROM (EPROM), an electrically erasable programmable ROM (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate synchronous DRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synch link DRAM (SLDRAM), and direct rambus RAM (DR RAM).
[0393] In some embodiments of the present application, the computer program 33 may be divided into one or more modules, which are stored in the memory 31 and executed by the processor 32 to complete the method for recording a page provided by the present application. The one or more modules may be a series of computer program instruction segments capable of performing specific functions, and the instruction segments are used to describe the execution process of the computer program 33 in the electronic device.
[0394] As Figure 15 shown, the electronic device 30 may further include:
[0395] A transceiver 34, which can be connected to the processor 32 or the memory 31.
[0396] Among them, the processor 32 can control the transceiver 34 to communicate with other devices. Specifically, it can send information or data to other devices, or receive information or data sent by other devices. The transceiver 34 can include a transmitter and a receiver. The transceiver 34 can further include an antenna, and the number of antennas can be one or more.
[0397] It should be understood that each component in the electronic device 30 is connected through a bus system. Among them, the bus system includes not only a data bus, but also a power bus, a control bus, and a status signal bus.
[0398] According to one aspect of the present application, a computer storage medium is provided, on which a computer program is stored. When the computer program is executed by the computer, the computer can execute the method of the above method embodiment. Or rather, the embodiment of the present application further provides a computer program product containing instructions. When the instructions are executed by the computer, the computer executes the method of the above method embodiment.
[0399] According to another aspect of the present application, a computer program product or a computer program is provided. The computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method of the above method embodiment.
[0400] In other words, when implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions according to the embodiments of this application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center in a wired manner (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or a wireless manner (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more integrated available media. The available medium can be a magnetic medium (such as a floppy disk, hard disk, magnetic tape), an optical medium (such as a digital video disc (DVD)), or a semiconductor medium (such as a solid-state disk (SSD)), etc.
[0401] Those of ordinary skill in the art will realize that the modules and algorithm steps of the examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or in a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.
[0402] In several embodiments provided in this application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the modules is only a logical function division, and there can be other division methods in actual implementation. For example, multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces, and the indirect couplings or communication connections of devices or modules can be in an electrical, mechanical, or other form.
[0403] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. For example, in each embodiment of this application, each functional module can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module.
[0404] The above content is only the specific implementation manner of this application, but the protection scope of this application is not limited thereto. Any person skilled in the art within the technical scope disclosed by this application can easily think of changes or substitutions, which should all be covered within the protection scope of this application. Therefore, the protection scope of this application should be subject to the protection scope of the claims.
Claims
1. A management method for stateful services, characterized in that, Including: Obtain the initial configuration information corresponding to the stateful service, where the initial configuration information includes Pod sharding information and Pod replica information; Based on the Pod sharding information and the Pod replica information, determine N shards corresponding to the stateful service, and create corresponding numbers of Pods under each replica of each shard, where N is a positive integer; Based on the Pod sharding information and the Pod replica information, determine the Pod naming range corresponding to each of the N shards; For the i-th shard among the N shards, within the Pod naming range corresponding to the i-th shard, determine the names of the Pods under each replica in the i-th shard, where i is a positive integer less than or equal to N.
2. The method according to claim 1, wherein The Pod sharding information further includes a preset number of shards and the maximum number of replicas included in each shard, and the Pod replica information includes the maximum number of co-existing Pods in each replica; The determining the Pod naming range corresponding to each of the N shards based on the Pod sharding information and the Pod replica information includes: For the i-th shard, based on the preset number of shards, determine the index of the i-th shard among the N shards; Based on the index of the i-th shard among the N shards, the maximum number of replicas included in each shard, and the maximum number of co-existing Pods in each replica, determine the Pod naming range corresponding to the i-th shard.
3. The method according to claim 2, wherein The determining the Pod naming range corresponding to the i-th shard based on the index of the i-th shard among the N shards, the maximum number of replicas included in each shard, and the maximum number of co-existing Pods in each replica includes: Based on the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica, determine the length of the Pod naming range corresponding to each of the N shards; Based on the length of the Pod naming range and the index of the i-th shard among the N shards, determine the Pod naming range corresponding to the i-th shard.
4. The method according to claim 3, characterized in that, The determining the Pod naming range corresponding to the i-th shard based on the length of the Pod naming range and the index of the i-th shard among the N shards includes: Determine the starting value of the Pod naming range corresponding to the i-th shard as the product of the length of the Pod naming range and the index of the i-th shard among the N shards; Determine the ending value of the Pod naming range corresponding to the i-th shard as the value obtained by adding 1 to the sum of the starting point of the Pod naming range corresponding to the i-th shard and the length of the Pod naming range.
5. The method according to claim 2, wherein The determining the names of the Pods under each replica in the i-th shard within the Pod naming range corresponding to the i-th shard includes: For the j-th Pod in the i-th shard, determine the replica index of the k-th replica where the j-th Pod is located among the replicas in the i-th shard, where both k and j are positive integers; Determine the name of the \(j\)th Pod based on the replica index of the \(k\)th replica and the Pod naming range corresponding to the \(i\)th shard.
6. The method according to claim 5, wherein The determining the name of the \(j\)th Pod based on the replica index of the \(k\)th replica and the Pod naming range corresponding to the \(i\)th shard includes: Multiply the replica index of the \(k\)th replica by the maximum number of co-existing Pods in each replica to obtain a first product; Determine the name of the first Pod in the \(k\)th replica as the sum of the starting value of the Pod naming range corresponding to the \(i\)th shard and the first product; Determine the name of the \(j\)th Pod based on the index of the \(j\)th Pod in the \(k\)th replica and the name of the first Pod in the \(k\)th replica.
7. The method according to claim 6, wherein The determining the name of the \(j\)th Pod based on the index of the \(j\)th Pod in the \(k\)th replica and the name of the first Pod in the \(k\)th replica includes: If the \(j\)th Pod is the first Pod in the \(k\)th replica, then determine the name of the first Pod as the name of the \(j\)th Pod; If the \(j\)th Pod is not the first Pod in the \(k\)th replica, then determine the sum of the index of the \(j\)th Pod in the \(k\)th replica and the name of the first Pod as the name of the \(j\)th Pod.
8. The method according to any one of claims 1-7, characterized in that, After determining the names of the Pods under each replica in the \(i\)th shard within the Pod naming range corresponding to the \(i\)th shard, the method further includes: Obtain the configuration change information corresponding to the stateful service, where the configuration change information includes at least one of Pod addition indication information, Pod deletion indication information, Pod template update indication information, and replica rolling upgrade indication information; Based on the configuration change information, change the Pod information currently corresponding to the stateful service.
9. The method according to claim 8, wherein If the configuration change information includes the Pod addition indication information, then the changing the Pod information currently corresponding to the stateful service based on the configuration change information includes: Based on the Pod addition indication information, determine the names of \(M\) first Pods to be added, where \(M\) is a positive integer; For each of the \(M\) first Pods, determine the first shard and the first replica where the first Pod is located based on the name of the first Pod; Add the first Pod in the first replica under the first shard.
10. The method according to claim 8, characterized in that If the configuration change information includes the Pod deletion indication information, then the changing the Pod information currently corresponding to the stateful service based on the configuration change information includes: Based on the Pod deletion indication information, determine the names of \(K\) second Pods to be deleted, where \(K\) is a positive integer; For each of the \(K\) second Pods, determine the second shard and the second replica where the second Pod is located based on the name of the second Pod; Delete the second Pod under the second replica in the second shard.
11. The method according to claim 8, wherein If the configuration change information includes the Pod addition indication information and the Pod deletion indication information, and the first Pod to be added indicated by the Pod addition indication information is the same Pod as the second Pod to be deleted indicated by the Pod deletion indication information, then skip the step of adding the first Pod.
12. The method according to claim 8, characterized in that, If the configuration change information includes the Pod template update indication information, then changing the Pod information currently corresponding to the stateful service based on the configuration change information includes: Based on the Pod template update indication information, determining the names of P third Pods whose templates are to be changed and the template configuration adjustment information corresponding to each of the P third Pods, where P is a positive integer; For each of the P third Pods, determining the third shard and the third replica where the third Pod is located based on the name of the third Pod; Adjusting the template configuration of the third Pod in the third replica under the third shard based on the template configuration adjustment information corresponding to the third Pod, where the template configurations of the Pods corresponding to the stateful service are not completely the same.
13. The method according to claim 8, characterized in that, If the configuration change information includes the replica rolling upgrade indication information, then changing the Pod information currently corresponding to the stateful service based on the configuration change information includes: Based on the replica rolling upgrade indication information, determining the names of Q fourth Pods to be upgraded, where Q is a positive integer; For each of the Q fourth Pods, determining the fourth shard and the fourth replica where the fourth Pod is located based on the name of the fourth Pod; Creating the fourth Pod under the fourth replica in the fourth shard, and after the successful creation of the fourth Pod, deleting the old Pod under the fourth replica in the fourth shard.
14. The method according to any one of claims 9, 10, 12 and 13, characterized in that Determining the shard and replica where the Pod is located based on the name of the Pod includes: Obtaining the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica; Based on the maximum number of replicas included in each shard and the maximum number of co-existing Pods in each replica, determining the length of the Pod naming interval corresponding to each shard; Based on the name of the Pod and the length of the Pod naming interval, determining the shard where the Pod is located; Based on the name of the Pod, the length of the Pod naming interval, and the maximum number of co-existing Pods in each replica, determining the replica where the Pod is located. Among them, if the Pod is the first Pod, the shard where the Pod is located is the first shard, and the replica where the Pod is located is the first replica; if the Pod is the second Pod, the shard where the Pod is located is the second shard, and the replica where the Pod is located is the second replica; if the Pod is the third Pod, the shard where the Pod is located is the third shard, and the replica where the Pod is located is the third replica; if the Pod is the fourth Pod, the shard where the Pod is located is the fourth shard, and the replica where the Pod is located is the fourth replica.
15. The method according to claim 14, wherein Determining the shard where the Pod is located based on the name of the Pod and the length of the Pod naming range includes: Rounding down the quotient of the name of the Pod and the length of the Pod naming range to obtain the shard where the Pod is located.
16. The method according to claim 14, characterized in that, Determining the replica where the Pod is located based on the name of the Pod, the length of the Pod naming range, and the maximum number of Pods coexisting in each replica includes: Performing a modulo operation on the name of the Pod and the length of the Pod naming range to obtain a remainder; Rounding down the quotient of the remainder and the maximum number of Pods coexisting in each replica to obtain the replica where the Pod is located.
17. A management device for a stateful service, characterized in that, Including: An acquisition unit for acquiring initial configuration information corresponding to a stateful service, where the initial configuration information includes Pod shard information and Pod replica information; A creation unit for determining N shards corresponding to the stateful service based on the Pod shard information and the Pod replica information, and creating corresponding numbers of Pods under each replica of each shard, where N is a positive integer; An interval determination unit for determining a Pod naming range corresponding to each shard among the N shards based on the Pod shard information and the Pod replica information; A naming unit for determining the names of the Pods under each replica in the i-th shard among the N shards within the Pod naming range corresponding to the i-th shard, where i is a positive integer less than or equal to N.
18. An electronic device, including a processor and a memory; The memory is used for storing a computer program; The processor is used for executing the computer program to implement the method according to any one of claims 1 to 16 above.
19. A computer-readable storage medium, characterized in that, For storing a computer program; The computer program causes the computer to execute the method according to any one of claims 1 to 16 above.