Configuration method and device based on Kubernetes container

By using adapters in Kubernetes containers to save configuration files to ConfigMap and implement dynamic updates and automatic injections, the flexibility and performance issues of configuration management in container environments are solved, and the shortcomings of log management are solved through custom log output.

CN120045280APending Publication Date: 2025-05-27中国邮政储蓄银行股份有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510087821.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-20
Publication Date
2025-05-27

AI Technical Summary

Technical Problem

In the prior art, the method of obtaining configuration of container environments cannot take into account performance problems such as flexibility, network latency, compatibility, dynamic updates, and automatic injection, and the log output of container environments cannot be customized.

Method used

Dynamic updates and automatic injection of configurations are achieved by using an adapter in a Kubernetes container to save the initial configuration file to ConfigMap and storing the configuration file to the target path of the container through a ConfigMap mount. At the same time, use the hostpath mount method to customize log output.

Benefits of technology

It realizes efficient and flexible configuration management in a container environment, supports dynamic updates and automatic injection, avoids network latency issues, and custom log output meets the needs of multiple environments and situations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120045280A_ABST
    Figure CN120045280A_ABST
Patent Text Reader

Abstract

The invention provides a configuration method and device based on a Kubernetes container, and the method comprises the steps: storing an initial configuration file in a ConfigMap through an adapter, and storing the initial configuration file in a first target path of the Kubernetes container through ConfigMap mounting; under the condition that the initial configuration file in the ConfigMap is updated, correspondingly updating the initial configuration file under the first target path to obtain an updated configuration file; and running the target service in the Kubernetes container by adopting the update configuration file. According to the method, a configuration adapter is combined with ConfigMap in a container environment, and a configuration function is realized in each container. When the service instance accesses the configuration, an external network is not needed, the configuration only needs to be obtained from the local path of the container environment, and when the configuration is changed, the service instance can monitor and update the memory configuration in real time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of software configuration. Specifically, it relates to a configuration method based on Kubernetes containers, a configuration device based on Kubernetes containers, a computer-readable storage medium, and an electronic device. Background Art

[0002] Currently, there are many methods for obtaining configurations in a container environment, but their advantages cannot be effectively balanced. The method based on environment variables has poor flexibility; the method based on an open-source software configuration center is affected by network latency when accessing configurations across regions, and has a high usage cost; the method based on an API gateway increases coupling, lacks flexibility, and has security risks; the method based on a storage volume mount has functional defects. In most cases, the running logs of services in a container environment are output in a native manner. However, native logs can only be output to a specified external path of a container with a specific name, and the access permissions of the logs cannot be standardized, which brings a lot of inconvenience to users. Summary of the Invention

[0003] The main purpose of this application is to provide a configuration method based on Kubernetes containers, a configuration device based on Kubernetes containers, a computer-readable storage medium, and an electronic device, so as to at least solve the problem that the methods for obtaining configurations in the existing container environment cannot balance performance such as flexibility, network latency, compatibility, dynamic update, and automatic injection.

[0004] To achieve the above object, according to one aspect of this application, a configuration method based on Kubernetes containers is provided, including: using an adapter to save an initial configuration file to a ConfigMap, and storing the initial configuration file to a first target path of a Kubernetes container through ConfigMap mounting; in the case where the initial configuration file in the ConfigMap is updated, correspondingly updating the initial configuration file under the first target path to obtain an updated configuration file; using the updated configuration file to run a target service in the Kubernetes container.

[0005] Optionally, before updating the initial configuration file in the ConfigMap and correspondingly updating the initial configuration file under the first target path to obtain an updated configuration file, the method further includes: setting the running environment of the target service in the environment variables of the Kubernetes container; running the target service using the running environment of the target service and the initial configuration file; starting a configuration file listener, and using the configuration file listener to monitor the status of the initial configuration file in the first target path in real time; the method further includes: when the configuration file listener monitors that the initial configuration file under the first target path is updated to the updated configuration file, updating the memory and cache.

[0006] Optionally, running the target service in the Kubernetes container using the updated configuration file includes: monitoring the configuration file under the first target path in the Kubernetes container in real time, and obtaining relevant operations of the configuration file, where the relevant operations include at least one of the following: addition operation, deletion operation, modification operation; when the initial configuration file under the first target path is updated to the updated configuration file, obtaining updated configuration parameters of the updated configuration file, where the updated configuration parameters include at least: updated configuration name, updated configuration data, and updated file path; creating an updated event instance and publishing the updated event instance according to the updated configuration name, updated configuration data, and updated file path of the updated configuration file.

[0007] Optionally, after obtaining the updated configuration parameters of the updated configuration file, the method further includes: creating an updated data source instance and a running instance according to the updated configuration data of the updated configuration file, where the updated data source instance includes the updated configuration data of the updated configuration file, and the updated data source instance corresponds to the running instance; reloading the configuration in the running instance according to the updated data source instance to replace the initial configuration data in the running instance with the updated configuration data in the updated data source instance; updating the configuration in the memory, and deleting the original running instance.

[0008] Optionally, the method further includes: naming the log files in the Kubernetes container to obtain the names of the log files, where the names correspond to the log files one by one, and at least one of the log files corresponds to one target service; determining the log viewing permissions of the user, where the log viewing permissions include the names of the log files that the user can view; storing the log viewing permissions of the user, and mounting all the log files in the Kubernetes container to a second target path outside the Kubernetes container through the hostpath mounting method.

[0009] Optionally, naming the log files in the Kubernetes container to obtain the names of the log files, including: setting the naming method of the log files, the naming method being LOG_${POD_NAME}, where ${POD_NAME} is the name of the started pod; storing the ${POD_NAME} corresponding to each log file in the environment variables of the Kubernetes container; obtaining the ${POD_NAME} corresponding to each log file from the environment variables, and naming the log files in the Kubernetes container according to the corresponding ${POD_NAME} to obtain the names of the log files.

[0010] Optionally, determining the log viewing permissions of users, including: specifying groups and group users using the Dockerfile component of the Kubernetes container, and specifying the log viewing permissions of specific users; determining the log viewing permissions of users by specifying groups and group users through the securityContext field using the yaml deployment file.

[0011] According to another aspect of the present application, there is provided a configuration device based on a Kubernetes container, including: a storage unit, configured to save an initial configuration file to a ConfigMap using an adapter, and store the initial configuration file to a first target path of the Kubernetes container through ConfigMap mounting; an update unit, configured to update the initial configuration file under the first target path correspondingly when the initial configuration file in the ConfigMap is updated, to obtain an updated configuration file; a running unit, configured to run a target service in the Kubernetes container using the updated configuration file.

[0012] According to another aspect of the present application, there is provided a computer-readable storage medium, the computer-readable storage medium including a stored program, wherein when the program runs, it controls the device where the computer-readable storage medium is located to execute any one of the configuration methods based on a Kubernetes container.

[0013] According to another aspect of the present application, there is provided an electronic device, including: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs include those for executing any one of the configuration methods based on a Kubernetes container.

[0014] Applying the technical solution of the present application, for the above-mentioned configuration method based on Kubernetes containers, first, an adapter is used to save the initial configuration file to the ConfigMap, and the initial configuration file is stored in the first target path of the Kubernetes container through ConfigMap mounting; then, in the case where the initial configuration file in the ConfigMap is updated, the initial configuration file in the first target path is correspondingly updated to obtain an updated configuration file; finally, the target service in the Kubernetes container is run using the updated configuration file. This method combines the configuration adapter with the ConfigMap in the container environment to implement the configuration center function in each container. When a service instance accesses the configuration, it only needs to obtain the configuration from the local path of the container environment. When the configuration changes, the service instance can listen and update the memory configuration in real time. Through the configuration adapter, the configuration can be accessed without an external network, ensuring flexibility while making the access more efficient and convenient. At the same time, the present invention customizes the log output configuration and can customize the output log, solving the problem that the existing methods for obtaining configurations in the container environment cannot balance performance such as flexibility, network latency, compatibility, dynamic update, and automatic injection. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] The specification drawings forming a part of the present application are used to provide a further understanding of the present application. The schematic embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation to the present application. In the drawings:

[0016] Figure 1 The hardware structure block diagram of a mobile terminal for executing a configuration method based on Kubernetes containers provided in an embodiment of the present application is shown;

[0017] Figure 2 The flowchart of a configuration method based on Kubernetes containers provided in an embodiment of the present application is shown;

[0018] Figure 3 The flowchart of another configuration method based on Kubernetes containers provided in an embodiment of the present application is shown;

[0019] Figure 4 The flowchart of another configuration method based on Kubernetes containers provided in an embodiment of the present application is shown;

[0020] Figure 5 The flowchart of a custom log collection within a container provided in an embodiment of the present application is shown;

[0021] Figure 6The block diagram of a configuration device based on Kubernetes containers provided according to an embodiment of the present application is shown.

[0022] Among them, the above-mentioned drawings include the following reference numerals:

[0023] 102. Processor; 104. Memory; 106. Transmission device; 108. Input / output device. Detailed implementation manners

[0024] It should be noted that, without conflict, the embodiments in the present application and the features in the embodiments may be combined with each other. The present application will be described in detail below with reference to the drawings and in combination with the embodiments.

[0025] In order to enable those skilled in the art to better understand the solutions of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without making creative efforts shall fall within the protection scope of the present application.

[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and do not have to be used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances so as to describe the embodiments of the present application here. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device including a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.

[0027] For the convenience of description, some nouns or terms related to the embodiments of the present application are described below:

[0028] ConfigMap: ConfigMap is an API object provided by Kubernetes for storing non-confidential configuration data. ConfigMap can be used to store fine-grained information such as a single property value, or coarse-grained information such as an entire configuration file or JSON blobs.

[0029] As introduced in the background art, currently in the container environment, there are the following four mainstream ways to obtain configurations in the industry:

[0030] 1). Inject the configuration into the container in the form of environment variables;

[0031] 2) Use open-source software configuration center services such as Nacos. Save the configuration in the software and obtain the configuration by accessing the configuration center in the software;

[0032] 3) Use the API gateway to centrally manage service configurations. As an intermediary for services to communicate with the outside world, the gateway can inject configuration information before forwarding requests.

[0033] 4) Mount it into the container environment in the way of Volume (storage volume) and obtain the configuration by reading files.

[0034] In the above solutions, Solution 1 is simple and easy to use, but in scenarios where the configuration needs to be dynamically changed, it is not flexible enough. The new environment variable values can only be obtained after the container is restarted; Solution 2 brings convenience and integration, but increases the dependence on open-source software, and may face migration costs and compatibility issues during migration. At the same time, problems such as network latency when obtaining the configuration will affect performance; the configuration management function provided by the API gateway in Solution 3 is not powerful enough and has poor flexibility; although Solution 4 can read the configuration, it cannot implement functions such as dynamic configuration update and priority automatic injection of configurations.

[0035] Currently, in the container environment, the Kubernetes native method is usually used to save the log files in the container to the host. However, the name and save path of the log files saved in the native method are fixed, and the groups and group users for viewing the logs cannot be customized. The native log saving method of Kubernetes cannot meet special requirements.

[0036] Currently, there are mainly four ways to obtain configurations in the container environment: one is based on environment variables, one is based on open-source software, one is based on the API gateway, and one is to mount it into the container environment in the way of Volume (storage volume); in the container environment, the native method is usually used to output the logs to the host outside the container, and the output path, output naming, permissions, etc. cannot be customized.

[0037] In addition, there are mainly three application solutions for saving configurations using ConfigMap in the existing solutions: 1. Use ConfigMap and Secret to save configuration files and perform basic format verification; 2. Integrate nginx with ConfigMap to implement dynamic routing functions; 3. Save helm templates through ConfigMap.

[0038] The above Application Solution 1 only saves the configuration in the container and does not implement the functions of priority automatic injection of configurations and configuration hot update; Application Solution 2 only implements nginx dynamic routing and cannot be applied to multiple scenarios; Application Solution 3 saves the helm template to ConfigMap.

[0039] Currently, there are many methods to obtain configurations in the container environment, but their advantages cannot be effectively balanced. The method based on environment variables has poor flexibility; when using the method based on the open-source software configuration center to access configurations across regions, it is affected by network latency and has a high usage cost; the method based on the API gateway increases coupling, lacks flexibility and has security risks; the method based on storage volumes has functional defects in mounting. In most cases, the running logs of services in the container environment are output in a native manner. However, the native logs can only be output to a specified external path of the container with a specific name, and the access permissions of the logs cannot be standardized, which brings a lot of inconvenience to users.

[0040] To solve the problem that the existing methods for obtaining configurations in the container environment cannot balance performance such as flexibility, network latency, compatibility, dynamic update, and automatic injection, embodiments of the present application provide a configuration method based on Kubernetes containers, a configuration device based on Kubernetes containers, a computer-readable storage medium, and an electronic device.

[0041] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described with reference to the accompanying drawings in the embodiments of the present invention.

[0042] The method embodiments provided in the embodiments of the present application can be executed on a mobile terminal, a computer terminal, or a similar computing device. Taking the execution on a mobile terminal as an example, Figure 1 is a hardware structure block diagram of a mobile terminal for a configuration method based on Kubernetes containers according to an embodiment of the present invention. As Figure 1 shown, the mobile terminal may include one or more ( Figure 1 only one is shown in Figure 1 a processor 102 (the processor 102 may include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data. Among them, the above mobile terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those of ordinary skill in the art can understand that Figure 1 the structure shown in Figure 1 is only schematic and does not limit the structure of the above mobile terminal. For example, the mobile terminal may further include more or fewer components than those shown in

[0043] The memory 104 can be used to store computer programs, such as software programs and modules of application software, such as the computer program corresponding to the configuration method based on Kubernetes containers in the embodiments of the present invention. The processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, that is, implements the above-mentioned method. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memories. In some instances, the memory 104 may further include a memory remotely disposed relative to the processor 102, and these remote memories may be connected to the mobile terminal through a network. Examples of the above-mentioned network include but are not limited to the Internet, enterprise intranet, local area network, mobile communication network, and combinations thereof. The transmission device 106 is used to receive or send data via a network. Specific examples of the above-mentioned network may include the wireless network provided by the communication provider of the mobile terminal. In one instance, the transmission device 106 includes a network adapter (Network Interface Controller, abbreviated as NIC), which can be connected to other network devices through a base station and thus can communicate with the Internet. In one instance, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0044] In this embodiment, a configuration method based on Kubernetes containers running on a mobile terminal, a computer terminal, or a similar computing device is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.

[0045] Figure 2 It is a flowchart of a configuration method based on Kubernetes containers according to an embodiment of the present application. As Figure 2 shown, the method includes the following steps:

[0046] Step S201, save the initial configuration file to the ConfigMap using an adapter, and store the above initial configuration file under the first target path of the Kubernetes container through ConfigMap mounting;

[0047] Specifically, the adapter provides the hot update function of the Kubernetes container, and the Kubernetes container provides a running environment for the service. The adapter combines with the ConfigMap to obtain the configuration from the local environment of the container, realizes functions such as automatic configuration injection and configuration hot update, and has the characteristics of safety, high efficiency, and convenience.

[0048] Wherein, when the above initial configuration file in the ConfigMap is updated, before updating the above initial configuration file in the above first target path to obtain an updated configuration file, the above method further includes the following steps:

[0049] Step S301, set the running environment of the above target service in the environment variables of the Kubernetes container;

[0050] Step S302, run the above target service using the running environment of the above target service and the above initial configuration file;

[0051] Step S303, start a configuration file listener, and use the above configuration file listener to monitor the status of the above initial configuration file in the above first target path in real time;

[0052] Specifically, under the container environment, configurations are loaded according to different environments and automatically injected with the highest priority. When the service starts, the service running environment (such as T1, SIT1, DEV, etc.) is added to the environment variables. The adapter first reads the running environment and loads the configuration file under the specified environment to achieve isolation of the configuration running environment. At the same time, the adapter automatically loads the configuration file with the highest priority to achieve injection before all Bean instances are instantiated, ensuring the correct operation of the service.

[0053] Step S202, when the above initial configuration file in the ConfigMap is updated, update the above initial configuration file in the above first target path correspondingly to obtain an updated configuration file;

[0054] Specifically, the dynamic hot update function of the configuration under the container environment. When the service starts running, various configurations can be read from the configuration file. During the running process of the service, if the configuration needs to be changed, after modifying the content of the configuration file in the ConfigMap, it is updated to all container environments. After the adapter rereads the configuration, the memory and cache are updated respectively to achieve the dynamic hot update function without restarting the service.

[0055] Wherein, the above method further includes: when the above configuration file listener monitors that the above initial configuration file in the above first target path is updated to the above updated configuration file, update the memory and cache.

[0056] Specifically, this can monitor the modification of the container environment configuration file in real time and solve the problems of poor flexibility in obtaining configurations in the container environment, unstable performance, and poor security.

[0057] Step S203, run the target service in the Kubernetes container using the above updated configuration file.

[0058] Specifically, integrate the adapter with the ConfigMap, and achieve a smooth migration of configuration items from the traditional configuration center to the ConfigMap through the adapter, ensuring the consistency and efficiency of configuration management in the cloud-native environment, and realizing functions such as automatic configuration injection into memory, configuration management, and configuration hot update. At the same time, the adapter mounts the log outside the container in the way of hostpath mounting to achieve custom log output, meeting the requirements of multiple environments and situations.

[0059] In some instances, such as Figure 3 shown, the working process of the configuration adapter is described as follows:

[0060] (1) Save the configuration file to the ConfigMap; through the ConfigMap mount, store the configuration file in the specified path of the container;

[0061] (2) Set the service running environment in the environment variables;

[0062] (3) The service starts normally, reads the running environment in the environment variables, and loads the relevant configuration according to the running environment; start the configuration file listener to monitor the modification of the container environment configuration file in real time;

[0063] (4) Modify the configuration file in the ConfigMap; the ConfigMap updates the modification to the container environment and modifies the configuration file in the specified path of the container;

[0064] (5) The file listener monitors the modification of the configuration file in the container, reads the updated configuration, and updates the memory and cache;

[0065] (6) During the execution of the service, send a request to obtain the configuration and get the modified configuration.

[0066] Among them, running the target service in the Kubernetes container by adopting the above method for updating the configuration file includes the following steps:

[0067] Step S2031, monitor the configuration file in the above-mentioned first target path in the Kubernetes container in real time, and obtain the relevant operations of the above-mentioned configuration file. The above-mentioned relevant operations include at least one of the following: add operation, delete operation, and modify operation;

[0068] Step S2032, when the above-mentioned initial configuration file in the above-mentioned first target path is updated to the above-mentioned updated configuration file, obtain the updated configuration parameters of the above-mentioned updated configuration file. The above-mentioned updated configuration parameters include at least: updated configuration name, updated configuration data, and updated file path;

[0069] Step S2033: Create a new update event instance and publish the new update event instance according to the update configuration name, update configuration data, and update file path of the above update configuration file.

[0070] Specifically, in the container environment, configurations are loaded according to different environments and automatically injected with the highest priority. When the service starts, the service running environment (such as T1, SIT1, DEV, etc.) is added to the environment variables. The adapter first reads the running environment and loads the configuration file in the specified environment to achieve isolation of the configuration running environment. At the same time, the adapter automatically loads the configuration file with the highest priority to inject it before all Bean instances are instantiated, ensuring the correct operation of the service.

[0071] After obtaining the update configuration parameters of the above update configuration file, the above method further includes the following steps:

[0072] Step S301: Create a new update data source instance and a running instance according to the update configuration data of the above update configuration file. The above update data source instance includes the update configuration data of the above update configuration file, and the above update data source instance corresponds to the above running instance;

[0073] Step S302: Reload the configurations in the above running instance according to the above update data source instance to replace the initial configuration data in the above running instance with the above update configuration data in the above update data source instance;

[0074] Step S303: Update the configurations in the memory and delete the original running instance.

[0075] Specifically, it is integrated with ConfigMap, and the adapter is used to achieve a smooth migration of traditional configuration center configuration items to ConfigMap, ensuring the consistency and efficiency of configuration management in the cloud native environment, and realizing functions such as automatic injection of configurations into memory, configuration management, and configuration hot update. At the same time, the adapter mounts the logs outside the container in the way of hostpath to achieve custom log output, meeting the requirements of multiple environments and multiple situations.

[0076] As Figure 4 shown, the container environment configuration hot update process specifically includes:

[0077] (1). Listen to the configuration files in the container in real time and capture operations such as addition, deletion, and modification of configuration files;

[0078] (2). After the configuration is modified, obtain the configuration name and file path; pass the name and parameters to step (4);

[0079] (3). According to the listening result, create a new update event instance and publish it;

[0080] (4) Pass in the parameters according to step (2), add a data source instance and a running instance, and the running instance reloads the configuration according to the data source instance;

[0081] (5) Update the configuration in memory and delete the cache.

[0082] Among them, the above method further includes the following steps:

[0083] Step S401, name the log files in the Kubernetes container to obtain the names of the above log files, and the above names correspond one-to-one with the above log files, and at least one of the above log files corresponds to one of the above target services;

[0084] Among them, naming the log files in the Kubernetes container to obtain the names of the above log files includes the following steps:

[0085] Step S4011, set the naming method of the above log files, and the above naming method is LOG_${POD_NAME}, where ${POD_NAME} is the name of the started pod;

[0086] Step S4012, store the ${POD_NAME} corresponding to each of the above log files in the environment variables of the Kubernetes container;

[0087] Step S4013, obtain the ${POD_NAME} corresponding to each of the above log files from the above environment variables, and name the above log files in the Kubernetes container according to the corresponding ${POD_NAME} to obtain the names of the above log files.

[0088] Specifically, the container environment customizes the log output. The adapter provides custom log configuration, and can customize the log output path outside the container, the log output name, the log group permission and the user permission, and can modify the log configuration according to different requirements.

[0089] For example, one instance may correspond to multiple logs. To distinguish these multiple logs, the logs can be named separately by pod. Since the pod is unique, the multiple logs corresponding to one instance can be distinguished according to the pod name.

[0090] Step S402, determine the user's log viewing permission, and the above log viewing permission includes the names of the above log files that the above user can view;

[0091] Among them, determining the user's log viewing permission includes the following steps:

[0092] Step S4021: Use the Dockerfile component of Kubernetes containers to specify groups and group users, and specify the log viewing permissions for specific users.

[0093] Step S4022: Use the yaml deployment file to specify groups and group users through the securityContext field, and determine the log viewing permissions of users.

[0094] Specifically, the adapter uses the environment variables in the container and the hostpath mounting method to customize the output name and path of the log file, thereby solving the problems in the prior art that the container logs cannot be customized in terms of output path and output log file name, and the viewing permissions of the logs in the specified path cannot be set.

[0095] Step S403: Store the log viewing permissions of the above users, and mount all the above log files in the Kubernetes container to the second target path outside the Kubernetes container through the hostpath mounting method.

[0096] Specifically, through a new type of adapter, the functions of the configuration center are implemented in the container environment, including functions such as configuration priority injection and configuration hot update. At the same time, the adapter can accurately distinguish the configuration files for different environments; in the present invention, the log files are customarily saved through the new type of adapter, no longer limited to the native storage method of Kubernetes, thereby improving the flexibility of log saving and the convenience of viewing.

[0097] As Figure 5 shown, the custom collection process of the logs in the container is as follows:

[0098] (1) Specify the naming method of the log file, name it as LOG_${POD_NAME}, where ${POD_NAME} is the name of the started pod, inject it into the environment variable, and ${POD_NAME} is unique.

[0099] (2) Modify the log configuration file, obtain ${POD_NAME} from the environment variable, and name the log file after splicing.

[0100] (3) Specify groups and group users in the Dockerfile, and specify the log viewing permissions for specific users.

[0101] (4) The yaml deployment file specifies groups and group users through the securityContext field.

[0102] (5) Mount the logs in the container to the specified path outside the container through the hostpath mounting method to achieve custom log operations.

[0103] Since the container environment of the prior art cannot directly use ConfigMap to implement the functions of a traditional configuration center. Although ConfigMap can save configuration files, the service cannot directly inject the configuration into the container, resulting in the service instance being unable to directly obtain the configuration from memory, and the coding of the traditional environment cannot meet the container environment. When the configuration file is modified, the running service cannot obtain the latest configuration, which brings difficulties to the migration of the traditional environment. At the same time, in the container environment, logs can only be output to a specified path outside the container in a native manner, and the usage permissions and naming of the logs cannot be customized.

[0104] The configuration method based on Kubernetes containers of the present application first uses an adapter to save the initial configuration file to ConfigMap, and stores the initial configuration file to the first target path of the Kubernetes container through ConfigMap mounting; then, in the case of the initial configuration file in ConfigMap being updated, the initial configuration file under the first target path is correspondingly updated to obtain an updated configuration file; finally, the target service in the Kubernetes container is run using the updated configuration file. This method combines the configuration adapter with ConfigMap in the container environment to implement the configuration center function in each container. When the service instance accesses the configuration, it only needs to obtain the configuration from the local path of the container environment. When the configuration changes, the service instance can listen and update the memory configuration in real time. Through the configuration adapter, the configuration can be accessed without an external network, ensuring flexibility while making the access more efficient and convenient. At the same time, the present invention customizes the log output configuration and can customize the output logs, solving the problem that the methods for obtaining configurations in the container environment of the prior art cannot balance performance such as flexibility, network latency, compatibility, dynamic update, and automatic injection.

[0105] The embodiment of the present application also provides a configuration device based on Kubernetes containers. It should be noted that the configuration device based on Kubernetes containers in the embodiment of the present application can be used to execute the configuration method based on Kubernetes containers provided in the embodiment of the present application. This device is used to implement the above-mentioned embodiments and preferred implementation manners, and those that have been described will not be repeated. As used hereinafter, the term "module" can be a combination of software and / or hardware that can achieve a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation in hardware, or a combination of software and hardware is also possible and contemplated.

[0106] The following introduces the configuration device based on Kubernetes containers provided in the embodiment of the present application.

[0107] Figure 6It is a schematic diagram of a configuration device based on Kubernetes containers according to an embodiment of the present application. As Figure 6 shown, the device includes a storage unit 10, an update unit 20, and a running unit 30. The storage unit 10 is configured to save an initial configuration file to a ConfigMap using an adapter, and store the initial configuration file under a first target path of a Kubernetes container through ConfigMap mounting; the update unit 20 is configured to correspondingly update the initial configuration file under the first target path to obtain an updated configuration file when the initial configuration file in the ConfigMap is updated; the running unit 30 is configured to run a target service in the Kubernetes container using the updated configuration file.

[0108] The configuration device based on Kubernetes containers of the present application includes a storage unit, an update unit, and a running unit. The storage unit is configured to save an initial configuration file to a ConfigMap using an adapter, and store the initial configuration file under a first target path of a Kubernetes container through ConfigMap mounting; the update unit is configured to correspondingly update the initial configuration file under the first target path to obtain an updated configuration file when the initial configuration file in the ConfigMap is updated; the running unit is configured to run a target service in the Kubernetes container using the updated configuration file. By combining a configuration adapter with a ConfigMap in a container environment, the device realizes the configuration center function in each container. When a service instance accesses the configuration, it only needs to obtain the configuration from the local path of the container environment. When the configuration changes, the service instance can listen and update the in-memory configuration in real time. Through the configuration adapter, the configuration can be accessed without an external network, ensuring flexibility while making the access more efficient and convenient. At the same time, the present invention customizes the log output configuration and can customize the output of logs, solving the problem that the method of obtaining configuration in the existing container environment cannot balance performance such as flexibility, network latency, compatibility, dynamic update, and automatic injection.

[0109] In some embodiments, the above device further includes a first processing module, a first running module, and a first monitoring module. The first processing module is configured to, when the above initial configuration file in the ConfigMap is updated, correspondingly update the above initial configuration file under the above first target path, and before obtaining the updated configuration file, set the running environment of the above target service in the environment variables of the Kubernetes container; the first running module is configured to run the above target service using the running environment of the above target service and the above initial configuration file; the first monitoring module is configured to start a configuration file monitor and use the above configuration file monitor to monitor the status of the above initial configuration file in the above first target path in real time; the above device further includes a first update module, configured to update the memory and cache when the above configuration file monitor monitors that the above initial configuration file under the above first target path is updated to the above updated configuration file. This can monitor the modification of the container environment configuration file in real time, and solve the problems of poor flexibility in obtaining the configuration of the container environment, unstable performance, and poor security.

[0110] In some embodiments, the running unit includes a second monitoring module, a first obtaining module, and a first creating module. The second monitoring module is configured to monitor the configuration file under the above first target path in the Kubernetes container in real time and obtain the related operations of the above configuration file. The above related operations include at least one of the following: an adding operation, a deleting operation, and a modifying operation; the first obtaining module is configured to obtain the updated configuration parameters of the above updated configuration file when the above initial configuration file under the above first target path is updated to the above updated configuration file. The above updated configuration parameters include at least: an updated configuration name, updated configuration data, and an updated file path; the first creating module is configured to create an update event instance and publish the above update event instance according to the updated configuration name, updated configuration data, and updated file path of the above updated configuration file. At the same time, the adapter automatically loads the configuration file with the highest priority and injects it before all Bean instances are instantiated to ensure the correct operation of the service.

[0111] In some embodiments, the above-mentioned device further includes a second new module, a first update module, and a second update module. The second new module is configured to, after obtaining the update configuration parameters of the above-mentioned update configuration file, create an update data source instance and a running instance according to the update configuration data of the above-mentioned update configuration file. The above-mentioned update data source instance includes the update configuration data of the above-mentioned update configuration file, and the above-mentioned update data source instance corresponds to the above-mentioned running instance. The first update module is configured to reload the configuration in the above-mentioned running instance according to the above-mentioned update data source instance, so as to replace the initial configuration data in the above-mentioned running instance with the above-mentioned update configuration data in the above-mentioned update data source instance. The second update module is configured to update the configuration in the memory and delete the original running instance. This ensures the consistency and efficiency of configuration management in the cloud-native environment and realizes functions such as automatic configuration injection into memory, configuration management, and configuration hot update.

[0112] In some embodiments, the above-mentioned device further includes a naming module, a first determination module, and a mounting module. The naming module is configured to name the log files in the Kubernetes container to obtain the names of the above-mentioned log files, and the above-mentioned names correspond to the above-mentioned log files one by one. At least one of the above-mentioned log files corresponds to one of the above-mentioned target services. The first determination module is configured to determine the user's log viewing permission, and the above-mentioned log viewing permission includes the names of the above-mentioned log files that the user can view. The mounting module is configured to store the above-mentioned user's log viewing permission and mount all the above-mentioned log files in the Kubernetes container to a second target path outside the Kubernetes container by means of hostpath mounting. The adapter mounts the logs outside the container in the way of hostpath mounting to achieve custom log output and meet the requirements of multiple environments and situations.

[0113] In some embodiments, the naming module includes a setting module, a storage module, and a naming sub-module. The setting module is configured to set the naming method of the above-mentioned log files, and the above-mentioned naming method is LOG_${POD_NAME}, where ${POD_NAME} is the name of the started pod. The storage module is configured to store the ${POD_NAME} corresponding to each of the above-mentioned log files in the environment variables of the Kubernetes container. The naming sub-module is configured to obtain the ${POD_NAME} corresponding to each of the above-mentioned log files from the above-mentioned environment variables and name the above-mentioned log files in the Kubernetes container according to the corresponding ${POD_NAME} to obtain the names of the above-mentioned log files. The log configuration can be modified according to different requirements.

[0114] In some embodiments, the first determination module includes a second processing module and a second determination module. The second processing module is used to specify a group and group users using the Dockerfile component of the Kubernetes container, and specify the log viewing permission for specific users. The second determination module is used to specify a group and group users through the securityContext field using the yaml deployment file, and determine the log viewing permission of the user. This solves the problems in the prior art that the container log cannot customize the output path, the output log file name, and cannot set the viewing permission for the log under the specified path.

[0115] The above-mentioned configuration device based on Kubernetes containers includes a processor and a memory. The above-mentioned storage units and the like are all stored in the memory as program units, and the corresponding functions are implemented by the processor executing the above-mentioned program units stored in the memory. The above-mentioned modules are all located in the same processor; or, the above-mentioned each module is located in different processors in any combined form.

[0116] The processor contains a kernel, and the kernel retrieves the corresponding program unit from the memory. One or more kernels can be set, and by adjusting the kernel parameters, the problems in the prior art that the method for obtaining configurations in the container environment cannot balance performance such as flexibility, network latency, compatibility, dynamic update, and automatic injection are solved.

[0117] The memory may include non-permanent memory in a computer-readable medium, forms such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash memory (flash RAM), and the memory includes at least one storage chip.

[0118] An embodiment of the present invention provides a computer-readable storage medium. The above-mentioned computer-readable storage medium includes a stored program. When the above-mentioned program runs, it controls the device where the above-mentioned computer-readable storage medium is located to execute the above-mentioned configuration method based on Kubernetes containers.

[0119] Specifically, the configuration method based on Kubernetes containers includes:

[0120] Step S201, use an adapter to save the initial configuration file to the ConfigMap, and store the above-mentioned initial configuration file under the first target path of the Kubernetes container through ConfigMap mounting;

[0121] Specifically, the adapter provides the hot update function of the Kubernetes container, and the Kubernetes container provides a running environment for the service. The adapter combines with the ConfigMap to obtain configurations from the local environment of the container, and realizes functions such as automatic configuration injection and configuration hot update, and has the characteristics of security, high efficiency, and convenience.

[0122] Step S202: When the above initial configuration file in the ConfigMap is updated, update the above initial configuration file under the above first target path correspondingly to obtain an updated configuration file.

[0123] Specifically, a dynamic hot update function is configured in the container environment. When the service starts running, various configurations can be read from the configuration file. During the running process of the service, if the configuration needs to be changed, after modifying the content of the configuration file in the ConfigMap, it is updated to all container environments. After the adapter rereads the configuration, it updates the memory and cache respectively, realizing the dynamic hot update function without restarting the service.

[0124] Step S203: Run the target service in the Kubernetes container by using the above updated configuration file.

[0125] Specifically, the adapter is integrated with the ConfigMap, and the smooth migration of configuration items from the traditional configuration center to the ConfigMap is realized through the adapter, ensuring the consistency and efficiency of configuration management in the cloud native environment, and realizing functions such as automatic configuration injection into memory, configuration management, and configuration hot update. At the same time, the adapter mounts the log outside the container in the way of hostpath mounting to realize custom log output, meeting the requirements of multiple environments and multiple situations.

[0126] Optionally, before updating the above initial configuration file under the above first target path correspondingly to obtain an updated configuration file when the above initial configuration file in the ConfigMap is updated, the above method further includes: setting the running environment of the above target service in the environment variables of the Kubernetes container; running the above target service by using the running environment of the above target service and the above initial configuration file; starting a configuration file listener, and using the above configuration file listener to monitor the status of the above initial configuration file in the above first target path in real time; the above method further includes: when the above configuration file listener monitors that the above initial configuration file under the above first target path is updated to the above updated configuration file, updating the memory and cache.

[0127] Optionally, running the target service in the Kubernetes container using the above update configuration file includes: listening in real time to the configuration file in the above first target path in the Kubernetes container, and obtaining relevant operations on the above configuration file, where the above relevant operations include at least one of the following: addition operation, deletion operation, modification operation; when the above initial configuration file in the above first target path is updated to the above update configuration file, obtaining the update configuration parameters of the above update configuration file, where the above update configuration parameters include at least: update configuration name, update configuration data, and update file path; according to the update configuration name, update configuration data, and update file path of the above update configuration file, creating an update event instance and publishing the above update event instance.

[0128] Optionally, after obtaining the update configuration parameters of the above update configuration file, the above method further includes: creating an update data source instance and a running instance according to the update configuration data of the above update configuration file, where the above update data source instance includes the update configuration data of the above update configuration file, and the above update data source instance corresponds to the above running instance; reloading the configuration in the above running instance according to the above update data source instance to replace the initial configuration data in the above running instance with the above update configuration data in the above update data source instance; updating the configuration in the memory and deleting the original running instance.

[0129] Optionally, the above method further includes: naming the log files in the Kubernetes container to obtain the names of the above log files, where the above names correspond one-to-one to the above log files, and at least one of the above log files corresponds to one of the above target services; determining the log viewing permission of the user, where the above log viewing permission includes the names of the above log files that the above user can view; storing the above log viewing permission of the user, and mounting all the above log files in the Kubernetes container to the second target path outside the Kubernetes container through the hostpath mounting method.

[0130] Optionally, naming the log files in the Kubernetes container to obtain the names of the above log files includes: setting the naming method of the above log files, where the above naming method is LOG_${POD_NAME}, where ${POD_NAME} is the name of the started pod; storing the ${POD_NAME} corresponding to each of the above log files in the environment variables of the Kubernetes container; obtaining the ${POD_NAME} corresponding to each of the above log files from the above environment variables, and naming the above log files in the Kubernetes container according to the corresponding ${POD_NAME} to obtain the names of the above log files.

[0131] Optionally, determine the user's log viewing permission, including: specifying groups and group users using the Dockerfile component of the Kubernetes container, and specifying the log viewing permission for specific users; specifying groups and group users through the securityContext field using the yaml deployment file to determine the user's log viewing permission.

[0132] An embodiment of the present invention provides a processor, which is used to run a program. When the program runs, the above-mentioned configuration method based on the Kubernetes container is executed.

[0133] An embodiment of the present invention provides a device, which includes a processor, a memory, and a program stored on the memory and executable on the processor. When the processor executes the program, at least the following steps are implemented:

[0134] Step S201, use an adapter to save the initial configuration file to the ConfigMap, and store the initial configuration file under the first target path of the Kubernetes container through the ConfigMap mount;

[0135] Step S202, when the initial configuration file in the ConfigMap is updated, correspondingly update the initial configuration file under the first target path to obtain an updated configuration file;

[0136] Step S203, run the target service in the Kubernetes container using the updated configuration file.

[0137] The device in this article can be a server, a PC, a PAD, a mobile phone, etc.

[0138] Optionally, before updating the initial configuration file under the first target path to obtain an updated configuration file when the initial configuration file in the ConfigMap is updated, the method further includes: setting the running environment of the target service in the environment variables of the Kubernetes container; running the target service using the running environment of the target service and the initial configuration file; starting a configuration file listener, and using the configuration file listener to monitor the status of the initial configuration file in the first target path in real time; the method further includes: when the configuration file listener monitors that the initial configuration file under the first target path is updated to the updated configuration file, updating the memory and cache.

[0139] Optionally, running the target service in the Kubernetes container with the above updated configuration file includes: listening in real time to the configuration file in the above first target path in the Kubernetes container, obtaining relevant operations on the above configuration file, and the above relevant operations include at least one of the following: addition operation, deletion operation, modification operation; when the above initial configuration file in the above first target path is updated to the above updated configuration file, obtaining the updated configuration parameters of the above updated configuration file, and the above updated configuration parameters include at least: updated configuration name, updated configuration data, and updated file path; according to the updated configuration name, updated configuration data, and updated file path of the above updated configuration file, creating an updated event instance and publishing the above updated event instance.

[0140] Optionally, after obtaining the updated configuration parameters of the above updated configuration file, the above method further includes: creating an updated data source instance and a running instance according to the updated configuration data of the above updated configuration file, the above updated data source instance includes the updated configuration data of the above updated configuration file, and the above updated data source instance corresponds to the above running instance; reloading the configuration in the above running instance according to the above updated data source instance to replace the initial configuration data in the above running instance with the above updated configuration data in the above updated data source instance; updating the configuration in the memory and deleting the original running instance.

[0141] Optionally, the above method further includes: naming the log files in the Kubernetes container to obtain the names of the above log files, the above names corresponding one-to-one to the above log files, and at least one of the above log files corresponding to one of the above target services; determining the log viewing permissions of the user, the above log viewing permissions including the names of the above log files that the user can view; storing the above log viewing permissions of the user, and mounting all the above log files in the Kubernetes container to the second target path outside the Kubernetes container by means of hostpath mounting.

[0142] Optionally, naming the log files in the Kubernetes container to obtain the names of the above log files includes: setting the naming method of the above log files, the above naming method being LOG_${POD_NAME}, where ${POD_NAME} is the name of the started pod; storing the ${POD_NAME} corresponding to each of the above log files in the environment variables of the Kubernetes container; obtaining the ${POD_NAME} corresponding to each of the above log files from the above environment variables, and naming the above log files in the Kubernetes container according to the corresponding ${POD_NAME} to obtain the names of the above log files.

[0143] Optionally, determine the user's log viewing permission, including: specifying groups and group users using the Dockerfile component of the Kubernetes container, and specifying the log viewing permission for specific users; specifying groups and group users through the securityContext field using the yaml deployment file to determine the user's log viewing permission.

[0144] The present application also provides a computer program product, which when executed on a data processing device, is adapted to execute a program initialized with at least the following method steps:

[0145] Step S201, save the initial configuration file to the ConfigMap using an adapter, and store the above initial configuration file under the first target path of the Kubernetes container through ConfigMap mounting;

[0146] Step S202, in the case where the above initial configuration file in the ConfigMap is updated, correspondingly update the above initial configuration file under the above first target path to obtain an updated configuration file;

[0147] Step S203, run the target service in the Kubernetes container using the above updated configuration file.

[0148] Optionally, before correspondingly updating the above initial configuration file under the above first target path to obtain an updated configuration file in the case where the above initial configuration file in the ConfigMap is updated, the above method further includes: setting the running environment of the above target service in the environment variables of the Kubernetes container; running the above target service using the running environment of the above target service and the above initial configuration file; starting a configuration file listener, and using the above configuration file listener to continuously monitor the status of the above initial configuration file in the above first target path; the above method further includes: updating the memory and cache in the case where the above configuration file listener monitors that the above initial configuration file under the above first target path is updated to the above updated configuration file.

[0149] Optionally, running the target service in the Kubernetes container with the above updated configuration file includes: listening in real time to the configuration file in the above first target path in the Kubernetes container, obtaining relevant operations on the above configuration file, and the above relevant operations include at least one of the following: addition operation, deletion operation, modification operation; when the above initial configuration file in the above first target path is updated to the above updated configuration file, obtaining the updated configuration parameters of the above updated configuration file, and the above updated configuration parameters include at least: updated configuration name, updated configuration data, and updated file path; according to the updated configuration name, updated configuration data, and updated file path of the above updated configuration file, creating an updated event instance and publishing the above updated event instance.

[0150] Optionally, after obtaining the updated configuration parameters of the above updated configuration file, the above method further includes: creating an updated data source instance and a running instance according to the updated configuration data of the above updated configuration file, the above updated data source instance includes the updated configuration data of the above updated configuration file, and the above updated data source instance corresponds to the above running instance; reloading the configuration in the above running instance according to the above updated data source instance to replace the initial configuration data in the above running instance with the above updated configuration data in the above updated data source instance; updating the configuration in the memory and deleting the original running instance.

[0151] Optionally, the above method further includes: naming the log files in the Kubernetes container to obtain the names of the above log files, the above names corresponding one-to-one to the above log files, and at least one of the above log files corresponding to one of the above target services; determining the log viewing permissions of the user, the above log viewing permissions including the names of the above log files that the user can view; storing the above log viewing permissions of the user, and mounting all the above log files in the Kubernetes container to the second target path outside the Kubernetes container through the hostpath mounting method.

[0152] Optionally, naming the log files in the Kubernetes container to obtain the names of the above log files includes: setting the naming method of the above log files, the above naming method being LOG_${POD_NAME}, where ${POD_NAME} is the name of the started pod; storing the ${POD_NAME} corresponding to each of the above log files in the environment variables of the Kubernetes container; obtaining the ${POD_NAME} corresponding to each of the above log files from the above environment variables, and naming the above log files in the Kubernetes container according to the corresponding ${POD_NAME} to obtain the names of the above log files.

[0153] Optionally, determine the user's log viewing permissions, including: specifying groups and group users using the Dockerfile component of the Kubernetes container, and specifying the log viewing permissions for specific users; specifying groups and group users through the securityContext field using the yaml deployment file to determine the user's log viewing permissions.

[0154] Obviously, those skilled in the art should understand that the above-mentioned modules or steps of the present invention can be implemented by a general-purpose computing device. They can be concentrated on a single computing device or distributed on a network composed of multiple computing devices. They can be implemented by program codes executable by the computing device. Thus, they can be stored in a storage device and executed by the computing device. And in some cases, the steps shown or described herein can be executed in a different order, or they can be separately fabricated into individual integrated circuit modules, or multiple modules or steps among them can be fabricated into a single integrated circuit module for implementation. In this way, the present invention is not limited to any specific combination of hardware and software.

[0155] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can 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 codes.

[0156] The present application is described with reference to the flowcharts and / or block diagrams of methods, apparatuses (systems), and computer program products according to the embodiments of the present application. It should be understood that each flow and / or block in the flowchart and / or block diagram, and the combination of flows 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 the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate a device for implementing the functions specified in Figure 1 one or more flows and / or blocks Figure 1 one or more blocks.

[0157] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory generate a manufactured article including an instruction device, and the instruction device implements the functions specified in Figure 1 one or more flows and / or blocks Figure 1The functions specified in one or more boxes.

[0158] These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process. Thus, the instructions executed on the computer or other programmable device provide for implementing the steps of the functions specified in one Figure 1 one process or more processes and / or boxes Figure 1 step of the functions specified in one or more boxes.

[0159] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.

[0160] The memory may include non-permanent memory in the computer-readable medium, in the form of random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash memory (flash RAM). The memory is an example of a computer-readable medium.

[0161] Computer-readable media includes permanent and non-permanent, removable and non-removable media and can store information by any method or technology. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, disk storage or other magnetic storage devices, or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media, such as modulated data signals and carrier waves.

[0162] It should also be noted that the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, commodity or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, commodity or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, commodity or device comprising the element.

[0163] As can be seen from the above description, the above embodiments of the present application achieve the following technical effects:

[0164] 1), The configuration method based on Kubernetes containers in the present application first uses an adapter to save the initial configuration file to ConfigMap and stores the initial configuration file to the first target path of the Kubernetes container through ConfigMap mounting; then, when the initial configuration file in ConfigMap is updated, the initial configuration file under the first target path is correspondingly updated to obtain an updated configuration file; finally, the target service in the Kubernetes container is run using the updated configuration file. This method combines the configuration adapter with ConfigMap in the container environment to implement the configuration center function in each container. When a service instance accesses the configuration, it only needs to obtain the configuration from the local path of the container environment. When the configuration changes, the service instance can listen and update the memory configuration in real time. Through the configuration adapter, the configuration can be accessed without an external network, ensuring flexibility while making the access more efficient and convenient. At the same time, the present invention customizes the log output configuration and can customize the output of logs, solving the problem that the methods for obtaining configurations in the existing container environment cannot balance performance such as flexibility, network latency, compatibility, dynamic update, and automatic injection.

[0165] 2), The configuration device based on Kubernetes containers in the present application includes a storage unit, an update unit, and a running unit. The storage unit is used to save the initial configuration file to ConfigMap using an adapter and store the initial configuration file to the first target path of the Kubernetes container through ConfigMap mounting; the update unit is used to correspondingly update the initial configuration file under the first target path to obtain an updated configuration file when the initial configuration file in ConfigMap is updated; the running unit is used to run the target service in the Kubernetes container using the updated configuration file. This device combines the configuration adapter with ConfigMap in the container environment to implement the configuration center function in each container. When a service instance accesses the configuration, it only needs to obtain the configuration from the local path of the container environment. When the configuration changes, the service instance can listen and update the memory configuration in real time. Through the configuration adapter, the configuration can be accessed without an external network, ensuring flexibility while making the access more efficient and convenient. At the same time, the present invention customizes the log output configuration and can customize the output of logs, solving the problem that the methods for obtaining configurations in the existing container environment cannot balance performance such as flexibility, network latency, compatibility, dynamic update, and automatic injection.

[0166] The above are only the preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, various changes and modifications can be made to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the protection scope of the present application.

Claims

1. A configuration method based on Kubernetes containers, characterized in that: include: Use an adapter to save the initial configuration file to ConfigMap, and store the initial configuration file in the first target path of the Kubernetes container through ConfigMap mounting; When the initial configuration file in ConfigMap is updated, the initial configuration file under the first target path is updated accordingly to obtain an updated configuration file; Run the target service in the Kubernetes container using the updated configuration file.

