Domain name resolution method and device, equipment, storage medium and product
By receiving and processing domain name resolution request packets for host network Pods in Kubernetes environment and converting addresses to point to CoreDNS servers, the problem that host network Pods cannot use CoreDNS domain name resolution is solved, and the domain name service function of smoothly using CoreDNS is realized, which is suitable for production environments.
Patent Information
- Application Number
- CN202411965706.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-11
AI Technical Summary
In Kubernetes environment, host network Pods cannot communicate with other applications through the domain name resolution function of CoreDNS server. Existing solutions require restarting the Pod or modifying the /etc/resolv.conf file one by one, affecting business continuity and cost.
By receiving the target domain name resolution request message sent by the target host network Pod, the destination and source addresses are converted to point to the CoreDNS server, the target application IP address is determined and sent to the Pod, so that it establishes a connection with the target application.
It realizes that without modifying the existing host network Pod, the host network Pod can immediately use the CoreDNS domain name service function, avoiding business interruptions and high modification costs, and is suitable for the actual production environment.
Smart Images

Figure CN119814725A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a domain name resolution method, device, equipment, storage medium and product. Background Art
[0002] In the Kubernetes environment, the CoreDNS server provides cluster-level domain name resolution services, which can communicate with other applications in the kubernetes cluster through domain names based on this service. For container network Pods based on CNI (Container Network Interface), kubelet will automatically modify its internal / etc / resolv.conf file and add the ClusterIP of the CoreDNS server to ensure that the container network Pod can access various services normally through domain names. However, the / etc / resolv.conf file of the host network Pod is usually inherited from the / etc / resolv.conf file of the node where the Pod is located, and the domain name resolution address in the / etc / resolv.conf file of the node may not be the ClusterIP of the CoreDNS server, which makes the host network Pod unable to communicate with other applications through domain names based on the domain name resolution function of the CoreDNS server.
[0003] In view of the above problems, the existing methods can be solved in the following two ways: one is to modify the node's / etc / resolv.conf file, add the CoreDNS server's ClusterIP, and then restart all host network Pods. After the restart, the Pod reuses the node's latest / etc / resolv.conf file, and the CoreDNS function can be used normally; the second is to enter all host network Pods one by one, modify their internal / etc / resolv.conf files, and add the CoreDNS server's ClusterIP, and then the CoreDNS function can be used normally. However, both of the above solutions have certain disadvantages. Method 1 requires restarting all host network Pods, which will affect the running business and cannot be handled smoothly; Method 2 requires modifying the / etc / resolv.conf file of each host network Pod, and the modification cost is relatively high. Therefore, how to enable the host network Pod to quickly use the CoreDNS domain name resolution service without making any changes to the existing host network Pod has become a technical problem that needs to be solved urgently. Summary of the invention
[0004] The present invention provides a domain name resolution method, device, equipment, storage medium and product, so as to enable the host network Pod to immediately use the domain name service function of CoreDNS without making any changes to the host network Pod, and at the same time be friendly to the actual production environment and have no impact on the business.
[0005] According to one aspect of the present invention, a domain name resolution method is provided, which is applied to a CoreDNS server in a cluster, and the method includes:
[0006] Receive the target domain name resolution request message sent by the target host network Pod after being processed by the first network address translation rule and the second network address translation rule respectively; wherein the first network address translation rule is used to convert the destination address of the domain name resolution request message to the designated IP address corresponding to the CoreDNS server when the destination address of the domain name resolution request message is a non-specified IP address; the second network address translation rule is used to convert the source address of the domain name resolution request message to the IP address of the network card sending the target message when the source address of the domain name resolution request message is a non-specified cluster container network segment;
[0007] Determine the corresponding target application IP address based on the target domain name resolution request message;
[0008] The target application IP address is sent to the target host network Pod, so that the target host network Pod establishes a connection with the target application based on the target application IP address.
[0009] According to another aspect of the present invention, a domain name resolution device is provided, which is applied to a CoreDNS server in a cluster, and the device includes:
[0010] A request message receiving module is used to receive a target domain name resolution request message sent by a target host network Pod and processed by a first network address translation rule and a second network address translation rule respectively; wherein the first network address translation rule is used to convert the destination address of the domain name resolution request message to a designated IP address corresponding to the CoreDNS server when the destination address of the domain name resolution request message is a non-specified IP address; the second network address translation rule is used to convert the source address of the domain name resolution request message to the IP address of the network card from which the target message is sent when the source address of the domain name resolution request message is a non-specified cluster container network segment;
[0011] A domain name resolution module, used to determine the corresponding target application IP address based on the target domain name resolution request message;
[0012] The address sending module is used to send the target application IP address to the target host network Pod, so that the target host network Pod establishes a connection with the target application based on the target application IP address.
[0013] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0014] at least one processor; and
[0015] a memory communicatively connected to the at least one processor; wherein,
[0016] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the domain name resolution method described in any embodiment of the present invention.
[0017] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the domain name resolution method described in any embodiment of the present invention when executed.
[0018] According to another aspect of the present invention, a computer program product is provided. The computer program product includes a computer program. When the computer program is executed by a processor, the domain name resolution method described in any embodiment of the present invention is implemented.
[0019] The technical solution of the embodiment of the present invention is applied to the CoreDNS server in the cluster, by receiving the target domain name resolution request message sent by the target host network Pod and processed by the first network address conversion rule and the second network address conversion rule respectively; wherein the first network address conversion rule is used to convert the destination address to the designated IP address corresponding to the CoreDNS server when the destination address of the domain name resolution request message is a non-specified IP address; the second network address conversion rule is used to convert the source address to the IP address of the network card sending the target message when the source address of the domain name resolution request message is a non-specified cluster container network segment; determine the corresponding target application IP address based on the target domain name resolution request message; send the target application IP address to the target host network Pod, so that the target host network Pod establishes a connection with the target application based on the target application IP address. This solution can achieve that the host network Pod can immediately use the domain name service function of CoreDNS without making any changes to the host network Pod, that is, smoothly use the domain name service function of CoreDNS, and is friendly to the actual production environment and has no impact on the business.
[0020] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0022] Figure 1 is a flowchart of a domain name resolution method provided according to Embodiment 1 of the present invention;
[0023] Figure 2 is a structural diagram of a domain name resolution device provided according to Embodiment 2 of the present invention;
[0024] Figure 3 It is a structural schematic diagram of an electronic device for implementing the domain name resolution method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0025] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0027] Embodiment 1
[0028] Figure 1 This is a flowchart of a domain name resolution method provided in the first embodiment of the present invention. This embodiment is applicable to the situation where the host network Pod can immediately use the domain name service function of CoreDNS without making any changes to the host network Pod. The method can be executed by a domain name resolution device, which can be implemented in the form of hardware and / or software, and the domain name resolution device can be configured in an electronic device. Figure 1 As shown, a domain name resolution method provided in the first embodiment is applied to a CoreDNS server in a cluster, and specifically includes the following steps:
[0029] S110, receiving the target domain name resolution request message sent by the target host network Pod after being processed by the first network address conversion rule and the second network address conversion rule respectively; wherein the first network address conversion rule is used to convert the destination address of the domain name resolution request message into the designated IP address corresponding to the CoreDNS server when the destination address of the domain name resolution request message is a non-specified IP address; the second network address conversion rule is used to convert the source address into the IP address of the network card sending the target message when the source address of the domain name resolution request message is a non-specified cluster container network segment.
[0030] The target host network Pod may refer to the host network Pod that sends the domain name resolution request message. When this type of Pod uses the host network, the containers in the Pod will share the host's network namespace, which means that the container will directly use the host's network interface and IP address instead of obtaining an independent IP address. This method allows containers to communicate directly with external networks, just like they run directly on the host. CoreDNS is a plug-in-driven DNS server written in Go that allows users to set up DNS services by writing simple configuration files.
[0031] The domain name resolution request message contains the domain name to be resolved corresponding to the target application. The domain name to be resolved may include but is not limited to: the service name and Pod name within the cluster, or the domain name outside the cluster.
[0032] The target application may refer to a target service or resource to be connected to the target host network Pod. The target application may include cluster internal and external applications, such as cluster internal and external services, cluster internal and external Pods, and cluster external applications.
[0033] Network Address Translation (NAT) is a network technology that allows rewriting the source IP address or destination IP address in a data packet passing through a network interface. NAT can include source address translation (SNAT) and destination address translation (DNAT).
[0034] The first network address translation (NAT) rule is used to convert the destination address of the domain name resolution request message into the designated IP address corresponding to the CoreDNS server when the destination address of the domain name resolution request message is a non-designated IP address, wherein the designated IP address may be the ClusterIP address corresponding to the CoreDNS server; specifically, the function of the first NAT rule is to redirect all domain name resolution request messages sent by the host network Pod whose destination IP address is not the ClusterIP address to the CoreDNS server.
[0035] The second network address translation (NAT) rule is used to convert the source address of the domain name resolution request message into the IP address of the network card sending the target message when the source address of the domain name resolution request message is a non-specified cluster container network segment, wherein the specified cluster container network segment may refer to the container network segment PodCIDR (Classless Inter Domain Routing) of the cluster where the CoreDNS server is located, and PodCIDR represents the network segment that allocates IP addresses to Pods in the cluster; the network card sending the target message may refer to the network device that sends the target domain name resolution request message; specifically, the role of the second NAT rule is to modify the source IP address of the outbound message to the IP address of the network card sending the target message, so as to ensure that the message processed by the CoreDNS server can be returned normally.
[0036] In an embodiment of the present invention, after the domain name resolution request message sent by the target host network Pod is processed by the first NAT rule and the second NAT rule respectively, the NAT-converted target domain name resolution request message will be sent to the CoreDNS server in the same cluster, so that the subsequent CoreDNS server can determine the corresponding target application IP address based on the target domain name resolution request message.
[0037] S120. Determine the corresponding target application IP address based on the target domain name resolution request message.
[0038] The target application IP address may refer to the corresponding IP address of the target application after domain name resolution.
[0039] In an embodiment of the present invention, after receiving the target domain name resolution request message, the CoreDNS server can resolve the domain name to be resolved from the message, and obtain the corresponding target application IP address by resolving the domain name to be resolved. In a specific embodiment, the CoreDNS server can find the target application IP address associated with the mapping based on the domain name to be resolved in the pre-configured DNS domain name resolution configuration file.
[0040] S130: Send the target application IP address to the target host network Pod, so that the target host network Pod establishes a connection with the target application based on the target application IP address.
[0041] In an embodiment of the present invention, after resolving and obtaining the target application IP address, the CoreDNS server can return it to the target host network Pod that initiated the request, so that after the target host network Pod receives the message containing the target application IP address, it can access the corresponding target application based on the target application IP address, that is, establish a communication connection with the target application.
[0042] The technical solution of the embodiment of the present invention is applied to the CoreDNS server in the cluster, by receiving the target domain name resolution request message sent by the target host network Pod and processed by the first network address conversion rule and the second network address conversion rule respectively; wherein the first network address conversion rule is used to convert the destination address to the designated IP address corresponding to the CoreDNS server when the destination address of the domain name resolution request message is a non-specified IP address; the second network address conversion rule is used to convert the source address to the IP address of the network card sending the target message when the source address of the domain name resolution request message is a non-specified cluster container network segment; determine the corresponding target application IP address based on the target domain name resolution request message; send the target application IP address to the target host network Pod, so that the target host network Pod establishes a connection with the target application based on the target application IP address. This solution can achieve that the host network Pod can immediately use the domain name service function of CoreDNS without making any changes to the host network Pod, that is, smoothly use the domain name service function of CoreDNS, and is friendly to the actual production environment and has no impact on the business.
[0043] Further, based on the above-mentioned embodiment of the invention, determining the corresponding target application IP address based on the target domain name resolution request message in S120 includes:
[0044] Parse the target domain name resolution request message to obtain the domain name to be resolved;
[0045] A target application IP address corresponding to the domain name to be resolved is determined based on the first preset domain name resolution configuration file.
[0046] Among them, the first preset domain name resolution configuration file mainly stores some mapping association information between regular domain names and corresponding IP addresses. The regular domain names here are mainly used to distinguish between the first type of external domain names and the second type of external domain names. Regular domain names can include service names and Pod names within the cluster.
[0047] In an embodiment of the present invention, after receiving the target domain name resolution request message, the CoreDNS server can parse the domain name to be resolved from the message, and based on the domain name to be resolved, find the target application IP address associated with the mapping in the pre-configured first preset domain name resolution configuration file.
[0048] Further, based on the above-mentioned embodiment of the invention, when the domain name to be resolved belongs to the first category of external domain names, the method for determining the target application IP address includes:
[0049] Determine the target server IP address of the target domain name resolution server corresponding to the domain name to be resolved based on the second preset domain name resolution configuration file;
[0050] The target domain name resolution request message is sent to the target domain name resolution server according to the target server IP address, so that the target domain name resolution server determines the corresponding target application IP address based on the target domain name resolution request message.
[0051] Among them, the first type of external domain name can refer to a specific type of domain name that requires an external target domain name resolution (DNS) server to perform domain name resolution. The resolution request of this type of domain name needs to be forwarded to the CoreDNS server first, and then forwarded by the CoreDNS server to the specified target DNS server. The first type of external domain name can include but is not limited to: top, com, net, cn, edu, info, gov, biz, etc., which can be set accordingly according to actual application requirements, and this embodiment does not limit this.
[0052] The second preset domain name resolution configuration file stores the mapping association information between the first type of external domain name and the corresponding target DNS server IP address. Based on the second preset domain name resolution configuration file, the CoreDNS server can know which target DNS server to forward the target domain name resolution request message to for subsequent processing.
[0053] In an embodiment of the present invention, after the CoreDNS server receives the target domain name resolution request message, it can parse the domain name to be resolved from the message, and determine whether the domain name to be resolved belongs to the first category of external domain names such as top, com, etc. based on the pre-configured DNS configuration rules. If so, the target server IP address of the target DNS server mapped with it is searched in the pre-configured second preset domain name resolution configuration file according to the domain name to be resolved, and then the target domain name resolution request message is forwarded to the corresponding target DNS server according to the target server IP address, and the target DNS server completes the subsequent domain name resolution tasks to obtain the target application IP address corresponding to the target domain name resolution request message.
[0054] The following is an example of CoreDNS server forwarding processing the first type of external domain name: Corefile:|-
[0055] top,com,net,cn,edu,info,gov,biz,name,mil,mobi,io:53{
[0056] errors
[0057] forward.114.114.114.114
[0058] }
[0059] In the above example, domain name resolution requests such as top and com will be forwarded to the target DNS server (IP address 114.114.114.114) through the CoreDNS server. Corefile is a configuration file of the CoreDNS server, which is used to define the behavior and configuration of the CoreDNS server.
[0060] In this embodiment, if the host network Pod wants to perform domain name resolution to other external domain name servers, the external domain name server can be configured in the CoreDNS server, that is, all domain name resolution requests are first forwarded to the CoreDNS server, and then forwarded by the CoreDNS server to the specified external domain name server.
[0061] Further, based on the above-mentioned embodiment of the invention, when the domain name to be resolved belongs to the second category of external domain names, the method for determining the target application IP address includes:
[0062] The preset domain name resolution component is called to determine the target application IP address corresponding to the domain name to be resolved in the pre-cached third preset domain name resolution configuration file.
[0063] The second type of external domain name may refer to a type of external cluster special domain name defined by a user, such as transwarp.txf1, etc., which may be set accordingly according to actual application requirements, and this embodiment does not limit this.
[0064] The preset domain name resolution component may include a Kubernetai plug-in in a Kubernetes (K8S) cluster, which can identify services in the Kubernetes cluster and provide DNS resolution support for these services. It should be understood that the use of the Kubernetai plug-in allows the CoreDNS server to communicate with an external Kubernetes cluster, obtain information about target applications in the external kubernetes cluster, and cache it in a local third preset domain name resolution configuration file, so that the second type of external domain names can be quickly resolved in the current cluster.
[0065] The third preset domain name resolution configuration file stores mapping association information between the second type of external domain names and corresponding IP addresses.
[0066] In an embodiment of the present invention, after the CoreDNS server receives the target domain name resolution request message, it can parse the domain name to be resolved from the message, and determine whether the resolved domain name belongs to the second category of external domain name based on the pre-configured DNS configuration rules. If so, the preset domain name resolution component, i.e., the Kubernetai plug-in, is called to search the pre-configured third preset domain name resolution configuration file for the target application IP address associated with the domain name to be resolved.
[0067] The following is an example of how the CoreDNS server handles the second type of external domain name:
[0068] .:53{
[0069] kubernetai transwarp.txf1 in-addr.arpa ip6.arpa{
[0070] endpoint https: / / 172.18.194.214:6443
[0071] pods verified
[0072] fallthrough
[0073] }
[0074] In the above example, the configuration ".:53{kubernetai transwarp.txf1...}" indicates that the CoreDNS server will listen on port 53 and use the Kubernetai plugin to handle resolution requests related to the transwarp.txf1 domain name (i.e., the second type of external domain name). The configuration "endpoint https: / / 172.18.194.214:6443" specifies the address of the kube-apiserver component of the external Kubernetes cluster. The CoreDNS server will communicate with the external cluster through this address to obtain relevant information about the target application (IP address, etc.) and cache it locally. In this way, when the CoreDNS server in the current cluster tries to resolve the target application under the transwarp.txf1 domain name, the CoreDNS server can directly obtain the domain name resolution result from the cache (the third preset domain name resolution configuration file) without sending a request to the kube-apiserver component of the external cluster every time, thereby improving the resolution speed.
[0075] In this embodiment, for domain name resolution of other Kubernetes clusters such as transwarp.txf1, the CoreDNS server will cache the request to the target Kubernetes cluster kube-apiserver locally based on the Kubernetai component for fast resolution of the current cluster.
[0076] It should be understood that 10.10.0.10 mentioned in the above example is the ClusterIP of the CoreDNS server. Regardless of whether the CoreDNS server is a single copy or multiple copies, all domain name resolution requests will be forwarded to 10.10.0.10 first, and then load balanced among all CoreDNS Pods to ensure high availability, that is, the technical solution of the embodiment of the present invention will not affect the original high availability solution.
[0077] Further, based on the above-mentioned embodiments of the invention, the first network address translation rule and the second network address translation rule are configured by a preset network address translation configuration tool based on a specified IP address and a specified cluster container network segment respectively.
[0078] Among them, the preset network address translation configuration tool may refer to a tool for configuring NAT rules, and the preset NAT configuration tool may include at least one of the following configuration modes: iptables mode, nftables mode and eBPF mode.
[0079] In an embodiment of the present invention, the first NAT rule and the second NAT rule can be configured using a preset NAT configuration tool, so that all domain name resolution request messages issued by the host network Pod are redirected to the CoreDNS server, and the messages responded by the CoreDNS server can be returned normally.
[0080] In a specific embodiment, the design architecture of this solution mainly involves a node-agent component, which is deployed in the form of DaemonSet on each node in the cluster to ensure that the new node can also automatically deploy the component when the cluster is expanded. The core function of the node-agent component is to obtain the ClusterIP of the CoreDNS server and configure the corresponding NAT rules based on the ClusterIP. Among them, in the Kubernetes cluster, DaemonSet is an API (Application Programming Interface) object that ensures that a specific Pod copy is running on each node in the cluster (or on a user-specified node). DaemonSet is typically used for services that need to run on all nodes, such as log collection, monitoring, or network services.
[0081] Specifically, the configuration process of the first NAT rule and the second NAT rule is as follows:
[0082] Step 1. Obtain the ClusterIP of the CoreDNS server through the kube-apiserver component, for example, 10.10.0.10; and obtain the container network segment PodCIDR of the current cluster, for example, 10.224.0.0 / 16.
[0083] Step 2: Set the configuration mode of the preset NAT configuration tool, including iptables mode, nftables mode and eBPF mode. Different configuration modes correspond to different NAT rule configuration methods. The following takes iptables mode as an example for explanation.
[0084] Step 3. Configure the first NAT rule: Add a rule to the OUTPUT chain of the NAT table. The content of the rule is: [When the destination address is not 10.10.0.10, and the message is UDP protocol, and the destination port is 53], convert the destination address to 10.10.0.10 (because this rule is added to the OUTPUT chain, it only takes effect on the host network and has no effect on the container network. The messages of the container network only pass through the PREROUTING, FORWARD, and POSTROUTING chains on the node).
[0085] Among them, the OUTPUT chain is used to process all data packets sent from the local machine. By configuring the OUTPUT chain, you can control the behavior of these outbound data packets, including whether to allow them to leave the local machine, how to modify them, etc.
[0086] The first NAT rule is configured in iptables mode, nftables mode, and eBPF mode as shown in the following examples:
[0087] 1)iptables mode: iptables-t nat-IOUTPUT! -d 10.10.0.10-p udp -m udp--dport 53-j DNAT--to-destination 10.10.0.10
[0088] 2) nftables mode: nft add rule nat output ip daddr! =10.10.0.10udp dport53dnat to 10.10.0.10
[0089] 3)ebpf mode:
[0090] if(iph->protocol==IPPROTO_UDP&&
[0091] udph->dest==bpf_htons(53)&&
[0092] iph->daddr! =bpf_htonl(0x0A0A0A0A)){
[0093] / / Redirect to 10.10.0.10
[0094] bpf_l3_csum_replace(iph,udph,0,0,bpf_htonl(0x0A0A0A0A),4);
[0095] return XDP_REDIRECT;
[0096] }
[0097] Step 4. Configure the second NAT rule: Add a rule to the POSTROUTING chain of the NAT table to ensure that this function has no effect on the container network Pod. The content of the rule is: [When the source IP is not in the specified cluster container network segment, and the message is UDP protocol, and the destination port is 53], execute the MASQUERADE action to convert the source IP of the message to the IP address of the network card sending the target message to ensure that the message can be returned normally.
[0098] Among them, the POSTROUTING chain: is used in iptables to process data packets when they leave the local machine, usually used for source address translation (SNAT).
[0099] The MASQUERADE action modifies the source IP address of the outbound message to the IP address of the network card that sent the target message. In this way, when the CoreDNS server responds to this message, it will send the response message back to the IP address of the network card that sent the message, rather than the IP address of the original target host network Pod.
[0100] The configuration of the second NAT rule in iptables mode, nftables mode, and eBPF mode are as follows:
[0101] 1) iptables mode: iptables-nat-IPOSTROUTING! -s 10.224.0.0 / 16 -p udp-mudp --dport 53 -j MASQUERADE
[0102] 2) nftables mode: nft add rule ip nat postrouting ip saddr! =10.224.0.0 / 16udp dport 53masquerade
[0103] 3)ebpf mode:
[0104]
[0105] It can be understood that after the domain name resolution request message sent by the host network Pod is processed based on the above-mentioned first NAT rule and second NAT rule, regardless of whether there is the ClusterIP of the CoreDNS server in the / etc / resolv.conf file of the node where it is located, the domain name resolution request of the host network Pod will be forwarded to the CoreDNS server to ensure that the host network Pod communicates with other applications inside and outside the cluster in the form of domain names, and has no impact on the container network Pod.
[0106] Embodiment 2
[0107] Figure 2 This is a schematic diagram of the structure of a domain name resolution device provided by Embodiment 2 of the present invention. Figure 2 As shown, the device is used for the CoreDNS server in the cluster, including:
[0108] The request message receiving module 21 is used to receive the target domain name resolution request message sent by the target host network Pod after being processed by the first network address conversion rule and the second network address conversion rule respectively; wherein the first network address conversion rule is used to convert the destination address of the domain name resolution request message to the designated IP address corresponding to the CoreDNS server when the destination address of the domain name resolution request message is a non-specified IP address; the second network address conversion rule is used to convert the source address of the domain name resolution request message to the IP address of the network card sending the target message when the source address of the domain name resolution request message is a non-specified cluster container network segment;
[0109] A domain name resolution module 22, configured to determine a corresponding target application IP address based on a target domain name resolution request message;
[0110] The address sending module 23 is used to send the target application IP address to the target host network Pod, so that the target host network Pod establishes a connection with the target application based on the target application IP address.
[0111] The technical solution of the embodiment of the present invention is applied to the CoreDNS server in the cluster, and receives the target domain name resolution request message sent by the target host network Pod after being processed by the first network address conversion rule and the second network address conversion rule respectively through the request message receiving module; wherein the first network address conversion rule is used to convert the destination address to the designated IP address corresponding to the CoreDNS server when the destination address of the domain name resolution request message is a non-specified IP address; the second network address conversion rule is used to convert the source address to the IP address of the network card sending the target message when the source address of the domain name resolution request message is a non-specified cluster container network segment; the domain name resolution module determines the corresponding target application IP address based on the target domain name resolution request message; the address sending module sends the target application IP address to the target host network Pod, so that the target host network Pod establishes a connection with the target application based on the target application IP address. This solution can realize that the host network Pod can immediately use the domain name service function of CoreDNS without making any changes to the host network Pod, that is, smoothly use the domain name service function of CoreDNS, and is friendly to the actual production environment and has no impact on the business.
[0112] Further, based on the above-mentioned embodiment of the invention, the domain name resolution module 22 includes:
[0113] A message parsing unit, used to parse the target domain name resolution request message to obtain the domain name to be resolved;
[0114] The domain name resolution unit is used to determine the target application IP address corresponding to the domain name to be resolved based on the first preset domain name resolution configuration file.
[0115] Further, based on the above-mentioned embodiment of the invention, when the domain name to be resolved belongs to the first category of external domain names, the method for determining the target application IP address includes:
[0116] Determine the target server IP address of the target domain name resolution server corresponding to the domain name to be resolved based on the second preset domain name resolution configuration file;
[0117] The target domain name resolution request message is sent to the target domain name resolution server according to the target server IP address, so that the target domain name resolution server determines the corresponding target application IP address based on the target domain name resolution request message.
[0118] Further, based on the above-mentioned embodiment of the invention, when the domain name to be resolved belongs to the second category of external domain names, the method for determining the target application IP address includes:
[0119] The preset domain name resolution component is called to determine the target application IP address corresponding to the domain name to be resolved in the pre-cached third preset domain name resolution configuration file.
[0120] Further, based on the above-mentioned embodiments of the invention, the first network address translation rule and the second network address translation rule are configured by a preset network address translation configuration tool based on a specified IP address and a specified cluster container network segment respectively.
[0121] Further, based on the above-mentioned embodiments of the invention, the configuration mode of the preset network address translation configuration tool includes at least one of iptables mode, nftables mode and eBPF mode.
[0122] The domain name resolution device provided in the embodiment of the present invention can execute the domain name resolution method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0123] Embodiment 3
[0124] Figure 3 A schematic diagram of the structure of an electronic device 30 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0125] like Figure 3As shown, the electronic device 30 includes at least one processor 31, and a memory connected to the at least one processor 31, such as a read-only memory (ROM) 32, a random access memory (RAM) 33, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 31 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 32 or the computer program loaded from the storage unit 38 to the random access memory (RAM) 33. In the RAM 33, various programs and data required for the operation of the electronic device 30 can also be stored. The processor 31, the ROM 32 and the RAM 53 are connected to each other through a bus 34. An input / output (I / O) interface 35 is also connected to the bus 34.
[0126] A number of components in the electronic device 30 are connected to the I / O interface 35, including: an input unit 36, such as a keyboard, a mouse, etc.; an output unit 37, such as various types of displays, speakers, etc.; a storage unit 38, such as a disk, an optical disk, etc.; and a communication unit 39, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 39 allows the electronic device 30 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0127] The processor 31 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 31 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 31 executes the various methods and processes described above, such as a domain name resolution method.
[0128] In some embodiments, the domain name resolution method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 38. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 30 via the ROM 32 and / or the communication unit 39. When the computer program is loaded into the RAM 33 and executed by the processor 31, one or more steps of the domain name resolution method described above may be performed. Alternatively, in other embodiments, the processor 31 may be configured to perform the domain name resolution method in any other appropriate manner (e.g., by means of firmware).
[0129] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0130] In some embodiments, the domain name resolution method may be implemented as a computer program, which is invisibly included in a computer program product. The computer program implements the domain name resolution method of the present invention when executed by a processor. The computer program product can be understood as a software product that implements its solution mainly through a computer program. The computer program for implementing the method of the present invention can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the computer program, when executed by the processor, implements the functions / operations specified in the flowchart and / or block diagram. The computer program can be executed entirely on the machine, partially on the machine, partially on the machine as an independent software package and partially on a remote machine, or entirely on a remote machine or server.
[0131] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0132] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0133] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0134] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0135] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0136] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A domain name resolution method, characterized in that: Applied to a CoreDNS server in a cluster, the method includes: Receive a target domain name resolution request message sent by a target host network Pod and processed by a first network address translation rule and a second network address translation rule respectively; wherein the first network address translation rule is used to convert the destination address of the domain name resolution request message to the designated IP address corresponding to the CoreDNS server when the destination address of the domain name resolution request message is a non-designated IP address; the second network address translation rule is used to convert the source address of the domain name resolution request message to the IP address of the network card from which the target message is sent when the source address of the domain name resolution request message is a non-designated cluster container network segment; Determine the corresponding target application IP address based on the target domain name resolution request message; The target application IP address is sent to the target host network Pod, so that the target host network Pod establishes a connection with the target application based on the target application IP address.
2. The method according to claim 1, characterized in that The determining the corresponding target application IP address based on the target domain name resolution request message includes: Parsing the target domain name resolution request message to obtain the domain name to be resolved; The target application IP address corresponding to the domain name to be resolved is determined based on a first preset domain name resolution configuration file.
3. The method according to claim 2, characterized in that When the domain name to be resolved belongs to the first category of external domain names, the method for determining the target application IP address includes: Determine the target server IP address of the target domain name resolution server corresponding to the domain name to be resolved based on the second preset domain name resolution configuration file; The target domain name resolution request message is sent to the target domain name resolution server according to the target server IP address, so that the target domain name resolution server determines the corresponding target application IP address based on the target domain name resolution request message.
4. The method according to claim 2, characterized in that: When the domain name to be resolved belongs to the second category of external domain names, the method for determining the target application IP address includes: The preset domain name resolution component is called to determine the target application IP address corresponding to the domain name to be resolved in the pre-cached third preset domain name resolution configuration file.
5. The method according to claim 1, characterized in that The first network address translation rule and the second network address translation rule are configured by a preset network address translation configuration tool based on the specified IP address and the specified cluster container network segment respectively.
6. The method according to claim 5, characterized in that The configuration mode of the preset network address translation configuration tool includes at least one of iptables mode, nftables mode and eBPF mode.
7. A domain name resolution device, characterized in that: Applied to a CoreDNS server in a cluster, the device comprises: A request message receiving module is used to receive a target domain name resolution request message sent by a target host network Pod and processed by a first network address conversion rule and a second network address conversion rule respectively; wherein, the first network address conversion rule is used to convert the destination address of the domain name resolution request message to the designated IP address corresponding to the CoreDNS server when the destination address of the domain name resolution request message is a non-specified IP address; the second network address conversion rule is used to convert the source address of the domain name resolution request message to the IP address of the network card from which the target message is sent when the source address of the domain name resolution request message is a non-specified cluster container network segment; A domain name resolution module, used to determine the corresponding target application IP address based on the target domain name resolution request message; The address sending module is used to send the target application IP address to the target host network Pod, so that the target host network Pod establishes a connection with the target application based on the target application IP address.
8. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the domain name resolution method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the domain name resolution method according to any one of claims 1 to 6 when executed.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the domain name resolution method according to any one of claims 1 to 6 is implemented.
Citation Information
Cited By
Domain name resolution method and apparatus, device, storage medium, and product
WO2026144678A1