4.2.6 Configuring CoreDNS for External Hostname Resolution

In order for the Kubernetes cluster to resolve the required hostnames for the installation, you must configure CoreDNS in your cluster.

You must configure CoreDNS as follows:
  • Either add the hostname.domain and IP addresses of any Proxy Severs, the Kubernetes nodes, the OAM OAuth server, the Oracle Database, and your Container Image Registry; or
  • Add the Domain Names Servers (DNS) that can resolve the hostname.domain and IP addresses of any Proxy Severs, the Kubernetes nodes, the OAM OAuth server, the Oracle Database, and your Container Image Registry.
Note: The instructions below are generic for Kubernetes and may not be applicable to all Kubernetes vendors. Refer to your Kubernetes vendor specific documentation on how to configure CoreDNS.

Adding individual hostnames and IP addresses or DNS to CoreDNS

  1. Run the following command to edit the coredns configmap:
    kubectl edit configmap/coredns -n kube-system
    This will take you into an edit session similar to vi.
  2. If you prefer to add each individual hostname and IP address, add a hosts section to the file including one entry for each of the hosts you wish to define. For example:
    apiVersion: v1
    data:
      Corefile: |
        .:53 {
            errors
            health {
               lameduck 5s
            }
            ready
            kubernetes cluster.local in-addr.arpa ip6.arpa {
               pods insecure
               fallthrough in-addr.arpa ip6.arpa
               ttl 30
            }
            prometheus :9153
            forward . /etc/resolv.conf {
               max_concurrent 1000
            }
            cache 30
            loop
            reload
            loadbalance
            hosts custom.hosts example.com { 
                 1.1.1.1 oam.example.com 
                 1.1.1.2 db.example.com 
                 1.1.1.3 container-registry.example.com 
                 1.1.1.4 masternode.example.com 
                 1.1.1.5 worker1.example.com
                 1.1.1.6 worker2.example.com
                 fallthrough 
            }
          }
    kind: ConfigMap
    metadata:
      creationTimestamp: "2021-11-09T14:08:31Z"
      name: coredns
      namespace: kube-system
      resourceVersion: "25242052"
      uid: 21e623cf-e393-425a-81dc-68b1b06542b4
    
    Alternatively, if you prefer to add the Domain Name Server (DNS) then add a section for the DNS:
    apiVersion: v1
    data:
      Corefile: |
        .:53 {
            errors
            health {
               lameduck 5s
            }
            ready
            kubernetes cluster.local in-addr.arpa ip6.arpa {
               pods insecure
               fallthrough in-addr.arpa ip6.arpa
               ttl 30
            }
            prometheus :9153
            forward . /etc/resolv.conf {
               max_concurrent 1000
            }
            cache 30
            loop
            reload
            loadbalance
          }
        example.com:53 {
          errors
          cache 30
          forward . <DNS_IPADDRESS>
          }
    kind: ConfigMap
    metadata:
      creationTimestamp: "2021-11-09T14:08:31Z"
      name: coredns
      namespace: kube-system
      resourceVersion: "25242052"
      uid: 21e623cf-e393-425a-81dc-68b1b06542b4
  3. Save the file (!wq).
  4. Restart CoreDNS:
    1. Run the following command to restart coredns:
      kubectl rollout restart -n kube-system deploy coredns
    2. Ensure the coredns pods restart without any problems by running the following command:
      kubectl get pods -n kube-system 
      If any errors are shown use the following command to view the logs, then correct by editing the coredns configmap again:
      kubectl logs -n kube-system coredns--<ID>

Validating DNS Resolution

Most containers do not have built in networking tools to allow you to check that the configuration changes you made are correct. The easiest way to validate the changes is to use a lightweight container with the network tools installed, such as alpine.
  1. Run the following command to run an alpine container:
    kubectl run -i --tty --rm debug --image=docker.io/library/alpine:latest --restart=Never -- sh
    This will take you inside a bash shell in the container.
  2. Inside the container you can then run nslookup against the Database, OAM OAuth Server, Container Image Registry etc, for example:
    nslookup oam.example.com