2. The method according to claim 1, characterized in that In the case where the initial configuration file in the ConfigMap is updated, the initial configuration file under the first target path is updated accordingly, and before obtaining the updated configuration file, the method further includes: setting the operating environment of the target service in the environment variables of the Kubernetes container; running the target service using the operating environment of the target service and the initial configuration file; starting a configuration file listener, and using the configuration file listener to monitor the status of the initial configuration file in the first target path in real time; The method further includes: updating the memory and cache when the configuration file listener monitors that the initial configuration file under the first target path is updated to the updated configuration file.

3. The method according to claim 1, characterized in that Use the updated configuration file to run the target service in the Kubernetes container, including: Monitor the configuration file under the first target path in the Kubernetes container in real time, and obtain related operations of the configuration file, where the related operations include at least one of the following: adding operation, deleting operation, and modifying operation; When the initial configuration file under the first target path is updated to the updated configuration file, acquiring update configuration parameters of the updated configuration file, the update configuration parameters at least including: an update configuration name, update configuration data and an update file path; According to the update configuration name, update configuration data and update file path of the update configuration file, a new update event instance is created and the update event instance is published.

4. The method according to claim 3, characterized in that: After acquiring the update configuration parameters of the update configuration file, the method further includes: According to the update configuration data of the update configuration file, create a new update data source instance and a running instance, wherein the update data source instance includes the update configuration data of the update configuration file, and the update data source instance corresponds to the running instance; Reloading the configuration in the running instance according to the updated data source instance to replace the initial configuration data in the running instance with the updated configuration data in the updated data source instance; Updates the in-memory configuration and deletes the original running instance.

5. The method according to claim 1, characterized in that The method further comprises: Naming the log file in the Kubernetes container to obtain the name of the log file, where the name corresponds to the log file one by one, and at least one log file corresponds to one target service; Determining the log review authority of the user, wherein the log review authority includes the name of the log file that the user can review; The user's log review permissions are stored, and all the log files in the Kubernetes container are mounted to the second target path outside the Kubernetes container through the hostpath mounting method.

6. The method according to claim 5, characterized in that Name the log file in the Kubernetes container to obtain the name of the log file, including: Set the naming method of the log file to LOG_${POD_NAME}, where ${POD_NAME} is the name of the startup pod; Store the ${POD_NAME} corresponding to each of the log files in the environment variable of the Kubernetes container; The ${POD_NAME} corresponding to each of the log files is obtained from the environment variable, and the log file in the Kubernetes container is named according to the corresponding ${POD_NAME} to obtain the name of the log file.

7. The method according to claim 5, characterized in that Determine the user's log access permissions, including: Use the Dockerfile component of the Kubernetes container to specify groups and group users, and specify log viewing permissions for specific users; Use the YAML deployment file to specify groups and group users through the securityContext field to determine the user's log viewing permissions.

8. A configuration device based on Kubernetes container, characterized in that: include: A storage unit, used to save the initial configuration file into ConfigMap by using an adapter, and store the initial configuration file into a first target path of a Kubernetes container by mounting ConfigMap; An updating unit, configured to update the initial configuration file under the first target path accordingly when the initial configuration file in the ConfigMap is updated, so as to obtain an updated configuration file; The running unit is used to run the target service in the Kubernetes container using the updated configuration file.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein when the program is running, the device where the computer-readable storage medium is located is controlled to execute the Kubernetes container-based configuration method according to any one of claims 1 to 7.

10. An electronic device, characterized in that: include: One or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs include a method for executing the Kubernetes container-based configuration method described in any one of claims 1 to 7.