A tenant-level DNS configuration file update method and system based on K8S

By defining tenant-level DNS configuration file configmaps in K8S and dynamically updating the Pod's DNS configuration using DnsOperator, the problem of inefficient update efficiency of tenant-level DNS configuration in native K8S is solved, and automatic update and flexibility of tenant-level DNS configuration is achieved.

CN116074194BActive Publication Date: 2024-11-26CHINA TELECOM CLOUD TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202211720033.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-30
Publication Date
2024-11-26
Estimated Expiration
2042-12-30

AI Technical Summary

Technical Problem

Native K8S lacks tenant-level custom DNS service support in multi-tenant scenarios, and the Pod's DNS service configuration cannot be changed and modified without rebuilding the Pod, resulting in low efficiency in updating DNS configurations.

Method used

By defining the corresponding custom DNS configuration file configmaps for tenants and using DnsOperator to listen for the change events of configmaps, dynamically update the DNS configuration file content of all Pods under the tenant, realizing automatic update of tenant-level DNS configuration files.

Benefits of technology

It realizes automatic update of tenant-level DNS configuration files, avoids the need to artificially modify the DNS configuration files of each Pod, solves the problem that DNS configuration cannot be dynamically modified in native K8S, and improves the flexibility and management efficiency of DNS configuration.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116074194B_ABST
    Figure CN116074194B_ABST
Patent Text Reader

Abstract

The present invention discloses a tenant-level DNS configuration file updating method and system based on K8S, which relates to the K8S field. The method and system define custom DNS configuration files configmaps corresponding to each tenant, create a namespace for storing the configmaps corresponding to each tenant, add a workload DnsOperator, subscribe to the change events of the configmaps corresponding to each tenant in the namespace through the DnsOperator, and dynamically update the DNS configuration file content corresponding to all Pods under the tenant by using a preset correction module when changes in the configmaps are monitored, thereby realizing automatic update of the tenant-level DNS configuration file.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of K8S, and in particular to a tenant-level DNS configuration file updating method and system based on K8S. Background Art

[0002] K8S (Kubernetes) is an open source container cluster management system developed in Go language. It is used to manage containerized applications on multiple hosts in the cloud platform. The goal of K8S is to make the deployment of containerized applications simple and efficient. It provides a complete set of functions such as resource scheduling, deployment management, service discovery, capacity expansion and contraction, monitoring, and maintenance. K8S is an open source platform that can automatically implement container operations. It can help users save many manual deployment and expansion operations in the application containerization process. For cloud-native applications that require rapid expansion, K8S is an ideal hosting platform.

[0003] DNS (Domain Name System) is a distributed database on the Internet that maps domain names and IP addresses to each other. It allows users to access the Internet more conveniently without having to remember IP strings that can be directly read by machines. The process of obtaining the IP address corresponding to a host through a host name is called domain name resolution (or host name resolution). In a K8S cluster, the DNS service is an important mechanism for service discovery, providing basic functions for K8S: accessing services through service names within the cluster, completing the resolution from service names to IP addresses, and thus accessing each other.

[0004] Native K8S is a weak tenancy mechanism that only supports setting up DNS services at the cluster level or at the pod level. The above functions can generally be achieved through services such as CoreDNS integrated in K8S and / etc / resolv.conf in the pod, but lack support for custom DNS services at the tenant level. Therefore, in a multi-tenant scenario, if you want to customize DNS services at the tenant level, you need to use other special methods, and the DNS service configuration of the workload (Pod) in native K8S cannot be changed without rebuilding the Pod.

[0005] Specifically, when setting up the DNS service at the cluster level, it is not possible to flexibly modify the DNS configuration file at the tenant level. When setting up the DNS service at the Pod level, since one tenant corresponds to one or more Pods, and one Pod corresponds to one DNS configuration file, when making changes, it is necessary to modify the DNS configuration files corresponding to all Pods under the tenant one by one externally (manually). Therefore, the Pod needs to be restarted for the modified configuration file to take effect. Summary of the invention

