Updated on 2024-05-31 GMT+08:00

Solution 1: 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 CCE cluster container CIDR block. For details about how to create a Direct Connect connection, see Getting Started with Direct Connect.

Procedure

  1. Create a DNS endpoint in the VPC where the CCE cluster is deployed.

    1. Access the VPC Endpoint page on the network console.
    2. Click Buy VPC Endpoint in the upper right corner.
    3. Select the DNS service and VPC where the CCE cluster is deployed.
      Figure 1 Creating a DNS endpoint
    4. Click Next and then Submit.

      After the creation is complete, you can view the IP address of the DNS endpoint on its details page.

      Figure 2 IP address of the DNS endpoint

  2. Configure cascading on the IDC DNS server.

    The configuration varies depending on the DNS server. The following configurations are used only as example.

    BIND (a commonly used DNS server software) is used for the following demonstration.

    In this step, you configure the DNS server to forward the requests of resolving Huawei Cloud internal domain names to the DNS endpoint created in the previous step.

    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; };
            
            .....
    };

  3. Change the DNS configuration 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.
    1. Log in to the worker node of the CCE cluster.
    2. 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
    3. Run the following command to 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 the Huawei Cloud internal domain name. Otherwise, the node cannot be created. You are advised to commission the DNS server before you change the DNS settings of the VPC subnet.

    Figure 3 Subnet DNS settings

  4. Configure the workload DNS policy.

    When creating a workload, you can 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 the 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 domain name of Huawei Cloud from the cluster 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 the 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.