This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 5. DNS Operator in OpenShift Container Platform
The DNS Operator deploys and manages CoreDNS to provide a name resolution service to pods, enabling DNS-based Kubernetes Service discovery in OpenShift Container Platform.
5.1. DNS Operator Copier lienLien copié sur presse-papiers!
The DNS Operator implements the dns
API from the operator.openshift.io
API group. The Operator deploys CoreDNS using a daemon set, creates a service for the daemon set, and configures the kubelet to instruct pods to use the CoreDNS service IP address for name resolution.
Procedure
The DNS Operator is deployed during installation with a Deployment
object.
Use the
oc get
command to view the deployment status:oc get -n openshift-dns-operator deployment/dns-operator
$ oc get -n openshift-dns-operator deployment/dns-operator
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
NAME READY UP-TO-DATE AVAILABLE AGE dns-operator 1/1 1 1 23h
NAME READY UP-TO-DATE AVAILABLE AGE dns-operator 1/1 1 1 23h
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
oc get
command to view the state of the DNS Operator:oc get clusteroperator/dns
$ oc get clusteroperator/dns
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
NAME VERSION AVAILABLE PROGRESSING DEGRADED SINCE dns 4.1.0-0.11 True False False 92m
NAME VERSION AVAILABLE PROGRESSING DEGRADED SINCE dns 4.1.0-0.11 True False False 92m
Copy to Clipboard Copied! Toggle word wrap Toggle overflow AVAILABLE
,PROGRESSING
andDEGRADED
provide information about the status of the operator.AVAILABLE
isTrue
when at least 1 pod from the CoreDNS daemon set reports anAvailable
status condition.
5.2. Changing the DNS Operator managementState Copier lienLien copié sur presse-papiers!
DNS manages the CoreDNS component to provide a name resolution service for pods and services in the cluster. The managementState
of the DNS Operator is set to Managed
by default, which means that the DNS Operator is actively managing its resources. You can change it to Unmanaged
, which means the DNS Operator is not managing its resources.
The following are use cases for changing the DNS Operator managementState
:
-
You are a developer and want to test a configuration change to see if it fixes an issue in CoreDNS. You can stop the DNS Operator from overwriting the fix by setting the
managementState
toUnmanaged
. -
You are a cluster administrator and have reported an issue with CoreDNS, but need to apply a workaround until the issue is fixed. You can set the
managementState
field of the DNS Operator toUnmanaged
to apply the workaround.
Procedure
Change
managementState
DNS Operator:oc patch dns.operator.openshift.io default --type merge --patch '{"spec":{"managementState":"Unmanaged"}}'
oc patch dns.operator.openshift.io default --type merge --patch '{"spec":{"managementState":"Unmanaged"}}'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
5.3. Controlling DNS pod placement Copier lienLien copié sur presse-papiers!
The DNS Operator has two daemon sets: one for CoreDNS and one for managing the /etc/hosts
file. The daemon set for /etc/hosts
must run on every node host to add an entry for the cluster image registry to support pulling images. Security policies can prohibit communication between pairs of nodes, which prevents the daemon set for CoreDNS from running on every node.
As a cluster administrator, you can use a custom node selector to configure the daemon set for CoreDNS to run or not run on certain nodes.
Prerequisites
-
You installed the
oc
CLI. -
You are logged in to the cluster with a user with
cluster-admin
privileges.
Procedure
To prevent communication between certain nodes, configure the
spec.nodePlacement.nodeSelector
API field:Modify the DNS Operator object named
default
:oc edit dns.operator/default
$ oc edit dns.operator/default
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Specify a node selector that includes only control plane nodes in the
spec.nodePlacement.nodeSelector
API field:spec: nodePlacement: nodeSelector: node-role.kubernetes.io/worker: ""
spec: nodePlacement: nodeSelector: node-role.kubernetes.io/worker: ""
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
To allow the daemon set for CoreDNS to run on nodes, configure a taint and toleration:
Modify the DNS Operator object named
default
:oc edit dns.operator/default
$ oc edit dns.operator/default
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Specify a taint key and a toleration for the taint:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- If the taint is
dns-only
, it can be tolerated indefinitely. You can omittolerationSeconds
.
5.4. View the default DNS Copier lienLien copié sur presse-papiers!
Every new OpenShift Container Platform installation has a dns.operator
named default
.
Procedure
Use the
oc describe
command to view the defaultdns
:oc describe dns.operator/default
$ oc describe dns.operator/default
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To find the service CIDR of your cluster, use the
oc get
command:oc get networks.config/cluster -o jsonpath='{$.status.serviceNetwork}'
$ oc get networks.config/cluster -o jsonpath='{$.status.serviceNetwork}'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Example output
[172.30.0.0/16]
[172.30.0.0/16]
5.5. Using DNS forwarding Copier lienLien copié sur presse-papiers!
You can use DNS forwarding to override the forwarding configuration identified in /etc/resolv.conf
on a per-zone basis by specifying which name server should be used for a given zone. If the forwarded zone is the Ingress domain managed by OpenShift Container Platform, then the upstream name server must be authorized for the domain.
Procedure
Modify the DNS Operator object named
default
:oc edit dns.operator/default
$ oc edit dns.operator/default
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This allows the Operator to create and update the ConfigMap named
dns-default
with additional server configuration blocks based onServer
. If none of the servers has a zone that matches the query, then name resolution falls back to the name servers that are specified in/etc/resolv.conf
.Sample DNS
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf
servers
is undefined or invalid, the ConfigMap only contains the default server.View the ConfigMap:
oc get configmap/dns-default -n openshift-dns -o yaml
$ oc get configmap/dns-default -n openshift-dns -o yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Sample DNS ConfigMap based on previous sample DNS
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Changes to the
forwardPlugin
triggers a rolling update of the CoreDNS daemon set.
5.6. DNS Operator status Copier lienLien copié sur presse-papiers!
You can inspect the status and view the details of the DNS Operator using the oc describe
command.
Procedure
View the status of the DNS Operator:
oc describe clusteroperators/dns
$ oc describe clusteroperators/dns
5.7. DNS Operator logs Copier lienLien copié sur presse-papiers!
You can view DNS Operator logs by using the oc logs
command.
Procedure
View the logs of the DNS Operator:
oc logs -n openshift-dns-operator deployment/dns-operator -c dns-operator
$ oc logs -n openshift-dns-operator deployment/dns-operator -c dns-operator