Corefile for adding additional nameserver to CoreDNS configuration file in OCP 4

Solution Verified - Updated -

Environment

  • Red Hat OpenShift Container Platform(OCP) v4.1
  • Red Hat OpenShift Container Platform(OCP) v4.2
  • Red Hat OpenShift Container Platform(OCP) v4.3
  • CoreDNS

Issue

  • How to add additional upstream nameserver for a specific domain to CoreDNS in OCP 4?
  • Configure two different upstream nameservers, One used to resolve default requests/domains, and the other one for a specific domain.
  • Can I modify CoreFile directly to add the nameserver?

Resolution

  • Is it NOT recommended or supported to add additional upstream nameserver by directly modifying the Corefile.

  • This feature is available only from OCP v4.3 with the help of DNS Operator API:

# oc patch dns.operator/default --type=merge --patch='{"spec":{"servers":[{"name":"test","zones":["example.local","example.net"],"forwardPlugin":{"upstreams":["<DNS_server_ip>"]}}]}}'

OR

# oc edit dns.operator/default 
spec:
  servers:
  - forwardPlugin:
      upstreams:
      - "<DNS1_server_IP>"
      - "<DNS2_server_IP>"
    name: test
    zones:
    - example.local
    - example.net
  • Verify the changes:
# oc get configmaps/dns-default -n openshift-dns -o yaml

Root Cause

  • API is forwarding to the upstream nameserver by domain. This API definition shows the API functionality of this feature.
  • As of now forward plugin is supported in OCP v4.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments