Kubernetes-based application configuration dynamic loading method and device
Through Kubernetes informer, it monitors application configuration resource changes, processes and stores configuration structure objects, solves the problems of synchronization delay in ConfigMap update and high application management threshold, realizes dynamic loading and management of application configuration, and improves real-time and robustness.
Patent Information
- Application Number
- CN202411522636.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-29
- Publication Date
- 2025-01-07
AI Technical Summary
The synchronization of ConfigMap updates in Kubernetes is delayed and applications cannot perceive configuration changes in real time, resulting in a high threshold for application management.
Listen to the data changes of the application configuration resource in the specified namespace through Kubernetes informer, decode and process the configuration structure object, use the custom interface to fill in default values, static checks, comparison checks, equivalent detection and data overwrites, and store them in the local cache , and obtain the configuration field value through the Get method to realize dynamic loading and management of application configuration.
It solves the problem of synchronization delay in ConfigMap updates, improves the robustness and real-time nature of application configuration, reduces unnecessary computing overhead, reduces the risk of application exceptions, and moderately reduces the intrusion of third-party references.
Smart Images

Figure CN119271306A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of cloud computing technology, can be used in the financial field, and in particular to a Kubernetes-based application configuration dynamic loading method and device. Background Art
[0002] Kubernetes is the de facto standard in the cloud-native field. With the help of Kubernetes, applications can obtain advantages and conveniences such as flexible scheduling, agile delivery, and elastic expansion and contraction that are lacking in general cloud computing solutions.
[0003] ConfigMap is a native resource provided by Kubernetes. This resource provides a data format of string key-value pairs, allowing any application deployed on Kubernetes to decouple the application from the configuration by writing the configuration to ConfigMap. This allows the management of the application itself and the management of the configuration to be separated to improve the flexibility of application management. For complex configurations of applications, the data stored in the key-value pairs can be serialized in formats such as JSON, YAML, and XML. At the same time, ConfigMap also supports non-UTF-8 binary sequence data as the value of the key-value pair, but they also need to be written to ConfigMap in string format.
[0004] ConfigMap exists to separate the image and configuration of the application. When the application is deployed in a Kubernetes cluster, the standard practice is to create the environment-independent configuration as the data of the ConfigMap, and then create a Kubernetes native deployment unit or a deployment unit defined by a custom resource definition (CRD) that uses the application image, and the configuration of the deployment unit will reference the ConfigMap as the mount configuration. Regardless of the Pod created by any deployment unit, after being scheduled by Kubernetes, it will be pulled up by the system service kubelet component running on the Kubernetes cluster node. During the pull-up process, kubelet will pull the referenced ConfigMap to the local node based on the information inherited from the deployment unit configuration in the Pod, and then mount the content in the ConfigMap to the Pod's container as a volume (or add it to the Pod's environment variables by environment variable injection, depending on the usage of the ConfigMap defined in the Pod), so that the application in the Pod container can directly read the application configuration defined in the ConfigMap when it starts.
[0005] ConfigMap is a relatively static configuration solution. Although kubelet will periodically check the ConfigMap referenced by the Pod running on the node, so that when the ConfigMap content changes, the latest ConfigMap content can be synchronized to the local. However, this continuous monitoring is not very timely (there will be a maximum delay of two minutes under the default configuration of kubelet); on the other hand, the synchronization of new ConfigMap content only affects the scenario where the volume is used. And when the Pod of the application uses the subpath (subPath) volume attribute, it will not be synchronized. If the application wants to get the ConfigMap content update synchronization, it must choose the volume method that covers the entire directory. In addition, in the volume method, unless the application in the Pod container actively detects whether the configuration file under the relevant volume has changed, it will not be able to perceive whether the configuration has changed, which undoubtedly raises the threshold for application implementation. Summary of the invention
[0006] In view of this, the present invention provides a method and device for dynamically loading application configuration based on Kubernetes to solve at least one of the problems mentioned above.
[0007] In order to achieve the above object, the present invention adopts the following scheme:
[0008] According to a first aspect of the present invention, a method for dynamic loading of application configuration based on Kubernetes is provided, the method comprising: starting Kubernetes informer to monitor application configuration resource data with a specified label in a specified namespace; when the application configuration resource changes, obtaining the application configuration resource data; decoding the application configuration resource data and writing it into a configuration structure object; calling a custom interface method of the configuration structure object to perform default value filling, static checking, comparison checking, equivalence detection, data coverage and data improvement processing to obtain a processed configuration structure object; storing the processed configuration structure object in a local cache; and obtaining the field value of the configuration structure object in the local cache through a Get method.
[0009] As an embodiment of the present invention, before starting the Kubernetes informer to monitor the application configuration resource data with a specified label in the specified namespace, the above method also includes: when deployed in the Kubernetes cluster, specifying the namespace and specifying the label by injecting the Pod configuration environment variables.
[0010] As an embodiment of the present invention, the above method further includes: when writing the configuration structure object fails, the static check is illegal, the comparison check fails, and the equivalence check is invalid, then ignoring the current application configuration resource change.
[0011] As an embodiment of the present invention, the above method calls the custom interface method of the configuration structure object to perform default value filling, static check, comparison check, equivalence detection, data overwriting and data improvement processing, including: calling the Default method of the configuration structure object, checking the configuration structure object, and writing default values to the default fields; calling the StaticValidate method of the configuration structure object, statically checking the configuration structure object; calling the Validate method of the cached configuration structure object, and passing in the new configuration structure object as a parameter, and comparing the cached configuration structure object with the new configuration structure object; calling the Equal method of the cached configuration structure object, and passing in the new configuration structure object as a parameter, and performing an equivalence check on the cached configuration structure object with the new configuration structure object; calling the OverrideFrom method of the cached configuration structure object, and passing in the new configuration structure object as a parameter, and overwriting the received new configuration structure object into the cached configuration structure object; calling the Complete method of the cached configuration structure object to perform additional data supplement processing on the configuration structure object.
[0012] As an embodiment of the present invention, when the field value of the configuration structure object in the local cache is obtained through the Get method in the above method, the read-write lock in the configuration structure is first read-locked, and the read lock is released before the corresponding value is obtained and returned through the Get method.
[0013] As an embodiment of the present invention, in the above method, when the received new configuration structure object is overwritten into the cached configuration structure object, a write lock operation is first performed on the read-write lock in the configuration structure, and after the overwriting is completed, a write lock release operation is performed.
[0014] As an embodiment of the present invention, the application configuration resource data in the above method includes ConfigMap resource data, Secret resource data and custom resource data.
[0015] According to a second aspect of the present invention, a Kubernetes-based application configuration dynamic loading device is provided, the device comprising: a monitoring unit, used to start Kubernetes informer to monitor application configuration resource data with a specified label in a specified namespace; a configuration resource acquisition unit, used to acquire the application configuration resource data when the application configuration resource changes; a decoding and writing unit, used to decode the application configuration resource data and write it into a configuration structure object; a data processing unit, used to call a custom interface method of the configuration structure object to perform default value filling, static checking, comparison checking, equivalence detection, data coverage and data improvement processing to obtain a processed configuration structure object; a cache unit, used to store the processed configuration structure object in a local cache; a configuration field acquisition unit, used to acquire the field value of the configuration structure object in the local cache through a Get method.
[0016] As an embodiment of the present invention, the above-mentioned device also includes: an injection unit, which is used to specify the namespace and the label by injecting the Pod configuration environment variables when deployed in the Kubernetes cluster.
[0017] As an embodiment of the present invention, the above-mentioned device also includes: a resource change ignoring unit, which is used to ignore the current application configuration resource change when writing the configuration structure object fails, the static check is illegal, the comparison check fails, and the equivalence check is invalid.
[0018] As an embodiment of the present invention, the above-mentioned data processing unit includes: a default value filling module, which is used to call the Default method of the configuration structure object, check the configuration structure object, and write default values to the default fields; a static check module, which is used to call the StaticValidate method of the configuration structure object to perform a static check on the configuration structure object; a comparison check module, which is used to call the Validate method of the cached configuration structure object, and pass in the new configuration structure object as a parameter, and compare and check the cached configuration structure object with the new configuration structure object; an equivalence check module, which is used to call the Equal method of the cached configuration structure object, and pass in the new configuration structure object as a parameter, and perform an equivalence check on the cached configuration structure object with the new configuration structure object; a data overwrite module, which is used to call the OverrideFrom method of the cached configuration structure object, and pass in the new configuration structure object as a parameter, and overwrite the received new configuration structure object into the cached configuration structure object; a supplement processing module, which is used to call the Complete method of the cached configuration structure object to perform additional data supplement processing on the configuration structure object.
[0019] As an embodiment of the present invention, when the above-mentioned configuration field acquisition unit obtains the field value of the configuration structure object in the local cache through the Get method, the read-write lock in the configuration structure is first read-locked, and before the corresponding value is obtained and returned through the Get method, the read lock is released.
[0020] As an embodiment of the present invention, when the data overwriting module overwrites the received new configuration structure object into the cached configuration structure object, it first performs a write lock operation on the read-write lock in the configuration structure, and then performs a write lock release operation after the overwriting is completed.
[0021] As an embodiment of the present invention, the above-mentioned application configuration resource data includes ConfigMap resource data, Secret resource data and custom resource data.
[0022] According to a third aspect of the present invention, there is provided an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.
[0023] According to a fourth aspect of the present invention, there is provided a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the steps of the above method when executed by a processor.
[0024] According to a fifth aspect of the present invention, there is provided a computer program product, comprising a computer program / instructions, which implement the steps of the above method when executed by a processor.
[0025] From the above technical solution, it can be seen that this application uses Kubernetes' native informer technology and a set of standard interfaces designed to achieve quasi-real-time monitoring and acquisition of application configurations, solve the problem of ConfigMap update synchronization delay, and at the same time improve the robustness of application configurations. In addition, this application also introduces a local caching mechanism to reduce unnecessary computing overhead, improve application performance, and is moderately invasive to third-party references. As long as the third-party reference implements the custom standard interface of this application, it can be seamlessly integrated into this patent solution to achieve dynamic loading and management of application configurations. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0027] Figure 1 It is a flow chart of a method for dynamic loading of application configuration based on Kubernetes provided by an embodiment of the present invention;
[0028] Figure 2 It is a schematic diagram of the processing flow of the custom interface method in the configuration structure object provided in the embodiment of the present application;
[0029] Figure 3 It is a flowchart of a method for dynamic loading of application configuration provided by another embodiment of the present application;
[0030] Figure 4 It is a structural diagram of a Kubernetes-based application configuration dynamic loading device provided by an embodiment of the present invention;
[0031] Figure 5 It is a structural diagram of a Kubernetes-based application configuration dynamic loading device provided by another embodiment of the present invention;
[0032] Figure 6 is a structural schematic diagram of a data processing unit provided by an embodiment of the present invention;
[0033] Figure 7 It is a schematic block diagram of the system structure of the electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0034] To make the purpose, technical solution and advantages of the embodiments of the present invention more clear, the embodiments of the present invention are further described in detail below in conjunction with the accompanying drawings. Here, the exemplary embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.
[0035] The information collected in the technical solution of this application is information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of relevant data comply with the relevant laws, regulations and standards of relevant countries and regions, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0036] The acquisition, transmission, storage, use, and processing of data in the technical solution of this application comply with the relevant provisions of national laws and regulations.
[0037] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.
[0038] like Figure 1 The figure shows a flow chart of a method for dynamic loading of application configuration based on Kubernetes provided in an embodiment of the present invention. This embodiment describes the present application from the third-party application side. The method includes the following steps:
[0039] Step S101: Start Kubernetes informer to monitor application configuration resource data with a specified label in a specified namespace.
[0040] In this embodiment, the third-party application needs to start a Kubernetes informer instance, which is responsible for monitoring the application configuration resource data with a specific label in the specified namespace. The application configuration resource data here includes but is not limited to ConfigMap resource data, Secret resource data, and custom resource data (CRD). In this embodiment, after starting the informer, the informer will establish a connection with the Kubernetes API Server and continue to monitor the change events of the specified resources.
[0041] Informer is a native technology implementation provided by Kubernetes to support different components in the Kubernetes platform to obtain resource object update events by listening to the Kubernetes apiserver. The underlying layer of informer is based on the List&Watch method to establish a connection with the Kubernetes apiserver. This method obtains full data through the List method when the connection is just established or interrupted and restored, and then obtains incremental data through the Watch method to ensure that the client code using informer can always obtain resource object update events from the Kubernetes apiserver in a timely manner. At the same time, it avoids the pressure on the Kubernetes apiserver when there are too many clients.
[0042] Namespace is a logical isolation mechanism used in Kubernetes to group resources. It allows multiple virtual clusters to be created in the same cluster, each of which can have its own resources (such as Pod, Service, ConfigMap, etc.). Label is a key-value pair attached to Kubernetes resources to identify and select resources. It can be used to organize, select, and filter resources.
[0043] In this embodiment, namespaces and labels can be used in combination to achieve more fine-grained resource management. The informer listens to ConfigMaps with specific labels in a specific namespace, which means that the informer will only pay attention to those ConfigMap resources in the specified namespace and that meet the specific label conditions. This method can effectively filter and manage resources to ensure that only relevant configurations are processed.
[0044] Preferably, the monitored namespace and label information are usually injected into the third-party application through environment variables, so that the third-party application can adapt to different deployment environments more flexibly. That is, when the third-party application is deployed in the Kubernetes cluster, the namespace and label are specified by injecting the Pod configuration environment variables.
[0045] Further preferably, this embodiment also defines the startup order of the informer in the third-party reference. The informer needs to be started before the components that have configuration dependencies are started or instantiated in the third-party application, and the third-party application needs to wait for the informer to complete the first synchronization with the Kubernetes APIServer. Only after the first synchronization is completed, the application can extract the configuration information required by the relevant components in the application from the ConfigMap, Secret or CRD. For example, an application may mainly provide services by starting the http service. Before the http service is started, it may include the registration of service routes, the instantiation of specific apps in the routing backend, etc. If the specific backend app needs to obtain configuration information when instantiated, it is necessary to instantiate the backend app after the informer completes the synchronization.
[0046] Step S102: when the application configuration resource changes, the application configuration resource data is obtained.
[0047] Taking the ConfigMap resource object as an example, when a new ConfigMap resource object is submitted to the Kubernetes API Server, or when a change to an existing ConfigMap resource object is submitted to the Kubernetes API Server, the Kubernetes API Server will notify the informer of the change of the ConfigMap resource object in the form of an event notification. Therefore, with the help of the informer's event notification mechanism, this application can obtain the application configuration changes contained in the ConfigMap in a quasi-real-time manner, and then obtain the application configuration resource data of the change.
[0048] Step S103: Decode the application configuration resource data and write it into a configuration structure object.
[0049] The third-party applications targeted by this application need to define their configurations in the form of structures, which can be one or more structures. The fields of these configuration structures can correspond to specific configuration items or nested substructures. Corresponding to general application development, an application may have one or more configuration files, and a configuration file corresponds to a configuration structure, that is, a configuration item in a configuration file can correspond to a field in the configuration structure. For the format of the configuration content corresponding to the configuration structure, this application considers mainstream formats, such as JSON, YAML, TOML, etc. When a third-party application uses the design scheme of this application, it is necessary to write the application configuration to the Kubernetes ConfigMap resource object. For example, it can be a YAML file that writes a ConfigMap object containing the configuration content, and then submits the contents of the YAML file to the Kubernetes APIServer in the form of the kubectl command line tool.
[0050] Therefore, when the ConfigMap resource data changes, this application first decodes the data in the ConfigMap in mainstream formats such as JSON, YAML, or TOML, and then tries to write it into the configuration structure object.
[0051] For the specific implementation of this step, the configuration structure of the third-party application of this application needs to implement a New method, which does not take any parameters and returns an object of the configuration structure. When the configuration data in ConfigMap is decoded in mainstream formats such as JSON, YAML, or TOML, it will be injected into the object obtained by the New method.
[0052] Step S104: calling the custom interface method of the configuration structure object to perform default value filling, static check, comparison check, equivalence check, data coverage and data improvement processing to obtain a processed configuration structure object.
[0053] In this embodiment, the third-party application needs to implement a set of standard interface methods for the configuration structure object, which are used to fill in missing values, static legality check, dynamic validity check, data comparison and overwriting, etc. on the configuration data to ensure the integrity and correctness of the configuration data. After these processes, a fully verified and supplemented configuration structure object can be obtained.
[0054] Preferably, Figure 2 As shown, in this step, calling the custom interface method of the configuration structure object to perform default value filling, static check, comparison check, equivalence check, data coverage and data improvement processing may further include:
[0055] Step S1041: calling the Default method of the configuration structure object, checking the configuration structure object, and writing default values to the default fields.
[0056] This step is to call the Default method of the configuration structure object, which is used to provide the default value of the configuration structure object. By calling the Default method, you can check whether there are default fields in the configuration structure object and fill these fields with default values. This ensures that the configuration structure object always contains complete configuration information.
[0057] Step S1042: calling the StaticValidate method of the configuration structure object to perform a static check on the configuration structure object.
[0058] The StaticValidate method here is used to perform a static validity check on the configuration structure object. The "static" here refers to a check that can be completed without relying on any external conditions or runtime information. Specifically, the StaticValidate method can include but is not limited to the following functions: check whether the format of the configuration data is correct; check whether a configuration item is the expected data type (integer, string, etc.); check whether the field meets specific format requirements (such as URL, Email format, etc.); check whether the value range of the configuration data is legal; check whether a time interval configuration item is within a reasonable range; check whether the logical relationship between configuration items is correct, etc.
[0059] Step S1043: calling the Validate method of the cached configuration structure object, and passing in the new configuration structure object as a parameter, and performing a comparison check between the cached configuration structure object and the new configuration structure object.
[0060] The StaticValidate method only checks the structure object itself, so it can only check the newly received configuration itself, and cannot do forward comparison, that is, compare with the cached configuration. For example, if there is a configuration item that cannot be modified once it is set, it is necessary to compare the cached configuration with the newly received configuration. Therefore, this step calls the Validate method of the cached configuration structure object, which is used to perform dynamic validity checks on configuration data. Specifically, the new configuration structure object is passed in as a parameter and compared with the cached configuration structure object. This can solve some detections that the StaticValidate method cannot perform.
[0061] Step S1044: calling the Equal method of the cached configuration structure object, and passing the new configuration structure object as a parameter, and performing an equivalence check between the cached configuration structure object and the new configuration structure object.
[0062] This step is to call the Equal method of the cached configuration structure object. This method is used to compare whether two configuration structure objects are equivalent. By passing in the new configuration structure object as a parameter and comparing it with the cached configuration structure object, it can be determined whether the new and old configurations are equivalent, thereby deciding whether subsequent operations need to be performed.
[0063] Step S1045: calling the OverrideFrom method of the cached configuration structure object, and passing in the new configuration structure object as a parameter, and overwriting the received new configuration structure object into the cached configuration structure object.
[0064] This step is to call the OverrideFrom method of the cached configuration structure object. This method is used to overwrite the value of a configuration structure object to another object, that is, to pass in a new configuration structure object as a parameter and overwrite it to the cached configuration structure object. In this way, the cached configuration structure object can be updated to contain the latest configuration data.
[0065] Step S1046: Call the Complete method of the cached configuration structure object to perform additional data supplementation processing on the configuration structure object.
[0066] This step is to call the Complete method of the cached configuration structure object. This method is used to perform additional data supplementation processing on the configuration structure object. Therefore, some specific business logic can be executed here to further improve and supplement the configuration data.
[0067] Step S105: storing the processed configuration structure object in a local cache.
[0068] In this embodiment, the third-party application needs to maintain a local cache to store the loaded and processed configuration structure objects. The local cache is the consumer of the informer. By implementing the event processing function, it accepts the ConfigMap update event from the informer and stores the processed data in the ConfigMap in the form of the third-party application configuration structure object in the local cache for subsequent quick access. This can reduce unnecessary computing overhead and improve application performance.
[0069] Preferably, in the above method, when the writing of the configuration structure object fails, the static check is illegal, the comparison check fails, and the equivalence check is invalid, the change in the application configuration resources will be ignored. The purpose of this is to ensure that only configuration data that has been fully verified and verified will be used by the application, thereby improving the robustness and reliability of the application. If a problem is found in the configuration data in any of the inspection steps, the configuration change is directly ignored to avoid introducing illegal or invalid configuration data into the application. Through this strict configuration verification mechanism, the present application solution ensures that the application always uses the correct configuration data, greatly reducing the risk of application anomalies or failures caused by configuration errors.
[0070] Step S106: Obtain the field values of the configuration structure object in the local cache through the Get method.
[0071] When a third-party application needs to access configuration data, it can obtain the required configuration item value by calling the Get method of the configuration structure object instead of directly reading the field value in the configuration structure. By providing the Get method on the configuration structure object instead of directly exposing the internal fields, the code of the third-party application can be made more concise, robust, and maintainable. In addition, this step reads the configuration data from the local cache instead of pulling it from the Kubernetes API Server every time, which can greatly improve the response speed.
[0072] Preferably, the configuration structure of the present application also includes a read-write lock. When the field value of the configuration structure object in the local cache is obtained by the Get method, the read-write lock in the configuration structure first performs a read lock operation, and before the corresponding value is obtained and returned by the Get method, a read lock release operation is performed. In a multi-threaded environment, if multiple threads access the configuration structure object at the same time, data competition problems may occur. By using a read-write lock, it can be ensured that the configuration value will not be modified by other threads when reading, thereby avoiding the problem of data competition. Moreover, the read-write lock allows multiple threads to read the configuration value at the same time, and the write lock is added only when the configuration value is written, blocking other read operations, which can greatly improve the concurrency performance of the application, especially in the scenario where the read operation is far more than the write operation. Compared with the use of a global mutex lock, the read-write lock can control the granularity of the lock in a finer granularity, reduce the overhead of lock competition, and only need to obtain a read lock in the read operation, without obtaining a write lock, which further improves performance. In short, adding a read-write lock to the configuration structure and automatically locking and releasing it in the Get method can not only ensure thread safety, but also improve the concurrency performance of the application, greatly simplifying the programming work of the developer, and is a supplement and improvement to the present application solution.
[0073] Further preferably, when the above-mentioned read-write lock overwrites the received new configuration structure object into the cached configuration structure object, it can also first perform a write lock operation on the read-write lock in the configuration structure, and when the overwriting is completed, perform a write lock release operation. Similarly, in a multi-threaded environment, if multiple threads try to update the configuration structure object at the same time, data inconsistency may occur. By adding a write lock before the update operation, it can be ensured that it will not be disturbed by other threads during the update process, thereby ensuring data consistency. If there are other threads reading the configuration value while updating the configuration structure object, there may be a read-write conflict problem. Therefore, adding a write lock can ensure that other read operations will be blocked during the update process, avoiding read-write conflicts. Compared with holding a global mutex lock throughout the update process, this read-write lock method can greatly improve concurrency, because read operations can be performed concurrently, and only when the update operation is performed, it is necessary to wait for the release of the write lock.
[0074] From the above technical solution, it can be seen that this application uses Kubernetes' native informer technology and a set of standard interfaces designed to achieve quasi-real-time monitoring and acquisition of application configurations, solve the problem of ConfigMap update synchronization delay, and at the same time improve the robustness of application configurations. In addition, this application also introduces a local caching mechanism to reduce unnecessary computing overhead, improve application performance, and is moderately invasive to third-party references. As long as the third-party reference implements the custom standard interface of this application, it can be seamlessly integrated into this patent solution to achieve dynamic loading and management of application configurations.
[0075] like Figure 3 FIG. 1 is a flow chart of a method for dynamically loading application configurations provided by another embodiment of the present application, comprising Figure 3 It can be seen that when a resource object in ConfigMap is created or updated, the informer obtains the resource object update event from the Kubernetes apiserver through the List&Watch method, and then calls the event processing & controller, which performs relevant processing using the interface defined in the framework of this patent application. The specific processing method can be found in the description in the above embodiment. After processing, it is stored in the local cache, and the application obtains the configuration data through the Get method.
[0076] like Figure 4 The figure shows a structural schematic diagram of a Kubernetes-based application configuration dynamic loading device provided in an embodiment of the present application, wherein the device includes: a monitoring unit 410, a configuration resource acquisition unit 420, a decoding and writing unit 430, a data processing unit 440, a cache unit 450 and a configuration field acquisition unit 460, which are connected in sequence.
[0077] in:
[0078] The monitoring unit 410 is used to start the Kubernetes informer to monitor the application configuration resource data with a specified label in the specified namespace.
[0079] The configuration resource acquisition unit 420 is used to acquire the application configuration resource data when the application configuration resource changes.
[0080] The decoding and writing unit 430 is used to decode the application configuration resource data and write it into a configuration structure object.
[0081] The data processing unit 440 is used to call the custom interface method of the configuration structure object to perform default value filling, static checking, comparison checking, equivalence detection, data coverage and data improvement processing to obtain a processed configuration structure object.
[0082] The cache unit 450 is used to store the processed configuration structure object in a local cache.
[0083] The configuration field acquisition unit 460 is used to obtain the field value of the configuration structure object in the local cache through the Get method.
[0084] Preferably, Figure 5 As shown, the above-mentioned device also includes an injection unit 470, which is used to specify the namespace and label by injecting the Pod configuration environment variables when deployed in the Kubernetes cluster.
[0085] Preferably, Figure 5 As shown, the above device also includes a resource change ignoring unit 480, which is used to ignore the current application configuration resource change when writing the configuration structure object fails, the static check is illegal, the comparison check fails, and the equivalence check is invalid.
[0086] Preferably, Figure 6 As shown, the data processing unit 440 includes: a default value filling module 441, a static checking module 442, a comparison checking module 443, an equivalence checking module 444, a data coverage module 445 and a supplementary processing module 446, which are sequentially connected.
[0087] The default value filling module 441 is used to call the Default method of the configuration structure object, check the configuration structure object, and write the default value to the default field.
[0088] The static check module 442 is used to call the StaticValidate method of the configuration structure object to perform a static check on the configuration structure object.
[0089] The comparison and checking module 443 is used to call the Validate method of the cached configuration structure object, and pass in the new configuration structure object as a parameter, and compare and check the cached configuration structure object with the new configuration structure object.
[0090] The equivalence check module 444 is used to call the Equal method of the cached configuration structure object, and pass in the new configuration structure object as a parameter, and perform an equivalence check between the cached configuration structure object and the new configuration structure object.
[0091] The data overwriting module 445 is used to call the OverrideFrom method of the cached configuration structure object, and pass in the new configuration structure object as a parameter, and overwrite the received new configuration structure object into the cached configuration structure object.
[0092] The supplement processing module 446 is used to call the Complete method of the cached configuration structure object to perform additional data supplement processing on the configuration structure object.
[0093] Preferably, when the configuration field acquisition unit 460 acquires the field value of the configuration structure object in the local cache through the Get method, the read-write lock in the configuration structure is first read-locked, and the read lock is released before the corresponding value is acquired and returned through the Get method.
[0094] Preferably, when the data overwriting module 445 overwrites the received new configuration structure object into the cached configuration structure object, it first performs a write lock operation on the read-write lock in the configuration structure, and then performs a write lock release operation after the overwriting is completed.
[0095] Preferably, the above-mentioned application configuration resource data includes ConfigMap resource data, Secret resource data and custom resource data.
[0096] From the above technical solution, it can be seen that this application uses Kubernetes' native informer technology and a set of standard interfaces designed to achieve quasi-real-time monitoring and acquisition of application configurations, solve the problem of ConfigMap update synchronization delay, and at the same time improve the robustness of application configurations. In addition, this application also introduces a local caching mechanism to reduce unnecessary computing overhead, improve application performance, and is moderately invasive to third-party references. As long as the third-party reference implements the custom standard interface of this application, it can be seamlessly integrated into this patent solution to achieve dynamic loading and management of application configurations.
[0097] An embodiment of the present invention further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the above method is implemented when the processor executes the program.
[0098] An embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the above method are implemented.
[0099] An embodiment of the present invention further provides a computer program product, including a computer program / instruction, which implements the steps of the above method when the computer program / instruction is executed by a processor.
[0100] like Figure 7 As shown, the electronic device 600 may further include: a communication module 110, an input unit 120, an audio processor 130, a display 160, and a power supply 170. It is worth noting that the electronic device 600 does not necessarily have to include Figure 7 In addition, the electronic device 600 may also include Figure 7 For components not shown, reference may be made to the prior art.
[0101] like Figure 7 As shown, the central processor 100 is sometimes also referred to as a controller or an operation control, and may include a microprocessor or other processor devices and / or logic devices. The central processor 100 receives inputs and controls the operations of various components of the electronic device 600.
[0102] The memory 140 may be, for example, one or more of a cache, a flash memory, a hard drive, a removable medium, a volatile memory, a non-volatile memory or other suitable devices. The above-mentioned information related to the failure may be stored, and a program for executing the relevant information may also be stored. The CPU 100 may execute the program stored in the memory 140 to implement information storage or processing.
[0103] The input unit 120 provides input to the CPU 100. The input unit 120 is, for example, a key or a touch input device. The power supply 170 is used to provide power to the electronic device 600. The display 160 is used to display display objects such as images and text. The display may be, for example, an LCD display, but is not limited thereto.
[0104] The memory 140 may be a solid-state memory, such as a read-only memory (ROM), a random access memory (RAM), a SIM card, etc. It may also be a memory that saves information even when the power is off, can be selectively erased, and is provided with more data, examples of which are sometimes referred to as ERPOMs, etc. The memory 140 may also be some other type of device. The memory 140 includes a buffer memory 141 (sometimes referred to as a buffer). The memory 140 may include an application / function storage unit 142, which is used to store application programs and function programs or processes for executing the operation of the electronic device 600 through the central processor 100.
[0105] The memory 140 may also include a data storage unit 143 for storing data, such as contacts, digital data, pictures, sounds, and / or any other data used by the electronic device. The driver storage unit 144 of the memory 140 may include various drivers for communication functions of the electronic device and / or for executing other functions of the electronic device (such as messaging applications, address book applications, etc.).
[0106] The communication module 110 is a transmitter / receiver that transmits and receives signals via the antenna 111. The communication module 110 (transmitter / receiver) is coupled to the central processor 100 to provide input signals and receive output signals, which may be the same as the case of a conventional mobile communication terminal.
[0107] Based on different communication technologies, multiple communication modules 110 may be provided in the same electronic device, such as a cellular network module, a Bluetooth module and / or a wireless LAN module. The communication module 110 (transmitter / receiver) is also coupled to a speaker 131 and a microphone 132 via an audio processor 130 to provide an audio output via the speaker 131 and receive an audio input from the microphone 132, thereby realizing a common telecommunication function. The audio processor 130 may include any suitable buffer, decoder, amplifier, etc. In addition, the audio processor 130 is also coupled to the central processor 100, so that recording can be performed on the local machine through the microphone 132, and the sound stored on the local machine can be played through the speaker 131.
[0108] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0109] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0110] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0111] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0112] The present invention uses specific embodiments to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A method for dynamic loading of application configuration based on Kubernetes, characterized in that: The method comprises: Start Kubernetes informer to monitor application configuration resource data with the specified label in the specified namespace; When the application configuration resource changes, obtaining the application configuration resource data; Decoding the application configuration resource data and writing it into a configuration structure object; Calling the custom interface method of the configuration structure object to perform default value filling, static check, comparison check, equivalence check, data coverage and data improvement processing to obtain a processed configuration structure object; Storing the processed configuration structure object in a local cache; Get the field values of the configuration structure object in the local cache through the Get method.
2. The Kubernetes-based application configuration dynamic loading method according to claim 1, characterized in that: Before starting the Kubernetes informer to monitor the application configuration resource data with the specified label in the specified namespace, the method further includes: When deployed in a Kubernetes cluster, the namespace and label are specified by injecting Pod configuration environment variables.
3. The Kubernetes-based application configuration dynamic loading method according to claim 1, characterized in that: The method further includes: when writing the configuration structure object fails, the static check is illegal, the comparison check fails, and the equivalence check is invalid, then ignoring the current application configuration resource change.
4. The Kubernetes-based application configuration dynamic loading method according to claim 1, characterized in that: The calling of the custom interface method of the configuration structure object to perform default value filling, static checking, comparison checking, equivalence checking, data coverage and data improvement processing includes: Call the Default method of the configuration structure object, check the configuration structure object, and write default values to the default fields; Call the StaticValidate method of the configuration structure object to perform a static check on the configuration structure object; Call the Validate method of the cached configuration structure object, pass in the new configuration structure object as a parameter, and compare and check the cached configuration structure object with the new configuration structure object; Call the Equal method of the cached configuration structure object, and pass the new configuration structure object as a parameter, and perform an equivalence check between the cached configuration structure object and the new configuration structure object; Call the OverrideFrom method of the cached configuration structure object and pass the new configuration structure object as a parameter to overwrite the received new configuration structure object with the cached configuration structure object; Call the Complete method of the cached configuration structure object to perform additional data supplementation on the configuration structure object.
5. The Kubernetes-based application configuration dynamic loading method according to claim 4, characterized in that: When the field value of the configuration structure object in the local cache is obtained by the Get method, the read-write lock in the configuration structure is first read-locked, and the read lock is released before the corresponding value is obtained and returned by the Get method.
6. The Kubernetes-based application configuration dynamic loading method according to claim 4, characterized in that: When the received new configuration structure object is overwritten into the cached configuration structure object, a write lock operation is first performed on the read-write lock in the configuration structure, and when the overwriting is completed, a write lock release operation is performed.
7. According to the Kubernetes-based application configuration dynamic loading method as described in claim 1, the application configuration resource data includes ConfigMap resource data, Secret resource data and custom resource data.
8. A Kubernetes-based application configuration dynamic loading device, characterized in that: The device comprises: The monitoring unit is used to start the Kubernetes informer to monitor the application configuration resource data with the specified label in the specified namespace; A configuration resource acquisition unit, used to acquire the application configuration resource data when the application configuration resource changes; A decoding and writing unit, used for decoding the application configuration resource data and writing it into a configuration structure object; A data processing unit, used to call the custom interface method of the configuration structure object to perform default value filling, static check, comparison check, equivalence check, data coverage and data improvement processing to obtain a processed configuration structure object; A cache unit, used to store the processed configuration structure object in a local cache; The configuration field acquisition unit is used to obtain the field value of the configuration structure object in the local cache through the Get method.
9. The Kubernetes-based application configuration dynamic loading device according to claim 8, characterized in that: The device also includes: The injection unit is used to specify the namespace and label by injecting the Pod configuration environment variables when deployed in the Kubernetes cluster.
10. The Kubernetes-based application configuration dynamic loading device according to claim 8, characterized in that: The device also includes: The resource change ignoring unit is used to ignore the resource changes of the current application configuration when the writing of the configuration structure object fails, the static check is illegal, the comparison check fails, and the equivalence check is invalid.
11. The Kubernetes-based application configuration dynamic loading device according to claim 8, characterized in that: The data processing unit comprises: A default value filling module is used to call the Default method of the configuration structure object, check the configuration structure object, and write the default value to the default field; A static check module, used to call the StaticValidate method of the configuration structure object to perform a static check on the configuration structure object; A comparison and checking module, used to call the Validate method of the cached configuration structure object, and pass in the new configuration structure object as a parameter, and compare and check the cached configuration structure object with the new configuration structure object; An equivalence check module, used to call the Equal method of the cached configuration structure object, and pass in the new configuration structure object as a parameter, and perform an equivalence check between the cached configuration structure object and the new configuration structure object; The data overwriting module is used to call the OverrideFrom method of the cached configuration structure object, and pass in the new configuration structure object as a parameter, and overwrite the received new configuration structure object into the cached configuration structure object; The supplement processing module is used to call the Complete method of the cached configuration structure object to perform additional data supplement processing on the configuration structure object.
12. The Kubernetes-based application configuration dynamic loading device according to claim 11, characterized in that: When the configuration field acquisition unit obtains the field value of the configuration structure object in the local cache through the Get method, the read-write lock in the configuration structure is first read-locked, and before the corresponding value is obtained and returned through the Get method, the read lock is released.
13. The Kubernetes-based application configuration dynamic loading device according to claim 11, characterized in that: When the data overwriting module overwrites the received new configuration structure object into the cached configuration structure object, it first performs a write lock operation on the read-write lock in the configuration structure, and then performs a write lock release operation after the overwriting is completed.
14. According to the Kubernetes-based application configuration dynamic loading device as described in claim 8, the application configuration resource data includes ConfigMap resource data, Secret resource data and custom resource data.
15. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
16. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
17. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Kubernetes configuration dynamic variation injection method based on context awareness
CN122195583A
A context-aware based Kubernetes configuration dynamic mutation injection method
CN122195583B