Method and device for realizing Kong DB-less cluster mode hot loading
Through the combination of K8S and Kong-updater and Nacos, the Kong DB-less cluster mode is realized, which solves the problems of configuration management complexity and dynamic updates, improves the reliability and flexibility of the system, and adapts to large-scale application scenarios. demand.
Patent Information
- Application Number
- CN202411189085.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-28
- Publication Date
- 2024-12-27
AI Technical Summary
Kong DB-less model has configuration management complexity, lack of dynamic update capabilities, and cluster consistency challenges in large-scale deployments, especially when ensuring all node configurations are synchronized.
Create Kong Deployment through K8S, connect with Nacos using Kong-updater to realize real-time updates and hot loading of API configurations, use Nacos Configuration Center to automatically push configuration changes, and write YAML format configurations to Kong through Kong admin API to achieve dynamic updates and cluster consistency.
It simplifies configuration management, provides dynamic update capabilities, enhances system reliability and flexibility, reduces operation and maintenance costs, and adapts to the needs of large-scale microservice architectures.
Smart Images

Figure CN119201203A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of microservices and cloud native, and specifically provides a method and device for implementing hot loading in Kong DB-less cluster mode. Background Art
[0002] The Kong DB-less mode does not rely on an external database to store configuration information, but stores the configuration information directly in the file system or similar storage media. The Kong DB-less mode is easy to deploy, has few external dependencies, and has relatively low operation and maintenance costs, but it also has some disadvantages:
[0003] Configuration management complexity: In DB-less mode, configuration information is stored directly in files, which may make configuration management complicated. Especially in large-scale deployments, it may become difficult to manually manage and synchronize configuration files.
[0004] Lack of dynamic updates: The traditional DB-less mode may not be able to dynamically update the configuration in real time. When the configuration changes, you need to manually reload the configuration or restart the Kong node for the new configuration to take effect.
[0005] Cluster consistency: In a multi-node Kong cluster, ensuring consistent configuration information on all nodes can be challenging. Especially in large-scale deployments, ensuring configuration synchronization on all nodes can become complex. Summary of the invention
[0006] The present invention aims at addressing the deficiencies of the above-mentioned prior art and provides a highly practical method for realizing hot loading of Kong DB-less cluster mode.
[0007] A further technical task of the present invention is to provide a reasonably designed, safe and applicable hot loading device for implementing Kong DB-less cluster mode.
[0008] The technical solution adopted by the present invention to solve its technical problem is:
[0009] A method for implementing hot loading in Kong DB-less cluster mode has the following steps:
[0010] S1. Use K8S to create Kong Deployment and set up multiple copies;
[0011] S2. Kong-updater uses javasdk to connect to Nacos;
[0012] S3. The external program completes the entry of basic API information through the UI interface;
[0013] S4, start Kong for the first time or elastically expand the node;
[0014] S5, Kong-updater monitors configuration changes;
[0015] S6. Perform hot loading.
[0016] Furthermore, in step S1, Kong DBless and Kong-updater are deployed in the Pod at the same time, and the Nacos configuration information is passed to the updater through the Env parameter;
[0017] At the same time, Deployment configures the HPA elastic scaling mechanism to determine whether nodes need to be expanded or reduced based on memory and CPU usage.
[0018] Furthermore, in step S2, Kong-updater uses javasdk to connect to Nacos, reads the API configuration in the Nacos configuration center, and obtains configuration changes in real time.
[0019] Furthermore, in step S3, the external program completes the entry of basic API information through the UI interface, and at the same time, stores the service, route, and upstream information of the API in the Nacos configuration center.
[0020] Furthermore, in step S4, when Kong is started for the first time or the node is elastically expanded, Kong-updater loads the complete API information from the configuration center, analyzes, verifies, and assembles it into YAML format, and then writes it to Kong in full through the Kong admin API.
[0021] Furthermore, in step S5, during subsequent incremental updates, Kong-updater monitors configuration changes, and Nacos automatically pushes the change information to Kong-updater, which parses and verifies the API configuration information and then assembles it into a YAML format.
[0022] Furthermore, in step S6, Kong-updater writes the configuration in YAML format into Kong through KongadminAPI to achieve hot loading.
[0023] A device for implementing hot loading in Kong DB-less cluster mode, comprising: at least one memory and at least one processor;
[0024] The at least one memory is used to store a machine-readable program;
[0025] The at least one processor is used to call the machine-readable program to execute a method for implementing Kong DB-less cluster mode hot loading.
[0026] Compared with the prior art, the method and device for implementing Kong DB-less cluster mode hot loading of the present invention has the following outstanding beneficial effects:
[0027] The present invention can simplify configuration management, provide dynamic update capabilities, enhance system reliability and elasticity, and reduce operation and maintenance costs to meet the needs of large-scale application scenarios under a modern microservice architecture. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the embodiments of the present invention 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 some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0029] Attached Figure 1 It is a framework diagram for implementing the hot loading method of Kong DB-less cluster mode;
[0030] Attached Figure 2 It is a flowchart of the hot loading method for implementing Kong DB-less cluster mode. DETAILED DESCRIPTION
[0031] In order to enable those skilled in the art to better understand the solution of the present invention, the present invention is further described in detail below in conjunction with specific implementation methods. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0032] A best embodiment is given below:
[0033] like Figure 1-2 As shown, a method for implementing hot loading in Kong DB-less cluster mode in this embodiment has the following steps:
[0034] S1. Use K8S to create Kong Deployment and set up multiple copies;
[0035] Kong DBless and Kong-updater are deployed in the Pod at the same time. The Nacos configuration information is passed to the updater through the Env parameter. At the same time, the Deployment configures the HPA elastic scaling mechanism to determine whether the node needs to be expanded or reduced based on the memory and CPU usage.
[0036] S2. Kong-updater uses javasdk to connect to Nacos;
[0037] Kong-updater uses javasdk to connect to Nacos, reads the API configuration in the Nacos configuration center, and obtains configuration changes in real time.
[0038] S3. The external program completes the entry of basic API information through the UI interface;
[0039] The external program completes the entry of basic API information through the UI interface, and stores the API's service, route, upstream and other configuration information in the Nacos configuration center.
[0040] S4, start Kong for the first time or elastically expand the node;
[0041] When Kong is started for the first time or a node is elastically expanded, Kong-updater loads the complete API information from the configuration center, analyzes, verifies, and assembles it into YAML format, and then writes it to Kong in full through the Kong admin API.
[0042] S5, Kong-updater monitors configuration changes;
[0043] During subsequent incremental updates, Kong-updater monitors configuration changes, and Nacos automatically pushes the change information to Kong-updater. Kong-updater parses and verifies the API configuration information, and then assembles it into YAML format.
[0044] S6, performing hot loading;
[0045] Kong-updater writes the YAML format configuration into Kong through KongadminAPI to achieve hot loading.
[0046] Based on the above method, a hot loading device for implementing Kong DB-less cluster mode in this embodiment includes: at least one memory and at least one processor;
[0047] The at least one memory is used to store a machine-readable program;
[0048] The at least one processor is used to call the machine-readable program to execute a method for implementing Kong DB-less cluster mode hot loading.
[0049] The above-mentioned specific implementations are only specific cases of the present invention. The patent protection scope of the present invention includes but is not limited to the above-mentioned specific implementations. Any technical solutions that comply with the claims of the present invention and any appropriate changes or substitutions made by ordinary technicians in the relevant technical field shall fall within the patent protection scope of the present invention.
[0050] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A method for implementing hot loading in Kong DB-less cluster mode, characterized in that: The steps are as follows: S1. Use K8S to create Kong Deployment and set up multiple copies; S2. Kong-updater uses javasdk to connect to Nacos; S3. The external program completes the entry of basic API information through the UI interface; S4, start Kong for the first time or elastically expand the node; S5, Kong-updater monitors configuration changes; S6. Perform hot loading.
2. According to claim 1, a method for implementing hot loading in Kong DB-less cluster mode is characterized in that: In step S1, Kong DBless and Kong-updater are deployed in the Pod at the same time, and the Nacos configuration information is passed to the updater through the Env parameter; At the same time, Deployment configures the HPA elastic scaling mechanism to determine whether nodes need to be expanded or reduced based on memory and CPU usage.
3. According to claim 2, a method for implementing hot loading in Kong DB-less cluster mode is characterized in that: In step S2, Kong-updater uses javasdk to connect to Nacos, reads the API configuration in the Nacos configuration center, and obtains configuration changes in real time.
4. According to claim 3, a method for implementing hot loading in Kong DB-less cluster mode is characterized in that: In step S3, the external program completes the entry of basic API information through the UI interface, and at the same time, stores the API's service, route, and upstream information in the Nacos configuration center.
5. According to claim 4, a method for implementing hot loading in Kong DB-less cluster mode is characterized in that: In step S4, when Kong is started for the first time or the node is elastically expanded, Kong-updater loads the complete API information from the configuration center, analyzes, verifies, and assembles it into YAML format, and then writes it to Kong in full through the Kong admin API.
6. According to claim 5, a method for implementing hot loading in Kong DB-less cluster mode is characterized in that: In step S5, during subsequent incremental updates, Kong-updater monitors configuration changes, and Nacos automatically pushes the change information to Kong-updater. Kong-updater parses and verifies the API configuration information, and then assembles it into YAML format.
7. According to claim 6, a method for implementing hot loading in Kong DB-less cluster mode is characterized in that: In step S6, Kong-updater writes the YAML format configuration into Kong through KongadminAPI to achieve hot loading.
8. A device for implementing hot loading in Kong DB-less cluster mode, characterized in that: include: at least one memory and at least one processor; The at least one memory is used to store a machine-readable program; The at least one processor is configured to call the machine-readable program to execute the method according to any one of claims 1 to 7.