[0006] In order to support the management and maintenance of each tenant's custom DNS configuration file at the unified entrance of the cluster, and realize the automatic update of the tenant-level DNS configuration file, that is, to realize the automatic update of the DNS configuration file content of all Pods under the tenant according to the custom DNS configuration file corresponding to the tenant, the present invention proposes a tenant-level DNS configuration file update method based on K8S, which is applied to the created tenant-level DNS configuration file revision program, and the revision program includes:

[0007] Create a module for defining custom DNS configuration files configmaps corresponding to each tenant, and create a namespace for storing the configmaps corresponding to each tenant; one tenant corresponds to one configmap;

[0008] The monitoring module is used to add a new workload DnsOperator, subscribe to the change events of the corresponding configmaps of each tenant through DnsOperator, and dynamically update the DNS configuration file content corresponding to all Pods under the tenant using the preset correction module when the configmaps are changed;

[0009] The method comprises the steps of:

[0010] S01: Initialize the Informer interface in K8S, and use the Informer interface to access the configmaps in the namespace through DnsOperator to monitor the change events in configmaps in real time;

[0011] S02: Determine whether the change event has changed. If so, obtain a change event list, in which one line of the change event list records one configmaps that has changed. Set the initial value of the variable h to 1, where h represents the current line number of the change event list.

[0012] S03: Get the configmaps corresponding to the current row number h, and get the Pod list of the tenant corresponding to the configmaps, where the Pod list includes all Pod resources of the tenant; set the initial value of the variable p to 1, where p represents the current row number of the Pod list;

[0013] S04: Determine whether the Pod list is empty. If so, jump to step S07; if not, proceed to the next step;

[0014] S05: Execute the preset correction module, in which the DNS configuration file content of the Pod corresponding to the current number p of rows in the Pod list under the tenant is modified through the latest content in configmaps and the dnsConfig and dnsPolicy configuration items defined in the K8S specification;

[0015] S06: Determine whether the variable p is greater than or equal to the total number of rows in the Pod list. If so, proceed to the next step; if not, add 1 to the variable p and return to step S05;

[0016] S07: Determine whether the variable h is greater than or equal to the total number of rows in the change event list. If so, return to step S02. If not, add 1 to the variable h and return to step S03.

[0017] Furthermore, the change event is a new addition event, an update event, or a deletion event.

[0018] Furthermore, the preset correction module specifically includes:

[0019] S51: Determine whether the configmaps corresponding to the current row number h is a new event or an update event. If so, update the DNS configuration file content of the Pod corresponding to the current row number p in the Pod list under the corresponding tenant to the latest content in the configmaps, and enter step S06. If not, enter the next step;

[0020] S52: Determine whether the configmaps corresponding to the current line number h is a deletion event. If so, update the DNS configuration file content of the Pod corresponding to the current line number p in the Pod list under the corresponding tenant through the dnsConfig and dnsPolicy configuration items defined in the K8S specification, and enter step S06. If not, jump to step S02.

[0021] Furthermore, the configmaps include: an upstream DNS server IP address, a list of DNS search domains, an object list, and a tenant ID identification number.

[0022] Furthermore, in the step S03, the Pod list of the tenant corresponding to the configmaps is obtained, specifically: all Pod resources corresponding to the tenant are obtained through the tenant ID identification number in the configmaps to obtain the Pod list; one tenant corresponds to one or more Pods.

[0023] Furthermore, the tenant ID identification number is a Label tag used to identify the Pod resources belonging to the tenant.

[0024] The present invention also proposes a tenant-level DNS configuration file update system based on K8S, which is applied to the created tenant-level DNS configuration file revision program, and the revision program includes:

[0025] Create a module for defining custom DNS configuration files configmaps corresponding to each tenant, and create a namespace for storing the configmaps corresponding to each tenant; one tenant corresponds to one configmap;

