Using a DNS Endpoint for Cascading Resolution
Prerequisites
The VPC where the CCE cluster is deployed has been connected to the on-premises IDC through a private line (Direct Connect) or other channels. The IDC can access the IP addresses in the VPC CIDR block and container CIDR block of the cluster. For details about how to create a Direct Connect connection, see Direct Connect Getting Started.
Procedure
- Create a DNS endpoint in the cluster VPC.
- Access the VPC Endpoints page on the network console.
- Click Buy VPC Endpoint in the upper right corner.
- Select the DNS service and the cluster VPC. Figure 1 Creating a DNS endpoint
- Click Next and complete the creation.
After the creation is complete, you can view the IP address of the DNS endpoint on its details page.
Figure 2 Viewing the IP address of the DNS endpoint
- Configure cascading on the IDC DNS server.
The configuration varies depending on the DNS server. The settings below are used only as example.
BIND (a commonly used DNS server software) is used for the demonstration.
In this step, configure the DNS server to forward the requests of resolving Huawei Cloud internal domain names to the DNS endpoint created previously.
For example, in BIND, you can add the lines marked in red to the /etc/named.conf file. 192.168.0.203 is the IP address of the DNS endpoint created in 1.options { listen-on port 53 { any; }; listen-on-v6 port 53 { ::1; }; directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; memstatistics-file "/var/named/data/named_mem_stats.txt"; recursing-file "/var/named/data/named.recursing"; secroots-file "/var/named/data/named.secroots"; allow-query { any; }; forward first; forwarders { 192.168.0.203; }; ..... }; - Change the DNS settings of the node in the CCE cluster.
You can use either of the following methods to change the settings.
Method 1:
Change the settings after the node is created.- Log in to the worker node of the CCE cluster.
- In the /etc/resolv.conf file, change the value of nameserver to the IP address of the IDC DNS server.
# vi /etc/resolv.conf nameserver 10.0.0.190
- Lock the resolv.conf file to prevent it from being automatically updated by Huawei Cloud.
chattr +i /etc/resolv.conf
For details about how to configure DNS, see Configuring DNS.
Method 2:
Change the DNS settings of the VPC subnet where the CCE cluster resides. In this way, the IP address of the specified DNS server is used in the /etc/resolv.conf file for newly created worker nodes.
Before using this method, ensure that the node can use the IDC DNS server to resolve Huawei Cloud internal domain names. Otherwise, the node cannot be created. You are advised to debug the DNS server before you change the DNS settings of the VPC subnet.
Figure 3 Subnet DNS settings
- Configure the workload DNS policy. When creating a workload, set dnsPolicy to ClusterFirst in the YAML file for domain name resolution in containers. This is also the default configuration in Kubernetes. For details about how to configure DNS for workloads, see DNS Configuration.
apiVersion: v1 kind: Pod metadata: namespace: default name: dns-example spec: containers: - name: test image: nginx dnsPolicy: ClusterFirst
Verification
After the configuration is complete, run the dig command on a cluster node. The command output shows that the IP address of the server is 10.0.0.190, which indicates that the domain name is resolved by the IDC DNS server.
# dig cce.ap-southeast-1.myhuaweicloud.com ; <<>> DiG 9.9.4-61.1.h14.eulerosv2r7 <<>> cce.ap-southeast-1.myhuaweicloud.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 24272 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;cce.ap-southeast-1.myhuaweicloud.com. IN A ;; ANSWER SECTION: cce.ap-southeast-1.myhuaweicloud.com. 274 IN A 100.125.4.16 ;; Query time: 4 msec ;; SERVER: 10.0.0.190#53(10.0.0.190) ;; WHEN: Tue Feb 23 19:16:08 CST 2021 ;; MSG SIZE rcvd: 76
Access a Huawei Cloud domain name from the node. The following output shows that the domain name is resolved to the corresponding IP address.
# ping cce.ap-southeast-1.myhuaweicloud.com PING cce.ap-southeast-1.myhuaweicloud.com (100.125.4.16) 56(84) bytes of data.
Create a pod to access a Huawei Cloud domain name. The following output shows that the domain name can be resolved.
# kubectl run -i --tty --image tutum/dnsutils dnsutils --restart=Never --rm /bin/sh If you do not see a command prompt, try pressing Enter. # ping cce.ap-southeast-1.myhuaweicloud.com PING cce.ap-southeast-1.myhuaweicloud.com (100.125.4.16) 56(84) bytes of data.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot