DNS in OpenShift Container Platform (OCP) is a critical, multi-layered service that handles internal service discovery, external traffic routing, and cluster node resolution.
OpenShift uses a CoreDNS-based operator architecture that runs as a managed service across all nodes.
1. High-Level Architecture
The OpenShift DNS stack consists of three distinct layers:
┌─────────────────────────────────────────────────────────────┐
│ Pod Level │
│ /etc/resolv.conf -> Node IP / CoreDNS │
└──────────────────────────────┬──────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Cluster DNS Layer (CoreDNS) │
│ DaemonSet in openshift-dns Namespace │
└──────────────┬───────────────────────────────┬──────────────┘
│ Internal Queries │ External Queries
▼ ▼
┌─────────────────────────────┐ ┌─────────────────────────────┐
│ Kubernetes API / Services │ │ Upstream / Host Node DNS │
│ (.cluster.local domains) │ │ (e.g., 8.8.8.8 / Corporate)│
└─────────────────────────────┘ └─────────────────────────────┘
- DNS Operator (
dns.operator.openshift.io): Manages the lifecycle, configuration, and scaling of CoreDNS across the cluster. - CoreDNS DaemonSet: Runs a CoreDNS pod on every worker and control-plane node in the
openshift-dnsnamespace, listening on port53of the host’s loopback or node interface. - Upstream Resolution: For non-Kubernetes domains (like
google.comor corporate database endpoints), CoreDNS forwards the request to the node’s underlying host DNS resolution settings (/etc/resolv.conf).
2. Internal Service Discovery Naming Scheme
When pods communicate within OpenShift, DNS automatically maps service names to their corresponding cluster virtual IPs (ClusterIP).
A. Standard Service DNS Names
Format: <service-name>.<namespace-name>.svc.cluster.local
- Same Namespace: A pod in
prodcan reach the servicefrontendby simply referencinghttp://frontend. - Cross Namespace: A pod in
devcan reach the servicefrontendinprodusing[http://frontend.prod.svc.cluster.local](http://frontend.prod.svc.cluster.local).
B. Headless Services (StatefulSets)
For stateful workloads (like databases or Kafka brokers) where pods need individual network identities, a Headless Service returns the individual pod IPs directly instead of a single Virtual IP.
Format: <pod-name>.<service-name>.<namespace-name>.svc.cluster.local
Example:kafka-0.kafka-service.messaging.svc.cluster.local
3. How Pods Resolve DNS Queries
When a container inside an OpenShift pod makes a network request:
- Pod
resolv.confCheck: The pod inspects its local/etc/resolv.conffile, which is injected automatically bykubelet:nameserver 172.30.0.10 # Cluster DNS Virtual IP search <namespace>.svc.cluster.local svc.cluster.local cluster.local options ndots:5 - Search Domain Appending (
ndots:5): If a query contains fewer than 5 dots (e.g.,api-service), CoreDNS sequentially appends the search domains (e.g., tryingapi-service.my-namespace.svc.cluster.localfirst). - CoreDNS Lookup: The request hits the local node’s CoreDNS instance.
- If the domain ends in
.cluster.local, CoreDNS resolves it using internal Kubernetes service records. - If the domain is external, CoreDNS forwards it to the upstream DNS servers defined on the underlying RHCOS host.
- If the domain ends in
4. Customizing Cluster DNS
You do not edit Corefile configurations directly. Instead, you modify the dns.operator/default Custom Resource (CR) to inject custom upstream servers, forward zones, or internal DNS overrides.
Example: Forwarding Specific Corporate Domains
To route queries for internal corporate domains (e.g., *.corp.internal) to a custom on-premises DNS server:
apiVersion: operator.openshift.io/v1kind: DNSmetadata: name: defaultspec: servers: - name: corp-dns-forwarder zones: - corp.internal - mycompany.local forwardPlugin: upstreams: - 10.0.0.53:53 - 10.0.0.54:53
Apply using:
oc edit dns.operator/default
5. Useful Commands for Debugging OpenShift DNS
- Check DNS Operator Status:
oc get clusteroperator dns - View CoreDNS Pods & Nodes:
oc get pods -n openshift-dns -o wide - Tail Logs of CoreDNS Pods:
oc logs -n openshift-dns -l dns.operator.openshift.io/daemonset-dns=default -c dns --tail=50 - Test DNS Resolution from inside a Pod:
oc run dns-test --image=registry.redhat.io/rhel8/support-tools --rm -it -- dig my-service.my-namespace.svc.cluster.local