[0026] The monitoring module is used to add a new workload DnsOperator, subscribe to the change events of the corresponding configmaps of each tenant through DnsOperator, and dynamically update the DNS configuration file content corresponding to all Pods under the tenant using the preset correction module when the configmaps are changed;

[0027] The system comprises:

[0028] Initialization module, used to initialize the Informer interface in K8S, and use the Informer interface to access configmaps in the namespace through DnsOperator to monitor change events in configmaps in real time;

[0029] The change event list acquisition module is used to determine whether the change event has changed. If so, obtain the change event list, in which one line records one configmaps that has changed; the initial value of the variable h is 1, and h represents the current line number of the change event list;

[0030] The Pod list acquisition module is used to obtain the configmaps corresponding to the current row number h, and obtain the Pod list of the tenant corresponding to the configmaps, where the Pod list includes all Pod resources of the tenant; the initial value of the variable p is set to 1, and p represents the current row number of the Pod list;

[0031] The first judgment module is used to judge whether the Pod list is empty. If so, it jumps to the third judgment module; if not, it enters the automatic update module;

[0032] The automatic update module is used to execute the preset correction module. In the preset correction module, the DNS configuration file content of the Pod corresponding to the current number p of the Pod list under the tenant is modified through the latest content in configmaps and the dnsConfig and dnsPolicy configuration items defined in the K8S specification;

[0033] The second judgment module is used to judge whether the variable p is greater than or equal to the total number of rows in the Pod list. If so, the third judgment module is entered; if not, the variable p is increased by 1 and the automatic update module is returned;

[0034] The third judgment module is used to judge whether the variable h is greater than or equal to the total number of rows in the change event list. If so, it returns to the change event list acquisition module. If not, the variable h is increased by 1 and returns to the Pod list acquisition module.

[0035] Furthermore, the change event is a new addition event, an update event, or a deletion event.

[0036] Furthermore, the preset correction module specifically includes:

[0037] The first correction module is used to determine whether the configmaps corresponding to the current line number h is a new event or an update event. If so, the DNS configuration file content of the Pod corresponding to the current line number p in the Pod list under the corresponding tenant is updated to the latest content in the configmaps, and enter the second judgment module. If not, enter the second correction module;

[0038] The second correction module is used to determine whether the configmaps corresponding to the current line number h is a deletion event. If so, the DNS configuration file content of the Pod corresponding to the current line number p in the Pod list under the corresponding tenant is updated through the dnsConfig and dnsPolicy configuration items defined in the K8S specification, and enter the second judgment module. If not, jump to the change event list acquisition module.

[0039] Furthermore, the configmaps include: an upstream DNS server IP address, a list of DNS search domains, an object list, and a tenant ID identification number.

[0040] Compared with the prior art, the present invention has at least the following beneficial effects:

[0041] (1) The present invention defines a custom DNS configuration file configmaps corresponding to each tenant, creates a namespace for storing the configmaps corresponding to each tenant, adds a workload DnsOperator, subscribes to the change events of the configmaps corresponding to each tenant in the namespace through DnsOperator, and dynamically updates the DNS configuration file content corresponding to all Pods under the tenant using a preset correction module when changes to the configmaps are detected. This realizes the automatic update of the tenant-level DNS configuration file. Specifically, the present invention accesses the configmaps in the namespace through the Informer interface to monitor the change events in the configmaps in real time, and then intelligently updates the DNS configuration file content of all Pods under the tenant, thereby avoiding the problem that when setting the DNS service at the Pod granularity, the DNS configuration files corresponding to all Pods under the tenant need to be modified one by one externally (manually), and the problem that the DNS service configuration of the Pod in the native K8S cannot be changed without rebuilding the Pod.

[0042] (2) The tenant-level DNS configuration file update method proposed in the present invention realizes the automatic update of the tenant-level DNS configuration file, which solves the problem that the DNS service is set at the entire cluster level and the tenant-level DNS configuration file cannot be modified flexibly and targetedly. In addition, the customized DNS configuration files of each tenant are isolated from each other and do not conflict with each other.

[0043] (3) The present invention accesses the configmaps in the namespace through the Informer interface, thereby updating the content of the DNS configuration file corresponding to the Pod, thereby avoiding the problem in the prior art that the Pod needs to be restarted to make the modified configuration file effective. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] Figure 1 A flowchart of a tenant-level DNS configuration file update method based on K8S;

[0045] Figure 2 Updated the system module diagram for a tenant-level DNS configuration file based on K8S;

[0046] Figure 3 This is a flow chart of the DNS service for native K8S workloads (Pod) in the prior art. DETAILED DESCRIPTION

[0047] The following are specific embodiments of the present invention and the accompanying drawings to further describe the technical solution of the present invention, but the present invention is not limited to these embodiments.

[0048] Embodiment 1

[0049] In the prior art, the native K8S DNS service is described as follows:

[0050] like Figure 3 As shown, all containers in the workload (Pod) share the DNS resolution configuration created by the sandbox, namely the DNS configuration file (specifically the / etc / resolv.conf file, the same below). During the entire life cycle of the Pod, its DNS resolution configuration does not support dynamic modification after it is created by the sandbox. If any container in the Pod needs to use the DNS domain name service (a Pod includes at least two containers, one of which is the basic container sandbox; in addition, a Pod corresponds to a DNS configuration file), a domain name request will be made based on the content of the DNS configuration file inside the Pod. The DNS configuration file contains the IP address of the upstream DNS server. The latest version of K8S creates a Pod by default, and the upstream DNS server of its DNS resolution configuration is the CoreDNS server that comes with the K8S cluster.

[0051] The DNS configuration file contains three parts: nameservers, searches, and options. nameservers represents the IP address of the upstream DNS server used by the Pod for DNS domain name resolution. Up to 3 IP addresses can be specified, and the attribute is required. searches is a list of DNS search domains used to find host names in the Pod. The attribute is optional, and up to 6 search domains are allowed. Options is a list of objects with optional attributes. Each object has a name attribute (required) and a value attribute (optional).

[0052] The K8S workload (Pod) specification definition includes dnsPolicy and dnsConfig configuration items. The Pod sandbox generates the Pod's DNS configuration file content based on the contents of these two configuration items. dnsConfig also contains three parts: nameservers, searches, and options. The specific meanings are described above. Among them, dnsPolicy has four configurations:

[0053] 1. ClusterFirst: Use the DNS resolution configuration of the K8S cluster, which is the default setting. ClusterFirst will use the DNS server provided by the K8S cluster for resolution, and the cluster DNS resolution server IP address is specified by the "cluster-dns" parameter of kubelet (the latest version of K8S installs CoreDNS by default to provide DNS services).

[0054] 2.Default: Mount / etc / resolv.conf directly from the node to the Pod, that is, the Pod uses the same DNS domain name resolution service as the K8S Node node.

[0055] 3.ClusterFirstWithHostNet: Enables cluster DNS service when using hostNetwork network mode. It must be used with "hostNetwork: true" in the Pod specification.

[0056] 4.None: Do not load the DNS service of the K8S cluster. It must be used together with dnsConfig and set the DNS service according to the content of dnsConfig.

[0057] Insufficient points of native K8S DNS service:

[0058] 1. Unless the workload (Pod) is rebuilt, its DNS resolution configuration cannot be changed again.

[0059] 2. Only DNS services at the Pod and cluster levels are supported. The cluster does not have a unified entry to manage, maintain, and set up custom DNS services at the tenant level. The main ways to set up custom DNS services at the tenant level in native K8S are: (1) Manually modify the dnsConfig and dnsPolicy of each workload (Pod) of the tenant and rebuild the Pod, but this is usually a large workload and prone to errors and omissions. (2) Build a CoreDNS server (workload) and service for each tenant, and then each workload (Pod) of the tenant needs to explicitly specify the use of the built-in custom DNS server when creating it, and the currently created workload (Pod) needs to be rebuilt every time the built-in DNS service content is modified. As the number of tenants increases, the proportion of system resource consumption may increase dramatically.

