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.
Adding individual hostnames and IP addresses or DNS to CoreDNS
- Run the following command to edit the coredns configmap:
This will take you into an edit session similar tokubectl edit configmap/coredns -n kube-system
vi
. - 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:
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 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
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
- Save the file (
!wq
). - Restart CoreDNS:
- Run the following command to restart
coredns:
kubectl rollout restart -n kube-system deploy coredns
- Ensure the coredns pods restart without any problems by running the following command:
If any errors are shown use the following command to view the logs, then correct by editing the coredns configmap again:kubectl get pods -n kube-system
kubectl logs -n kube-system coredns--<ID>
- Run the following command to restart
coredns:
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.
- Run the following command to run an alpine container:
This will take you inside a bash shell in the container.kubectl run -i --tty --rm debug --image=docker.io/library/alpine:latest --restart=Never -- sh
- Inside the container you can then run
nslookup
against the Database, OAM OAuth Server, Container Image Registry etc, for example:nslookup oam.example.com