Stateless access method based on K8s cluster and server
By deploying redundant PODs in the K8s cluster and realizing internal communication and request forwarding, the problem that stateful Pods are difficult to manifest as stateless in the K8s cluster is solved, and the horizontal scale and 1:1 redundancy function are achieved.
Patent Information
- Application Number
- CN202411841349.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-13
- Publication Date
- 2025-03-28
- Estimated Expiration
- 2044-12-13
AI Technical Summary
In K8s clusters, it is difficult for the prior art to reflect two redundant stateful Pods as stateless to the outside, resulting in the inability to easily achieve horizontal scale and 1:1 redundancy.
By deploying redundant PODs in the K8s cluster, the main POD and the backup POD each configure internal services for communication and interconnection, and the external services provide external access, realizing the routing of service requests, synchronization of processing results and request forwarding.
It realizes data synchronization and request forwarding between two stateful Pods in the K8s cluster, and has redundant functions, making external access appear stateless, supporting horizontal scale and 1:1 redundancy.
Smart Images

Figure CN119718543A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a stateless access method and server based on a K8s cluster. Background Art
[0002] In cluster deployment, K8s cluster provides container orchestration technology. The basic deployment unit of K8s cluster is denoted as POD, which can contain one or more containers. These containers share network, storage and configuration, and can be scheduled and managed together, so as to quickly deploy application cloud clusters.
[0003] Since the business of the application determines whether the container is stateful, stateful applications usually cannot be simply horizontally expanded and cannot easily achieve 1:1 redundancy. Only stateless applications can easily achieve horizontal expansion and naturally support 1:1 redundancy. Summary of the invention
[0004] The present application provides a stateless access method and server based on a K8s cluster, the purpose of which is to make the two redundant stateful Pods corresponding to the application appear stateless to the outside world.
[0005] In order to achieve the above objectives, this application provides the following technical solutions:
[0006] A stateless access method based on a K8s cluster is applicable to a system where redundant PODs are deployed. The redundant PODs include a primary POD and a backup POD. The primary POD and the backup POD are each configured to perform an internal service for communication and interconnection. The system is configured to provide an external service for 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 a corresponding processing result, and the processing result is sent to the upper layer application;
[0009] When the main POD generates status data, the status data is sent to the internal service of the backup POD through the internal service of the main POD, so that the backup POD obtains the status data and realizes data synchronization between the backup POD and the main POD; the status data includes the processing result obtained by the main POD processing the business request.
[0010] Optionally, the method further includes:
[0011] When the business request is routed to the standby POD by the external service, the business request is sent to the internal service of the primary POD through the internal service of the standby POD, so that the primary POD obtains the business request, thereby realizing request forwarding between the standby POD and the primary POD.
[0012] Optionally, the deployment process of the redundant POD includes:
[0013] Obtaining redundant configuration information input by a user; the redundant configuration information includes a pairing relationship between the first POD and the second POD, and respective services of the first POD and the second POD;
[0014] Establishing a communication connection between the first POD and the second POD based on respective services of the first POD and the second POD;
[0015] Based on that, one of the first POD and the second POD is initialized as the primary POD, and the other is initialized as the standby POD, so as to complete the deployment of the redundant POD.
[0016] Optionally, the first POD and the second POD are both stateful PODs, and both belong to the same application.
[0017] A server, wherein the operating system of the server is a K8s cluster with redundant PODs deployed, wherein the redundant PODs include a primary POD and a backup POD, wherein the primary POD and the backup POD are each configured with an internal service for communication and interconnection, and the K8s cluster provides an external service for external access, including:
[0018] A request receiving unit, used to obtain a business request sent by an upper layer application to the external service;
[0019] A request processing unit, configured to, when the service request is routed to the main POD by the external service, process the service request through the main POD to obtain a corresponding processing result, and send the processing result to the upper layer application;
[0020] A data synchronization unit is used to send the status data to the internal service of the standby POD through the internal service of the main POD when the main POD generates the status data, so that the standby POD obtains the status data and realizes data synchronization between the standby POD and the main POD; the status data includes the processing result obtained by the main POD processing the business request.
[0021] Optionally, the server further includes:
[0022] A 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 obtains the service request and realizes request forwarding between the backup POD and the primary POD.
[0023] Optionally, the server further includes:
[0024] A redundant deployment unit is used to: obtain redundant configuration information input by a user; the redundant configuration information includes a pairing relationship between the first POD and the second POD, and respective services of the first POD and the second POD; establish a communication connection between the first POD and the second POD based on 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 the other as the backup POD to complete the deployment of the redundant POD.
[0025] Optionally, the first POD and the second POD are both stateful PODs, and both belong to the same application.
[0026] A storage medium, comprising a stored program, wherein the program is executed by a processor when it is run to execute the stateless access method based on a K8s cluster.
[0027] An electronic device, comprising: a processor, a memory and a bus; the processor and the memory are connected via the bus;
[0028] The memory is used to store programs, and the processor is used to run programs, wherein the program executes the stateless access method based on the K8s cluster when the processor runs it.
[0029] The technical solution provided by the present application obtains the business request sent by the upper-layer application to the external service. 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. When the main POD generates status data, the status data is sent to the internal service of the standby POD through the internal service of the main POD, so that the standby POD obtains the status data and realizes data synchronization between the standby POD and the main POD. The present application enables the two stateful PODs in the K8s cluster to have redundant functions such as mutual communication, request forwarding, and data synchronization, thereby realizing two redundant stateful PODs, which appear to be stateless to the outside world. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0031] Figure 1 A flow chart of a stateless access method based on a K8s cluster provided in an embodiment of the present application;
[0032] Figure 2 A flowchart of a redundant POD deployment method provided in an embodiment of the present application;
[0033] Figure 3 A schematic diagram of data synchronization provided in an embodiment of the present application;
[0034] Figure 4 A schematic diagram of request forwarding provided in an embodiment of the present application;
[0035] Figure 5 A schematic diagram of the architecture of a server provided in an embodiment of the present application. DETAILED DESCRIPTION
[0036] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0037] In this application, relational terms such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. The terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of more restrictions, the elements defined by the sentence "comprise one..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0038] The professional terms mentioned in the embodiments of the present application can be explained with reference to the meaning shown below.
[0039] K8s (Kubernetes): An open source container orchestration platform for automating the deployment, expansion, and management of containerized applications. K8s simplifies container management by providing service discovery, load balancing, rolling updates, automatic fault recovery, and other functions.
[0040] Cluster: refers to multiple computers (nodes) grouped together to provide stronger processing power and higher availability. In a K8s 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 restore these states after restart or failure.
[0042] Stateless: The application does not save any state information. Each request is independent. The server does not need to know the previous state when processing a request. Stateless applications can be easily expanded and restarted.
[0043] POD: The basic deployment unit in K8s, which can contain one or more containers. These containers share the 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 additional components (such as servers, nodes, or replicas) to ensure that the system continues to operate normally if one component fails.
[0045] Service: In K8s, Service is an abstraction that defines a set of access policies for PODs. Service enables PODs in a cluster to be accessed through a fixed IP address and port number, regardless of how the POD life cycle changes. K8s provides multiple types of Service, namely Cluster IP, Node Port, Load Balance, and ExternalName.
[0046] Cluster IP: The default type, which can only be accessed within the cluster, that is, it is 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 create an external load balancer in the cloud environment to distribute traffic to the corresponding PODs.
[0049] External Name: Maps the service to an external Domain Name System name.
[0050] ConfigMAP: It is a resource in K8s that is used to store non-confidential configuration information for use in PODs, allowing users to separate configuration information from container images, so that application configurations can be flexibly modified without rebuilding the image.
[0051] like Figure 1 As shown, it is a flow chart of a stateless access method based on a K8s cluster provided in an embodiment of the present application. The method is applicable to a system in which redundant PODs are deployed. 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 and interconnection. The system configuration is used to provide an external service for external access, including the steps shown below.
[0052] S101: Obtaining a business request sent by an upper-layer application to an external service.
[0053] The upper layer application includes but is not limited to a browser, that is, the browser sends a business request to the external service of the system.
[0054] In some examples, the type of external service can be Load Balance.
[0055] S102: When a business request is routed to the main POD by an external service, the business request is processed by the main POD to obtain a corresponding processing result, and the processing result is sent to an upper-layer application.
[0056] For upper-layer applications (such as browsers), the external service can be regarded as a unique virtual IP. The external service corresponds to two different services (i.e., the primary POD and the backup POD), and can be randomly routed to the primary POD or the backup POD. Generally speaking, if the node corresponding to either the primary POD or the backup POD goes offline, the external service will automatically route the business request to another node.
[0057] Optionally, when a business request is routed to the standby POD by an external service, the business request is sent to the internal service of the primary POD through the internal service of the standby POD, so that the primary POD obtains the business request, thereby realizing request forwarding between the standby POD and the primary POD.
[0058] In some examples, the type of internal service can be Cluster IP.
[0059] It can be understood that the primary POD and the backup POD communicate and interconnect through their respective internal services. To this end, the backup POD can forward business requests to the primary POD.
[0060] S103: When the primary POD generates status data, the status data is sent to the internal service of the standby POD through the internal service of the primary POD, so that the standby POD obtains the status data, thereby achieving data synchronization between the standby POD and the primary POD.
[0061] The status data includes the processing result obtained by the main POD when processing the business request.
[0062] It should be noted that based on the system shown in the embodiment of the present application, mutual communication and data synchronization are carried out between the two PODs, so that the originally two redundant stateful PODs can be exposed statelessly to the outside through an external service, thereby easily realizing redundant functions such as mutual connection between applications, request forwarding, and data synchronization.
[0063] Optionally, for the implementation process of deploying redundant PODs on the system, see Figure 2 The steps are shown and the corresponding explanations.
[0064] In some examples, for the scenario of browser accessing application A, the external service corresponding to application A is service-A, the redundant PODs corresponding to application A include POD-A1 and POD-A2, the internal service of POD-A1 is service-A1, the internal service of POD-A2 is service-A2, and POD-A1 is the main POD and POD-A2 is the backup POD. When the business request is forwarded from service-A to POD-A1, the data synchronization scenario between POD-A1 and POD-A2 can be seen in Figure 3 When the business request is forwarded from service-A to POD-A2, the request forwarding scenario between POD-A1 and POD-A2 can be seen in Figure 4 shown.
[0065] That is to say, when a business request is sent to POD-A2, POD-A2 sends the request to POD-A1 for processing. After POD-A1 completes the processing, POD-A2 returns the processing result to the requester. When POD-A1 generates status data, POD-A1 transmits the status data to POD-A2 through the synchronization channel, so that POD-A2 can maintain data synchronization with POD-A1. In addition, when a business request is sent to POD-A1, POD-A1 directly processes it and returns it to the upper-level application, and synchronizes the processing result to POD-A2. The next time there is a business request to POD-A2, it can also maintain the status after the last request to POD-A1. So far, no matter whether the upper-level application accesses POD-A1 or POD-A2, it can obtain the same result, realizing stateless access to the outside world.
[0066] The process shown in S101-S103 above enables the two stateful PODs in the K8s cluster to have redundant functions such as mutual communication, request forwarding, and data synchronization, thereby realizing two redundant stateful PODs, which appear to be stateless to the outside world.
[0067] like Figure 2 As shown, it is a flow chart of a redundant POD deployment method provided in an embodiment of the present application, including the following steps.
[0068] S201: Obtaining redundant configuration information input by a user.
[0069] 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.
[0070] Optionally, both the first POD and the second POD are stateful PODs, and both belong to the same application.
[0071] In some examples, the type of redundant configuration information may be ConfigMAP. In a possible implementation, for redundant PODs of two applications, the corresponding ConfigMAP may 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. The upper-layer application 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: 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.
[0075] The service type of each of the first POD and the second POD may be Cluster IP.
[0076] In some examples, POD-A1 and POD-A2 may establish a communication connection through service-A1 and service-A2, and POD-B1 and POD-B2 may establish a communication connection through service-B1 and service-B2.
[0077] S203: Based on one of the first POD and the second POD, initialize it as a main POD, and initialize the other one as a backup POD, so as to complete the deployment of the redundant POD.
[0078] After the main POD and the backup POD are initialized, the redundancy function of the system can be realized through the main POD and the backup POD.
[0079] The above process shown in S201-S203 can successfully deploy the redundant POD corresponding to the application on the system.
[0080] like Figure 5 As shown, it is a schematic diagram of the architecture of a server provided in an embodiment of the present 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 an internal service for communication and interconnection. The K8s cluster provides an external service for external access. The server includes the units shown below.
[0081] The request receiving unit 100 is used to obtain the business request sent by the upper layer application to the external service.
[0082] The request processing unit 200 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 to 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 standby POD through the internal service of the main POD when the main POD generates the status data, so that the standby POD obtains the status data and realizes data synchronization between the standby POD and the main POD; the status data includes the processing result obtained by the main POD processing the business request.
[0084] The request forwarding unit 400 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 obtains the service request and realizes request forwarding between the backup POD and the primary POD.
[0085] The redundant deployment unit 500 is used to: obtain redundant configuration information input by a user; the redundant configuration information includes a 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 a main POD and the other as a backup POD to complete the deployment of the redundant POD.
[0086] Optionally, both the first POD and the second POD are stateful PODs, and both belong to the same application.
[0087] The above-mentioned units enable the two stateful PODs in the K8s cluster to have redundant functions such as mutual communication, request forwarding, and data synchronization, thereby realizing two redundant stateful PODs, which appear to be stateless to the outside world.
[0088] The present application also provides a computer-readable storage medium, which includes a stored program, wherein the program executes the method provided by the present application.
[0089] The present 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 programs, and the processor is used to run the programs, wherein the method provided by the present application is executed when the programs are run.
[0090] In addition, the functions described above in the embodiments of the present application may be at least partially performed by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0091] Although several specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present application. Certain features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination.
[0092] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in this application (but not limited to) by each other to form a technical solution.
Claims
1. A stateless access method based on K8s cluster, characterized in that: A system for deploying redundant PODs, wherein the redundant PODs include a primary POD and a backup POD, wherein the primary POD and the backup POD are each configured to perform an internal service for communication and interconnection, and wherein the system is configured to provide an external service for external access, wherein the method includes: Obtain the business request sent by the upper-layer application to the external service; 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 a corresponding processing result, and the processing result is sent to the upper layer application; When the main POD generates status data, the status data is sent to the internal service of the backup POD through the internal service of the main POD, so that the backup POD obtains the status data and realizes data synchronization between the backup POD and the main POD; the status data includes the processing result obtained by the main POD processing the business request.
2. The method according to claim 1, characterized in that The method further comprises: When the business request is routed to the standby POD by the external service, the business request is sent to the internal service of the primary POD through the internal service of the standby POD, so that the primary POD obtains the business request, thereby realizing request forwarding between the standby POD and the primary POD.
3. The method according to claim 1, characterized in that The deployment process of the redundant POD includes: Obtaining redundant configuration information input by a user; the redundant configuration information includes a pairing relationship between the first POD and the second POD, and respective services of the first POD and the second POD; Establishing a communication connection between the first POD and the second POD based on respective services of the first POD and the second POD; Based on that, one of the first POD and the second POD is initialized as the primary POD, and the other is initialized as the standby POD, so as to complete the deployment of the redundant POD.
4. The method according to claim 3, characterized in that The first POD and the second POD are both stateful PODs, and both belong to the same application.
5. A server, characterized in that: The operating system of the server is a K8s cluster that deploys 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 and interconnection. The K8s cluster provides external services for external access, including: A request receiving unit, used to obtain a business request sent by an upper layer application to the external service; A request processing unit, configured to, when the service request is routed to the main POD by the external service, process the service request through the main POD to obtain a corresponding processing result, and send the processing result to the upper layer application; A data synchronization unit is used to send the status data to the internal service of the standby POD through the internal service of the main POD when the main POD generates the status data, so that the standby POD obtains the status data and realizes data synchronization between the standby POD and the main POD; the status data includes the processing result obtained by the main POD processing the business request.
6. The server according to claim 5, characterized in that: The server also includes: A 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 obtains the service request and realizes request forwarding between the backup POD and the primary POD.
7. The server according to claim 5, characterized in that: The server also includes: A redundant deployment unit is used to: obtain redundant configuration information input by a user; the redundant configuration information includes a pairing relationship between the first POD and the second POD, and respective services of the first POD and the second POD; establish a communication connection between the first POD and the second POD based on 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 the other as the backup POD to complete the deployment of the redundant POD.
8. The server according to claim 7, characterized in that: The first POD and the second POD are both stateful PODs, and both belong to the same application.
9. A storage medium, characterized in that: The storage medium includes a stored program, wherein the program, when executed by a processor, executes the stateless access method based on a K8s cluster as described in any one of claims 1 to 4.
10. An electronic device, characterized in that: include: processor, memory, and bus; The processor is connected to the memory via the bus; The memory is used to store programs, and the processor is used to run programs, wherein the program, when run by the processor, executes the stateless access method based on the K8s cluster described in any one of claims 1-4.
Citation Information
Patent Citations
Server hot standby method and system
CN109451063A
Pod creation method and device
CN110321115A
Service access method and system for kubernetes cluster, electronic equipment and medium
CN112671860A
Access request forwarding method and device, storage medium and electronic device
CN114490070A
Authentication service distribution method, node cluster and computer readable storage medium
CN115834705A