[0060] In order to solve the above technical problems, the automatic update of tenant-level DNS configuration files is realized. Under the premise that the DNS configuration files of all pods corresponding to a tenant are the same, Figure 1 As shown, the present invention proposes a tenant-level DNS configuration file update method based on K8S, which is applied to the created tenant-level DNS configuration file revision program, and the revision program includes:

[0061] Create a module to define the custom DNS configuration files configmaps corresponding to each tenant, and create a namespace (tenantDnsOpt) for storing the configmaps corresponding to each tenant; one tenant corresponds to one configmap; (each tenant's custom DNS information consists of one configmaps definition);

[0062] It should be noted that, in the present invention, the cluster administrator uniformly manages and maintains (create / update / delete) the custom DNS configuration files configmaps of all tenants through the K8S external exposure interface (kubectl, etc.).

[0063] The configmaps include: the upstream DNS server IP address nameservers, the DNS search domain list searches, the object list options and the tenant ID identification number.

[0064] The tenant ID identification number is a Label tag used to identify the Pod resources to which the tenant belongs or a vpcId of a custom CR resource of a CNI plug-in that supports VPC, etc.

[0065] The monitoring module is used to add a new workload DnsOperator (multiple copies of DnsOperator running simultaneously can be added to ensure sufficient monitoring resources when there are many tenants). The DnsOperator subscribes to the change events of the configmaps corresponding to each tenant, and when the configmaps are changed, the preset correction module is used to dynamically update the DNS configuration file content corresponding to all Pods under the tenant.

[0066] The tenant-level DNS configuration file updating method proposed in the present invention realizes the automatic updating of the tenant-level DNS configuration file, solves the problem that the DNS service is set at the whole cluster level and the tenant-level DNS configuration file cannot be modified flexibly and targetedly, and the customized DNS configuration files of each tenant are isolated from each other and do not conflict.

[0067] The method comprises the steps of:

[0068] S01: Initialize the Informer interface in K8S, and use the Informer interface to access the configmaps in the namespace through DnsOperator to monitor the change events in configmaps in real time;

[0069] The present invention accesses configmaps in the namespace through an Informer interface, thereby updating the content of the DNS configuration file corresponding to the Pod, thereby avoiding the problem in the prior art that the Pod needs to be restarted to make the modified configuration file effective.

[0070] S02: Determine whether the change event has changed. If so, obtain a change event list, in which one line of the change event list records one configmaps that has changed. Set the initial value of the variable h to 1, where h represents the current line number of the change event list.

[0071] S03: Get the configmaps corresponding to the current row number h, and get the Pod list of the tenant corresponding to the configmaps, where the Pod list includes all Pod resources of the tenant; set the initial value of the variable p to 1, where p represents the current row number of the Pod list;

[0072] In the step S03, the Pod list of the tenant corresponding to the configmaps is obtained, specifically: all Pod resources corresponding to the tenant are obtained through the tenant ID identification number in the configmaps to obtain the Pod list; one tenant corresponds to one or more Pods.

[0073] S04: Determine whether the Pod list is empty. If so, jump to step S07; if not, proceed to the next step;

[0074] S05: Execute the preset correction module, in which the DNS configuration file content of the Pod corresponding to the current number p of rows in the Pod list under the tenant is modified through the latest content in configmaps and the dnsConfig and dnsPolicy configuration items defined in the K8S specification;

[0075] The change event is a new event, an update event, or a deletion event.

[0076] The preset correction module specifically includes:

[0077] S51: Determine whether the configmaps corresponding to the current row number h is a new event or an update event. If so, update the DNS configuration file content of the Pod corresponding to the current row number p in the Pod list under the corresponding tenant to the latest content in the configmaps, and enter step S06. If not, enter the next step;

[0078] S52: Determine whether the configmaps corresponding to the current line number h is a deletion event. If so, update the DNS configuration file content of the Pod corresponding to the current line number p in the Pod list under the corresponding tenant through the dnsConfig and dnsPolicy configuration items defined in the K8S specification, and enter step S06. If not, jump to step S02.

[0079] It should be noted that when it is a deletion event, it means that the tenant no longer needs a customized DNS configuration, so it is changed to the K8S default configuration information.

[0080] S06: Determine whether the variable p is greater than or equal to the total number of rows in the Pod list. If so, proceed to the next step; if not, add 1 to the variable p and return to step S05;

[0081] S07: Determine whether the variable h is greater than or equal to the total number of rows in the change event list. If so, return to step S02. If not, add 1 to the variable h and return to step S03.

[0082] The present invention defines a custom DNS configuration file configmaps corresponding to each tenant, creates a namespace for storing the configmaps corresponding to each tenant, adds a workload DnsOperator, subscribes to the change events of the configmaps corresponding to each tenant in the namespace through the DnsOperator, and dynamically updates the DNS configuration file content corresponding to all Pods under the tenant by using a preset correction module when changes in the configmaps are monitored, thereby realizing automatic update of the tenant-level DNS configuration file. Specifically, the present invention accesses the configmaps in the namespace through the Informer interface to monitor the change events in the configmaps in real time, and then intelligently updates the DNS configuration file content of all Pods under the tenant, thereby avoiding the problem that when the DNS service is set at the Pod granularity, the DNS configuration files corresponding to all Pods under the tenant need to be modified one by one externally (manually), and the problem that the DNS service configuration of the Pod in the native K8S cannot be changed or modified without rebuilding the Pod.

[0083] Embodiment 2

[0084] like Figure 2 As shown, the present invention also proposes a tenant-level DNS configuration file update system based on K8S, which is applied to the created tenant-level DNS configuration file revision program, and the revision program includes:

[0085] Create a module for defining custom DNS configuration files configmaps corresponding to each tenant, and create a namespace for storing the configmaps corresponding to each tenant; one tenant corresponds to one configmap;

[0086] The configmaps include: an upstream DNS server IP address, a list of DNS search domains, an object list, and a tenant ID identification number.

[0087] The monitoring module is used to add a new workload DnsOperator, subscribe to the change events of the corresponding configmaps of each tenant through DnsOperator, and dynamically update the DNS configuration file content corresponding to all Pods under the tenant using the preset correction module when the configmaps are changed;

[0088] The system comprises:

[0089] Initialization module, used to initialize the Informer interface in K8S, and use the Informer interface to access configmaps in the namespace through DnsOperator to monitor change events in configmaps in real time;

[0090] The change event list acquisition module is used to determine whether the change event has changed. If so, obtain the change event list, in which one line records one configmaps that has changed; the initial value of the variable h is 1, and h represents the current line number of the change event list;

[0091] The Pod list acquisition module is used to obtain the configmaps corresponding to the current row number h, and obtain the Pod list of the tenant corresponding to the configmaps, where the Pod list includes all Pod resources of the tenant; the initial value of the variable p is set to 1, and p represents the current row number of the Pod list;

[0092] The first judgment module is used to judge whether the Pod list is empty. If so, it jumps to the third judgment module; if not, it enters the automatic update module;

[0093] The automatic update module is used to execute the preset correction module. In the preset correction module, the DNS configuration file content of the Pod corresponding to the current number p of the Pod list under the tenant is modified through the latest content in configmaps and the dnsConfig and dnsPolicy configuration items defined in the K8S specification;

[0094] The change event is a new event, an update event, or a deletion event.

[0095] The preset correction module specifically includes:

[0096] The first correction module is used to determine whether the configmaps corresponding to the current line number h is a new event or an update event. If so, the DNS configuration file content of the Pod corresponding to the current line number p in the Pod list under the corresponding tenant is updated to the latest content in the configmaps, and enter the second judgment module. If not, enter the second correction module;

[0097] The second correction module is used to determine whether the configmaps corresponding to the current line number h is a deletion event. If so, the DNS configuration file content of the Pod corresponding to the current line number p in the Pod list under the corresponding tenant is updated through the dnsConfig and dnsPolicy configuration items defined in the K8S specification, and enter the second judgment module. If not, jump to the change event list acquisition module.

[0098] The second judgment module is used to judge whether the variable p is greater than or equal to the total number of rows in the Pod list. If so, the third judgment module is entered; if not, the variable p is increased by 1 and the automatic update module is returned;

[0099] The third judgment module is used to judge whether the variable h is greater than or equal to the total number of rows in the change event list. If so, it returns to the change event list acquisition module. If not, the variable h is increased by 1 and returns to the Pod list acquisition module.

[0100] It should be noted that all directional indications (such as up, down, left, right, front, back, etc.) in the embodiments of the present invention are only used to explain the relative position relationship, movement, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly. In addition, in the present invention, the descriptions such as "first", "second", "one", etc. are only used for descriptive purposes, and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In the description of the present invention, the meaning of "multiple" is at least two, such as two, three, etc., unless otherwise clearly defined. In the present invention, unless otherwise clearly defined and defined, the terms "connection", "fixation", etc. should be understood in a broad sense. For example, "fixation" can be a fixed connection, a detachable connection, or an integral body; it can be a mechanical connection or an electrical connection; it can be directly connected or indirectly connected through an intermediate medium, it can be the internal connection of two elements or the interaction relationship between two elements, unless otherwise clearly defined. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances. In addition, the technical solutions between the various embodiments of the present invention can be combined with each other, but it must be based on the ability of ordinary technicians in this field to implement. When the combination of technical solutions is contradictory or cannot be implemented, it should be considered that such a combination of technical solutions does not exist and is not within the protection scope required by the present invention.

Claims

1. A tenant-level DNS configuration file update method based on K8S, characterized in that: A tenant-level DNS configuration file revision procedure is applied to the creation of the following: Create a module for defining custom DNS configuration files configmaps corresponding to each tenant, and create a namespace for storing the configmaps corresponding to each tenant; one tenant corresponds to one configmap; The monitoring module is used to add a new workload DnsOperator, subscribe to the change events of the corresponding configmaps of each tenant through DnsOperator, and dynamically update the DNS configuration file content corresponding to all Pods under the tenant using the preset correction module when the configmaps are changed; The method comprises the steps of: S01: Initialize the Informer interface in K8S, and use the Informer interface to access the configmaps in the namespace through DnsOperator to monitor the change events in configmaps in real time; S02: Determine whether the change event has changed. If so, obtain a change event list, in which one line of the change event list records one configmaps that has changed. Set the initial value of the variable h to 1, where h represents the current line number of the change event list. S03: Get the configmaps corresponding to the current row number h, and get the Pod list of the tenant corresponding to the configmaps, where the Pod list includes all Pod resources of the tenant; set the initial value of the variable p to 1, where p represents the current row number of the Pod list; S04: Determine whether the Pod list is empty. If so, jump to step S07; if not, proceed to the next step; S05: Execute the preset correction module, in which the DNS configuration file content of the Pod corresponding to the current number p of the Pod list under the tenant is modified through the latest content in configmaps and the dnsConfig and dnsPolicy configuration items defined in the K8S specification; specifically including: S51: Determine whether the configmaps corresponding to the current row number h is a new event or an update event. If so, update the DNS configuration file content of the Pod corresponding to the current row number p in the Pod list under the corresponding tenant to the latest content in the configmaps, and enter step S06. If not, enter the next step; S52: Determine whether the configmaps corresponding to the current line number h is a deletion event. If so, update the DNS configuration file content of the Pod corresponding to the current line number p in the Pod list under the corresponding tenant through the dnsConfig and dnsPolicy configuration items defined in the K8S specification, and enter step S06. If not, jump to step S02; S06: Determine whether the variable p is greater than or equal to the total number of rows in the Pod list. If so, proceed to the next step; if not, add 1 to the variable p and return to step S05; S07: Determine whether the variable h is greater than or equal to the total number of rows in the change event list. If so, return to step S02. If not, add 1 to the variable h and return to step S03.

2. According to a K8S-based tenant-level DNS configuration file update method according to claim 1, it is characterized in that: The configmaps include: an upstream DNS server IP address, a list of DNS search domains, an object list, and a tenant ID identification number.

3. According to a K8S-based tenant-level DNS configuration file update method according to claim 2, it is characterized in that: In the step S03, the Pod list of the tenant corresponding to the configmaps is obtained, specifically: all Pod resources corresponding to the tenant are obtained through the tenant ID identification number in the configmaps to obtain the Pod list; one tenant corresponds to one or more Pods.

4. According to a K8S-based tenant-level DNS configuration file update method according to claim 2, it is characterized in that: The tenant ID is a label used to identify the Pod resources to which the tenant belongs.

5. A tenant-level DNS configuration file update system based on K8S, characterized in that: A tenant-level DNS configuration file revision procedure is applied to the creation of the following: Create a module for defining custom DNS configuration files configmaps corresponding to each tenant, and create a namespace for storing the configmaps corresponding to each tenant; one tenant corresponds to one configmap; The monitoring module is used to add a new workload DnsOperator, subscribe to the change events of the corresponding configmaps of each tenant through DnsOperator, and dynamically update the DNS configuration file content corresponding to all Pods under the tenant using the preset correction module when the configmaps are changed; specifically, it includes: The first correction module is used to determine whether the configmaps corresponding to the current line number h is a new event or an update event. If so, the DNS configuration file content of the Pod corresponding to the current line number p in the Pod list under the corresponding tenant is updated to the latest content in the configmaps, and enter the second judgment module. If not, enter the second correction module; The second correction module is used to determine whether the configmaps corresponding to the current line number h is a deletion event. If so, the DNS configuration file content of the Pod corresponding to the current line number p in the Pod list under the corresponding tenant is updated through the dnsConfig and dnsPolicy configuration items defined in the K8S specification, and enter the second judgment module. If not, jump to the change event list acquisition module; The system comprises: Initialization module, used to initialize the Informer interface in K8S, and use the Informer interface to access configmaps in the namespace through DnsOperator to monitor change events in configmaps in real time; The change event list acquisition module is used to determine whether the change event has changed. If so, the change event list is acquired. In the change event list, one line records one configmaps that has changed. The initial value of the variable h is 1, and h represents the current line number of the change event list. The Pod list acquisition module is used to obtain the configmaps corresponding to the current row number h, and obtain the Pod list of the tenant corresponding to the configmaps, where the Pod list includes all Pod resources of the tenant; the initial value of the variable p is set to 1, and p represents the current row number of the Pod list; The first judgment module is used to judge whether the Pod list is empty. If so, it jumps to the third judgment module; if not, it enters the automatic update module; The automatic update module is used to execute the preset correction module. In the preset correction module, the DNS configuration file content of the Pod corresponding to the current number of rows p in the Pod list under the tenant is modified through the latest content in configmaps and the dnsConfig and dnsPolicy configuration items defined in the K8S specification; The second judgment module is used to judge whether the variable p is greater than or equal to the total number of rows in the Pod list. If so, the third judgment module is entered; if not, the variable p is increased by 1 and the automatic update module is returned; The third judgment module is used to judge whether the variable h is greater than or equal to the total number of rows in the change event list. If so, it returns to the change event list acquisition module. If not, the variable h is increased by 1 and returns to the Pod list acquisition module.

6. According to a K8S-based tenant-level DNS configuration file update system according to claim 5, it is characterized in that: The configmaps include: an upstream DNS server IP address, a list of DNS search domains, an object list, and a tenant ID identification number.