Stateless access method and server based on k8s cluster
By deploying redundant PODs in the Kubernetes cluster and implementing data synchronization and request forwarding, the problem of stateful applications being unable to scale horizontally is solved, improving the reliability and availability of the system and making it appear stateless to the outside world.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SUPCON TECH CO LTD
- Filing Date
- 2024-12-13
- Publication Date
- 2026-05-01
AI Technical Summary
In a Kubernetes cluster, stateful applications cannot easily achieve 1:1 redundancy, cannot be easily scaled horizontally, and cannot appear stateless to the outside world, resulting in insufficient system reliability and availability.
By deploying redundant PODs in a Kubernetes cluster, the primary POD and the backup POD are configured with their own internal services to communicate with each other. The primary POD processes business requests and synchronizes status data to the backup POD, thereby achieving data synchronization and request forwarding and ensuring data consistency between the backup POD and the primary POD.
It implements redundancy for stateful PODs in the Kubernetes cluster, making them appear stateless to the outside world, supporting horizontal scaling and 1:1 redundancy, and improving the reliability and availability of the system.
Smart Images

Figure CN119718543B_ABST
Abstract
Description
Stateless access method and server based on Kubernetes cluster Technical Field
[0001] This application relates to the field of computer technology, and in particular to a stateless access method and server based on a K8s cluster. Background Technology
[0002] In cluster deployment, Kubernetes clusters provide container orchestration technology. The basic deployment unit of a Kubernetes cluster is called a POD, which can contain one or more containers. These containers share network, storage, and configuration, and can be scheduled and managed together, thereby enabling rapid cloud-based cluster deployment of applications.
[0003] Since the application's business logic determines whether the container is stateful, stateful applications typically cannot perform simple horizontal scaling and cannot easily achieve 1:1 redundancy. Only stateless applications can easily achieve horizontal scaling and naturally support 1:1 redundancy. Summary of the Invention
[0004] This application provides a stateless access method and server based on a K8s cluster, with the aim of making the two redundant stateful Pods corresponding to the application appear stateless to the outside world.
[0005] To achieve the above objectives, this application provides the following technical solution:
[0006] A stateless access method based on a Kubernetes cluster is applicable to systems deploying redundant Points of Data (PODs). The redundant PODs include a primary POD and a backup POD. Each primary POD and the backup POD is configured with an internal service for communication interconnection. The system is configured with an external service for providing external access. The method includes:
[0007] Obtain the business request sent by the upper-layer application to the external service;
[0008] When the business request is routed to the main POD by the external service, the business request is processed by the main POD to obtain the corresponding processing result, and the processing result is sent to the upper layer application;
[0009] When the primary POD generates status data, it sends the status data to the internal service of the backup POD through the internal service of the primary POD, so that the backup POD can obtain the status data and realize data synchronization between the backup POD and the primary POD; the status data includes the processing result obtained by the primary POD in processing the business request.
[0010] Optionally, the method further includes:
[0011] When the service request is routed to the backup POD by the external service, the service request is sent to the internal service of the primary POD through the internal service of the backup POD, so that the primary POD can obtain the service request and realize request forwarding between the backup POD and the primary POD.
[0012] Optionally, the deployment process of the redundant POD includes:
[0013] Obtain redundant configuration information input by the user; the redundant configuration information includes the pairing relationship between the first POD and the second POD, as well as the respective services of the first POD and the second POD;
[0014] Based on the services of the first POD and the second POD respectively, establish a communication connection between the first POD and the second POD;
[0015] One of the first POD and the second POD is initialized as the primary POD, and the other is initialized as the backup POD, so as to complete the deployment of the redundant POD.
[0016] Optionally, both the first POD and the second POD are stateful PODs and belong to the same application.
[0017] A server, wherein the operating system of the server is a Kubernetes cluster deploying redundant Points of Data (PODs), the redundant PODs including a primary POD and a backup POD, each of the primary POD and the backup POD being configured with internal services for communication interconnection, and the Kubernetes cluster providing external services for external access, including:
[0018] The request receiving unit is used to obtain the business request sent by the upper-layer application to the external service;
[0019] The request processing unit is used to process the business request through the main POD when the business request is routed to the main POD by the external service, so as to obtain the corresponding processing result and send the processing result to the upper layer application.
[0020] The data synchronization unit is used to send the status data to the internal service of the backup POD through the internal service of the primary POD when the primary POD generates status data, so that the backup POD can obtain the status data and realize data synchronization between the backup POD and the primary POD; the status data includes the processing result obtained by the primary POD from processing the service request.
[0021] Optionally, the server further includes:
[0022] The request forwarding unit is used to send the service request to the internal service of the primary POD through the internal service of the backup POD when the service request is routed to the backup POD by the external service, so that the primary POD can obtain the service request and realize request forwarding between the backup POD and the primary POD.
[0023] Optionally, the server further includes:
[0024] A redundancy deployment unit is configured to: obtain redundancy configuration information input by the user; the redundancy configuration information includes the pairing relationship between the first POD and the second POD, and the respective services of the first POD and the second POD; establish a communication connection between the first POD and the second POD based on the respective services of the first POD and the second POD; initialize one of the first POD and the second POD as the primary POD, and initialize the other as the backup POD, to complete the deployment of the redundant POD.
[0025] Optionally, both the first POD and the second POD are stateful PODs and belong to the same application.
[0026] A storage medium comprising a stored program, wherein the program is executed by a processor to perform the stateless access method based on a Kubernetes cluster.
[0027] An electronic device includes: a processor, a memory, and a bus; the processor and the memory are connected via the bus.
[0028] The memory is used to store the program, and the processor is used to run the program, wherein the program is executed by the processor to perform the stateless access method based on the Kubernetes cluster.
[0029] The technical solution provided in this application obtains business requests sent by the upper-layer application to an external service. When a business request is routed to the primary POD by the external service, the primary POD processes the request to obtain the corresponding processing result and sends the result back to the upper-layer application. When the primary POD generates state data, it sends the state data to the internal service of the backup POD through the internal service of the primary POD, enabling the backup POD to obtain the state data and achieve data synchronization between the backup POD and the primary POD. This application enables two stateful PODs in a Kubernetes cluster to have redundant functions such as mutual communication, request forwarding, and data synchronization, thereby realizing two redundant stateful PODs that appear stateless to the outside world. Attached Figure Description
[0030] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0031] Figure 1 is a flowchart illustrating a stateless access method based on a K8s cluster provided in an embodiment of this application;
[0032] Figure 2 is a flowchart illustrating a redundant POD deployment method provided in an embodiment of this application;
[0033] Figure 3 is a schematic diagram of data synchronization provided in an embodiment of this application;
[0034] Figure 4 is a schematic diagram of a request forwarding provided in an embodiment of this application;
[0035] Figure 5 is a schematic diagram of the architecture of a server provided in an embodiment of this application. Detailed Implementation
[0036] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0037] In this application, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. The terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0038] The technical terms mentioned in the embodiments of this application can be explained in the following explanations.
[0039] Kubernetes (K8s) is an open-source container orchestration platform used to automate the deployment, scaling, and management of containerized applications. K8s simplifies container management by providing services such as discovery, load balancing, rolling updates, and automatic fault recovery.
[0040] Cluster: refers to a combination of multiple computers (nodes) to provide greater processing power and higher availability. In a Kubernetes cluster, the cluster consists of multiple nodes, including master nodes and worker nodes.
[0041] Stateful: refers to the ability of an application to save its state information (such as user data, session information, etc.) and to recover this state after restarting or failure.
[0042] Stateless: This means that the application does not store any state information. Each request is independent, and the server does not need to know the previous state when processing the request. Stateless applications can be easily scaled and restarted.
[0043] POD: The basic deployment unit in Kubernetes, which can contain one or more containers that share network, storage, and configuration and can be scheduled and managed together.
[0044] Redundancy: refers to improving the reliability and availability of a system by adding extra components (such as servers, nodes, or replicas). If one component fails, redundancy can ensure that the system continues to operate normally.
[0045] Service: In Kubernetes, a Service is an abstraction that defines a set of access policies for Devices within a cluster (PODs). A Service allows PODs in the cluster to be accessed through a fixed IP address and port number, regardless of the POD's lifecycle. Kubernetes provides several types of Services: Cluster IP, Node Port, Load Balance, and ExternalName.
[0046] Cluster IP: The default type, accessible only within the cluster, i.e., used for communication between PODs.
[0047] Node Port: Open a specific port on each node so that external traffic can access it.
[0048] Load Balance: Automatically creates an external load balancer in the cloud environment to distribute traffic to the corresponding POD.
[0049] External Name: Maps the service to an external domain name system name.
[0050] ConfigMAP is a resource in Kubernetes used to store non-confidential configuration information for use in PODs. It allows users to separate configuration information from the container image, enabling flexible modification of application configurations without rebuilding the image.
[0051] Figure 1 shows a flowchart of a stateless access method based on a K8s cluster provided in an embodiment of this application. This method is applicable to systems that deploy redundant PODs. The redundant PODs include a primary POD and a backup POD. The primary POD and the backup POD are each configured with an internal service for communication interconnection. The system is configured with an external service for providing external access, including the following steps.
[0052] S101: Obtain the business request sent by the upper-layer application to the external service.
[0053] Among them, upper-layer applications include, but are not limited to, browsers, i.e., browsers sending business requests to external services of the system.
[0054] In some examples, the type of external service can be Load Balancer.
[0055] S102: When a business request is routed to the main POD by an external service, the main POD processes the business request to obtain the corresponding processing result and sends the processing result to the upper-layer application.
[0056] For upper-layer applications (such as browsers), an external service can be considered a unique virtual IP address. This external service corresponds to two different services (i.e., a primary POD and a backup POD), and can therefore randomly route requests to either the primary or backup POD. Generally speaking, if the node corresponding to either the primary or backup POD goes offline, the external service will automatically route business requests to the other node.
[0057] Optionally, when a business request is routed to the backup POD by an external service, the business request is sent to the internal service of the primary POD through the internal service of the backup POD, so that the primary POD can obtain the business request and realize request forwarding between the backup POD and the primary POD.
[0058] In some examples, the type of the internal service can be Cluster IP.
[0059] It is understandable that the primary POD and the backup POD communicate with each other through their respective internal services. Therefore, the backup POD can forward business requests to the primary POD.
[0060] S103: When the primary POD generates status data, it sends the status data to the backup POD's internal service through the primary POD's internal service, so that the backup POD can obtain the status data and realize data synchronization between the backup POD and the primary POD.
[0061] The status data includes the processing results obtained by the main POD from processing business requests.
[0062] It should be noted that, based on the system shown in the embodiments of this application, mutual communication and data synchronization between two PODs are performed, so that the two originally redundant stateful PODs can be exposed to the outside world in a stateless manner through an external service, thereby easily realizing redundant functions such as inter-application interconnection, request forwarding, and data synchronization.
[0063] Optionally, the process of deploying redundant PODs on the system can be found in the steps shown in Figure 2 and the corresponding explanations.
[0064] In some examples, for a scenario where a browser accesses application A, the external service corresponding to application A is service-A, and the redundant PODs corresponding to application A include POD-A1 and POD-A2. The internal service of POD-A1 is service-A1, and the internal service of POD-A2 is service-A2. POD-A1 is the primary POD, and POD-A2 is the backup POD. The data synchronization scenario between POD-A1 and POD-A2 when a business request is forwarded from service-A to POD-A1 is shown in Figure 3. The request forwarding scenario between POD-A1 and POD-A2 when a business request is forwarded from service-A to POD-A2 is shown in Figure 4.
[0065] In other words, when a business request is sent to POD-A2, POD-A2 forwards the request to POD-A1 for processing. After POD-A1 completes its processing, POD-A2 returns the result to the requester. When POD-A1 generates state data, it transmits this data to POD-A2 via a synchronization channel, ensuring data synchronization between POD-A2 and POD-A1. Furthermore, when a business request is sent to POD-A1, POD-A1 processes it directly and returns the result to the upper-layer application, synchronizing the result with POD-A2. Subsequent business requests to POD-A2 will retain the state established after the last request to POD-A1. Thus, regardless of whether the upper-layer application accesses POD-A1 or POD-A2, it will receive the same result, achieving stateless access to the outside world.
[0066] The processes shown in S101-S103 above enable two stateful PODs in a K8s cluster to have redundant functions such as mutual communication, request forwarding, and data synchronization, thereby realizing that the two redundant stateful PODs appear to be stateless to the outside world.
[0067] Figure 2 shows a flowchart of a redundant POD deployment method provided in an embodiment of this application, which includes the following steps.
[0068] S201: Obtain redundant configuration information input by the user.
[0069] The redundancy configuration information includes the pairing relationship between the first POD and the second POD, as well as the respective services of the first POD and the second POD.
[0070] Optionally, both the first POD and the second POD are stateful PODs and belong to the same application.
[0071] In some examples, the type of redundant configuration information can be a ConfigMAP. In a possible implementation, for redundant PODs for two applications, the corresponding ConfigMAP can be "name:A1;redu:A2;ip:192.168.1.1;name:A2;redu:A1;ip:192.168.1.2;name:B1;redu:B2;value:192.168.2.1;name:B2;redu:B1;value:192.168.2.2". Specifically, in the ConfigMAP shown, the redundant PODs corresponding to application A include POD-A1 and POD-A2, and the redundant PODs corresponding to application B include POD-B1 and POD-B2.
[0072] In a possible implementation, the external service corresponding to application A is service-A, and the external service corresponding to application B is service-B. Upper-layer applications can access POD-A1 or POD-A2 through service-A, and can access POD-B1 or POD-B2 through service-B.
[0073] In a possible implementation, the internal service of POD-A1 is service-A1, the internal service of POD-A2 is service-A2, the internal service of POD-B1 is service-B1, and the internal service of POD-B2 is service-B2.
[0074] S202: Based on the services of the first POD and the second POD respectively, establish a communication connection between the first POD and the second POD.
[0075] The service type of the first POD and the second POD can be Cluster IP.
[0076] In some examples, POD-A1 and POD-A2 can establish a communication connection through service-A1 and service-A2, and POD-B1 and POD-B2 can establish a communication connection through service-B1 and service-B2.
[0077] S203: Based on one of the first POD and the second POD, initialize the primary POD and the other as the backup POD to complete the deployment of redundant PODs.
[0078] After initializing the primary POD and the backup POD, the redundancy function of the system can be realized through the primary POD and the backup POD.
[0079] The processes described in S201-S203 above can successfully deploy the redundant POD corresponding to the application on the system.
[0080] Figure 5 shows a schematic diagram of the architecture of a server provided in an embodiment of this application. The operating system of the server is a K8s cluster with redundant PODs deployed. The redundant PODs include a primary POD and a backup POD. The primary POD and the backup POD are each configured with internal services for communication interconnection. The K8s cluster provides external services for external access. The server includes the following units.
[0081] The request receiving unit 100 is used to obtain business requests sent by the upper-layer application to the external service.
[0082] The request processing unit 200 is used to process business requests through the main POD when a business request is routed to the main POD by an external service, obtain the corresponding processing result, and send the processing result to the upper layer application.
[0083] The data synchronization unit 300 is used to send the status data to the internal service of the backup POD through the internal service of the primary POD when the primary POD generates status data, so that the backup POD can obtain the status data and realize data synchronization between the backup POD and the primary POD; the status data includes the processing results obtained by the primary POD from processing business requests.
[0084] The request forwarding unit 400 is used to forward the business request to the internal service of the primary POD through the internal service of the secondary POD when the business request is routed to the secondary POD by the external service, so that the primary POD can obtain the business request and realize the request forwarding between the secondary POD and the primary POD.
[0085] The redundant deployment unit 500 is used to: obtain redundant configuration information input by the user; the redundant configuration information includes the pairing relationship between the first POD and the second POD, and the services of the first POD and the second POD respectively; establish a communication connection between the first POD and the second POD based on the services of the first POD and the second POD respectively; initialize one of the first POD and the second POD as the primary POD, and initialize the other as the backup POD, so as to complete the deployment of the redundant POD.
[0086] Optionally, both the first POD and the second POD are stateful PODs and belong to the same application.
[0087] The units shown above enable two stateful PODs in a Kubernetes cluster to have redundant functions such as mutual communication, request forwarding, and data synchronization, thereby realizing two redundant stateful PODs that appear stateless to the outside world.
[0088] This application also provides a computer-readable storage medium including a stored program, wherein the program executes the method provided in this application described above.
[0089] This application also provides an electronic device, including a processor, a memory, and a bus. The processor and the memory are connected via the bus. The memory is used to store a program, and the processor is used to run the program, wherein the program executes the method provided in this application as described above.
[0090] Furthermore, the functions described above in the embodiments of this application can be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that can be used include: Field Programmable Gate Arrays (FPGAs), Application-Specific Integrated Circuits (ASICs), Application Standard Products (ASSPs), System-on-Chip (SOCs), Complex Programmable Logic Devices (CPLDs), and so on.
[0091] While several specific implementation details are included in the foregoing discussion, these should not be construed as limiting the scope of this application. Certain features described in the context of individual embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.
[0092] The above description is merely a preferred embodiment of this application and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of disclosure in this application is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions disclosed in this application.
Claims
1. A stateless access method based on a Kubernetes cluster, characterized in that, A system for deploying redundant Points of Data (PODs) is provided. The redundant PODs include a primary POD and a backup POD. Each primary POD and backup POD is configured with an internal service for communication interconnection. The system is configured with an external service for providing external access. The method includes: obtaining a business request sent by an upper-layer application to the external service; when the business request is routed to the primary POD by the external service, processing the business request through the primary POD to obtain a corresponding processing result, and sending the processing result to the upper-layer application; when the primary POD generates status data, sending the status data to the internal service of the backup POD through the primary POD's internal service, so that the backup POD obtains the status data, achieving data synchronization between the backup POD and the primary POD; the status data includes the processing result obtained by the primary POD from processing the business request; when a business request is routed to the backup POD by the external service, sending the business request to the internal service of the primary POD through the backup POD's internal service, so that the primary POD obtains the business request, achieving request forwarding between the backup POD and the primary POD.
2. The method according to claim 1, characterized in that, The deployment process of the redundant POD includes: obtaining redundant configuration information input by the user; the redundant configuration information includes the pairing relationship between the first POD and the second POD, and the respective services of the first POD and the second POD; establishing a communication connection between the first POD and the second POD based on the respective services of the first POD and the second POD; initializing one of the first POD and the second POD as the primary POD and the other as the backup POD to complete the deployment of the redundant POD.
3. The method according to claim 2, characterized in that, Both the first POD and the second POD are stateful PODs and belong to the same application.
4. A server, characterized in that, The server's operating system is a Kubernetes cluster deploying redundant Points of Data (PODs). The redundant PODs include a primary POD and a backup POD. Each primary POD and backup POD is configured with an internal service for communication and interconnection. The Kubernetes cluster provides an external service for external access, including: a request receiving unit for receiving business requests sent by the upper-layer application to the external service; a request processing unit for processing the business request through the primary POD when the external service routes the request to the primary POD, obtaining the corresponding processing result, and sending the processing result to the upper-layer application; and a data synchronization unit for synchronizing data when the primary POD generates a state. When processing data, the status data is sent from the internal service of the primary POD to the internal service of the backup POD, so that the backup POD can obtain the status data and realize data synchronization between the backup POD and the primary POD. The status data includes the processing result obtained by the primary POD in processing the service request. The request forwarding unit is used to send the service request to the internal service of the primary POD through the internal service of the backup POD when the service request is routed to the backup POD by the external service, so that the primary POD can obtain the service request and realize request forwarding between the backup POD and the primary POD.
5. The server according to claim 4, characterized in that, The server further includes a redundancy deployment unit, configured to: obtain redundancy configuration information input by the user; the redundancy configuration information includes the pairing relationship between the first POD and the second POD, and the respective services of the first POD and the second POD; establish a communication connection between the first POD and the second POD based on the respective services of the first POD and the second POD; initialize one of the first POD and the second POD as the primary POD, and initialize the other as the backup POD, to complete the deployment of the redundant POD.
6. The server according to claim 5, characterized in that, Both the first POD and the second POD are stateful PODs and belong to the same application.
7. A storage medium, characterized in that, The storage medium includes a stored program, wherein the program is executed by a processor to perform the stateless access method based on any one of claims 1-3 based on a Kubernetes cluster.
8. An electronic device, characterized in that, include: Processor, memory, and bus; The processor and the memory are connected via the bus; The memory is used to store the program, and the processor is used to run the program, wherein the program is executed by the processor to perform the stateless access method based on any one of claims 1-3 based on a K8s cluster.
Citation Information
Patent Citations
Access request forwarding method and device, storage medium and electronic device
CN114490070A