$ oc get -n openshift-dns-operator deployment/dns-operator
In OKD, the dns Operator deploys and manages a Coredns instance to provide a name resolution service to pods inside the cluster, enables dns-based Kubernetes Service discovery, and resolves internal cluster.local
names.
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.
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
NAME READY UP-TO-DATE AVAILABLE AGE
dns-operator 1/1 1 1 23h
Use the oc get
command to view the state of the dns Operator:
$ oc get clusteroperator/dns
NAME VERSION AVAILABLE PROGRESSING DEGRADED SINCE MESSAGE
dns 4.1.15-0.11 True False False 92m
AVAILABLE
, PROGRESSING
, and DEGRADED
provide information about the status of the Operator. AVAILABLE
is True
when at least 1 pod from the Coredns daemon set reports an Available
status condition, and the dns service has a cluster IP address.
Every new OKD installation has a dns.operator
named default
.
Use the oc describe
command to view the default dns
:
$ oc describe dns.operator/default
Name: default
Namespace:
Labels: <none>
Annotations: <none>
API Version: operator.openshift.io/v1
Kind: dns
...
Status:
Cluster Domain: cluster.local (1)
Cluster IP: 172.30.0.10 (2)
...
1 | The Cluster Domain field is the base dns domain used to construct fully qualified pod and service domain names. |
2 | The Cluster IP is the address pods query for name resolution. The IP is defined as the 10th address in the service CIDR range. |
To find the service CIDR range of your cluster, use the oc get
command:
$ oc get networks.config/cluster -o jsonpath='{$.status.serviceNetwork}'
[172.30.0.0/16]
You can use dns forwarding to override the default forwarding configuration in the /etc/resolv.conf
file in the following ways:
Specify name servers (spec.servers
) for every zone. If the forwarded zone is the ingress domain managed by OKD, then the upstream name server must be authorized for the domain.
Provide a list of upstream dns servers (spec.upstreamResolvers
).
Change the default forwarding policy.
A dns forwarding configuration for the default domain can have both the default servers specified in the |
Modify the dns Operator object named default
:
$ oc edit dns.operator/default
After you issue the previous command, the Operator creates and updates the config map named dns-default
with additional server configuration blocks based on spec.servers
.
If none of the servers have a zone that matches the query, then name resolution falls back to the upstream dns servers.
apiVersion: operator.openshift.io/v1
kind: dns
metadata:
name: default
spec:
cache:
negativeTTL: 0s
positiveTTL: 0s
logLevel: Normal
nodePlacement: {}
operatorLogLevel: Normal
servers:
- name: example-server (1)
zones:
- example.com (2)
forwardPlugin:
policy: Random (3)
upstreams: (4)
- 1.1.1.1
- 2.2.2.2:5353
upstreamResolvers: (5)
policy: Random (6)
protocolStrategy: "" (7)
transportConfig: {} (8)
upstreams:
- type: SystemResolvConf (9)
- type: Network
address: 1.2.3.4 (10)
port: 53 (11)
status:
clusterDomain: cluster.local
clusterIP: x.y.z.10
conditions:
...
1 | Must comply with the rfc6335 service name syntax. |
2 | Must conform to the definition of a subdomain in the rfc1123 service name syntax. The cluster domain, cluster.local , is an invalid subdomain for the zones field. |
3 | Defines the policy to select upstream resolvers listed in the forwardPlugin . Default value is Random . You can also use the values RoundRobin , and Sequential . |
4 | A maximum of 15 upstreams is allowed per forwardPlugin . |
5 | You can use upstreamResolvers to override the default forwarding policy and forward dns resolution to the specified dns resolvers (upstream resolvers) for the default domain. If you do not provide any upstream resolvers, the dns name queries go to the servers declared in /etc/resolv.conf . |
6 | Determines the order in which upstream servers listed in upstreams are selected for querying. You can specify one of these values: Random , RoundRobin , or Sequential . The default value is Sequential . |
7 | When omitted, the platform chooses a default, normally the protocol of the original client request. Set to TCP to specify that the platform should use TCP for all upstream dns requests, even if the client request uses UDP. |
8 | Used to configure the transport type, server name, and optional custom CA or CA bundle to use when forwarding dns requests to an upstream resolver. |
9 | You can specify two types of upstreams : SystemResolvConf or Network . SystemResolvConf configures the upstream to use /etc/resolv.conf and Network defines a Networkresolver . You can specify one or both. |
10 | If the specified type is Network , you must provide an IP address. The address field must be a valid IPv4 or IPv6 address. |
11 | If the specified type is Network , you can optionally provide a port. The port field must have a value between 1 and 65535 . If you do not specify a port for the upstream, the default port is 853. |
For more information on dns forwarding, see the Coredns forward documentation.
You can inspect the status and view the details of the dns Operator
using the oc describe
command.
View the status of the dns Operator:
$ oc describe clusteroperators/dns
Though the messages and spelling might vary in a specific release, the expected status output looks like:
Status:
Conditions:
Last Transition Time: <date>
Message: dns "default" is available.
Reason: AsExpected
Status: True
Type: Available
Last Transition Time: <date>
Message: Desired and current number of dnses are equal
Reason: AsExpected
Status: False
Type: Progressing
Last Transition Time: <date>
Reason: dnsNotDegraded
Status: False
Type: Degraded
Last Transition Time: <date>
Message: dns default is upgradeable: dns Operator can be upgraded
Reason: dnsUpgradeable
Status: True
Type: Upgradeable
You can view dns Operator logs by using the oc logs
command.
View the logs of the dns Operator:
$ oc logs -n openshift-dns-operator deployment/dns-operator -c dns-operator
Log levels for Coredns and the Coredns Operator are set by using different methods. You can configure the Coredns log level to determine the amount of detail in logged error messages. The valid values for Coredns log level are Normal
, Debug
, and Trace
. The default logLevel
is Normal
.
The Coredns error log level is always enabled. The following log level settings report different error responses:
|
To set logLevel
to Debug
, enter the following command:
$ oc patch dnses.operator.openshift.io/default -p '{"spec":{"logLevel":"Debug"}}' --type=merge
To set logLevel
to Trace
, enter the following command:
$ oc patch dnses.operator.openshift.io/default -p '{"spec":{"logLevel":"Trace"}}' --type=merge
To ensure the desired log level was set, check the config map:
$ oc get configmap/dns-default -n openshift-dns -o yaml
For example, after setting the logLevel
to Trace
, you should see this stanza in each server block:
errors
log . {
class all
}
Log levels for Coredns and Coredns Operator are set by using different methods. Cluster administrators can configure the Operator log level to more quickly track down OpenShift dns issues. The valid values for operatorLogLevel
are Normal
, Debug
, and Trace
. Trace
has the most detailed information. The default operatorlogLevel
is Normal
. There are seven logging levels for Operator issues: Trace, Debug, Info, Warning, Error, Fatal, and Panic. After the logging level is set, log entries with that severity or anything above it will be logged.
operatorLogLevel: "Normal"
sets logrus.SetLogLevel("Info")
.
operatorLogLevel: "Debug"
sets logrus.SetLogLevel("Debug")
.
operatorLogLevel: "Trace"
sets logrus.SetLogLevel("Trace")
.
To set operatorLogLevel
to Debug
, enter the following command:
$ oc patch dnses.operator.openshift.io/default -p '{"spec":{"operatorLogLevel":"Debug"}}' --type=merge
To set operatorLogLevel
to Trace
, enter the following command:
$ oc patch dnses.operator.openshift.io/default -p '{"spec":{"operatorLogLevel":"Trace"}}' --type=merge
To review the resulting change, enter the following command:
$ oc get dnses.operator -A -oyaml
You should see two log level entries. The operatorLogLevel
applies to OpenShift dns Operator issues, and the logLevel
applies to the daemonset of Coredns pods:
logLevel: Trace
operatorLogLevel: Debug
To review the logs for the daemonset, enter the following command:
$ oc logs -n openshift-dns ds/dns-default
For Coredns, you can configure the maximum duration of both successful or unsuccessful caching, also known respectively as positive or negative caching. Tuning the cache duration of dns query responses can reduce the load for any upstream dns resolvers.
Setting TTL fields to low values could lead to an increased load on the cluster, any upstream resolvers, or both. |
Edit the dns Operator object named default
by running the following command:
$ oc edit dns.operator.openshift.io/default
Modify the time-to-live (TTL) caching values:
apiVersion: operator.openshift.io/v1
kind: dns
metadata:
name: default
spec:
cache:
positiveTTL: 1h (1)
negativeTTL: 0.5h10m (2)
1 | The string value 1h is converted to its respective number of seconds by Coredns. If this field is omitted, the value is assumed to be 0s and the cluster uses the internal default value of 900s as a fallback. |
2 | The string value can be a combination of units such as 0.5h10m and is converted to its respective number of seconds by Coredns. If this field is omitted, the value is assumed to be 0s and the cluster uses the internal default value of 30s as a fallback. |
To review the change, look at the config map again by running the following command:
oc get configmap/dns-default -n openshift-dns -o yaml
Verify that you see entries that look like the following example:
cache 3600 {
denial 9984 2400
}
For more information on caching, see Coredns cache.
The dns Operator 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 configuration change by setting the managementState
to Unmanaged
.
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 to Unmanaged
to apply the workaround.
Change managementState
to Unmanaged
in the dns Operator:
oc patch dns.operator.openshift.io default --type merge --patch '{"spec":{"managementState":"Unmanaged"}}'
Review managementState
of the dns Operator using the jsonpath
command line JSON parser:
$ oc get dns.operator.openshift.io default -ojsonpath='{.spec.managementState}'
"Unmanaged"
You cannot upgrade while the |
The dns Operator has two daemon sets: one for Coredns called dns-default
and one for managing the /etc/hosts
file called node-resolver
.
You might find a need to control which nodes have Coredns pods assigned and running, although this is not a common operation. For example, if the cluster administrator has configured security policies that can prohibit communication between pairs of nodes, that would necessitate restricting the set of nodes on which the daemonset for Coredns runs. If dns pods are running on some nodes in the cluster and the nodes where dns pods are not running have network connectivity to nodes where dns pods are running, dns service will be available to all pods.
The node-resolver
daemon set must run on every node host because it adds an entry for the cluster image registry to support pulling images. The node-resolver
pods have only one job: to look up the image-registry.openshift-image-registry.svc
service’s cluster IP address and add it to /etc/hosts
on the node host so that the container runtime can resolve the service name.
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.
You installed the oc
CLI.
You are logged in to the cluster as a user with cluster-admin
privileges.
Your dns Operator managementState
is set to Managed
.
To allow the daemon set for Coredns to run on certain nodes, configure a taint and toleration:
Modify the dns Operator object named default
:
$ oc edit dns.operator/default
Specify a taint key and a toleration for the taint:
spec:
nodePlacement:
tolerations:
- effect: NoExecute
key: "dns-only"
operators: Equal
value: abc
tolerationSeconds: 3600 (1)
1 | If the taint is dns-only , it can be tolerated indefinitely. You can omit tolerationSeconds . |
When working in a highly regulated environment, you might need the ability to secure dns traffic when forwarding requests to upstream resolvers so that you can ensure additional dns traffic and data privacy.
Be aware that Coredns caches forwarded connections for 10 seconds. Coredns will hold a TCP connection open for those 10 seconds if no request is issued. With large clusters, ensure that your dns server is aware that it might get many new connections to hold open because you can initiate a connection per node. Set up your dns hierarchy accordingly to avoid performance issues.
Modify the dns Operator object named default
:
$ oc edit dns.operator/default
Cluster administrators can configure transport layer security (TLS) for forwarded dns queries.
apiVersion: operator.openshift.io/v1
kind: dns
metadata:
name: default
spec:
servers:
- name: example-server (1)
zones:
- example.com (2)
forwardPlugin:
transportConfig:
transport: TLS (3)
tls:
caBundle:
name: mycacert
serverName: dnstls.example.com (4)
policy: Random (5)
upstreams: (6)
- 1.1.1.1
- 2.2.2.2:5353
upstreamResolvers: (7)
transportConfig:
transport: TLS
tls:
caBundle:
name: mycacert
serverName: dnstls.example.com
upstreams:
- type: Network (8)
address: 1.2.3.4 (9)
port: 53 (10)
1 | Must comply with the rfc6335 service name syntax. |
2 | Must conform to the definition of a subdomain in the rfc1123 service name syntax. The cluster domain, cluster.local , is an invalid subdomain for the zones field. The cluster domain, cluster.local , is an invalid subdomain for zones . |
3 | When configuring TLS for forwarded dns queries, set the transport field to have the value TLS . |
4 | When configuring TLS for forwarded dns queries, this is a mandatory server name used as part of the server name indication (SNI) to validate the upstream TLS server certificate. |
5 | Defines the policy to select upstream resolvers. Default value is Random . You can also use the values RoundRobin , and Sequential . |
6 | Required. Use it to provide upstream resolvers. A maximum of 15 upstreams entries are allowed per forwardPlugin entry. |
7 | Optional. You can use it to override the default policy and forward dns resolution to the specified dns resolvers (upstream resolvers) for the default domain. If you do not provide any upstream resolvers, the dns name queries go to the servers in /etc/resolv.conf . |
8 | Only the Network type is allowed when using TLS and you must provide an IP address. Network type indicates that this upstream resolver should handle forwarded requests separately from the upstream resolvers listed in /etc/resolv.conf . |
9 | The address field must be a valid IPv4 or IPv6 address. |
10 | You can optionally provide a port. The port must have a value between 1 and 65535 . If you do not specify a port for the upstream, the default port is 853. |
If |
View the config map:
$ oc get configmap/dns-default -n openshift-dns -o yaml
apiVersion: v1
data:
Corefile: |
example.com:5353 {
forward . 1.1.1.1 2.2.2.2:5353
}
bar.com:5353 example.com:5353 {
forward . 3.3.3.3 4.4.4.4:5454 (1)
}
.:5353 {
errors
health
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
upstream
fallthrough in-addr.arpa ip6.arpa
}
prometheus :9153
forward . /etc/resolv.conf 1.2.3.4:53 {
policy Random
}
cache 30
reload
}
kind: ConfigMap
metadata:
labels:
dns.operator.openshift.io/owning-dns: default
name: dns-default
namespace: openshift-dns
1 | Changes to the forwardPlugin triggers a rolling update of the Coredns daemon set. |
For more information on dns forwarding, see the Coredns forward documentation.