Questo contenuto non è disponibile nella lingua selezionata.
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 Copia collegamentoCollegamento copiato negli appunti!
The DNS Operator implements the
dns
operator.openshift.io
Procedure
The DNS Operator is deployed during installation with a
Deployment
Use the
command to view the deployment status:oc get$ oc get -n openshift-dns-operator deployment/dns-operatorExample output
NAME READY UP-TO-DATE AVAILABLE AGE dns-operator 1/1 1 1 23hUse the
command to view the state of the DNS Operator:oc get$ oc get clusteroperator/dnsExample output
NAME VERSION AVAILABLE PROGRESSING DEGRADED SINCE dns 4.1.0-0.11 True False False 92m,AVAILABLEandPROGRESSINGprovide information about the status of the operator.DEGRADEDisAVAILABLEwhen at least 1 pod from the CoreDNS daemon set reports anTruestatus condition.Available
5.2. Changing the DNS Operator managementState Copia collegamentoCollegamento copiato negli appunti!
DNS manages the CoreDNS component to provide a name resolution service for pods and services in the cluster. The
managementState
Managed
Unmanaged
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 to
managementState.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 field of the DNS Operator to
managementStateto apply the workaround.Unmanaged
Procedure
Change
DNS Operator:managementStateoc patch dns.operator.openshift.io default --type merge --patch '{"spec":{"managementState":"Unmanaged"}}'
5.3. Controlling DNS pod placement Copia collegamentoCollegamento copiato negli appunti!
The DNS Operator has two daemon sets: one for CoreDNS and one for managing the
/etc/hosts
/etc/hosts
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 CLI.
oc -
You are logged in to the cluster with a user with privileges.
cluster-admin
Procedure
To prevent communication between certain nodes, configure the
API field:spec.nodePlacement.nodeSelectorModify the DNS Operator object named
:default$ oc edit dns.operator/defaultSpecify a node selector that includes only control plane nodes in the
API field:spec.nodePlacement.nodeSelectorspec: nodePlacement: nodeSelector: node-role.kubernetes.io/worker: ""
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/defaultSpecify a taint key and a toleration for the taint:
spec: nodePlacement: tolerations: - effect: NoExecute key: "dns-only" operators: Equal value: abc tolerationSeconds: 36001 - 1
- If the taint is
dns-only, it can be tolerated indefinitely. You can omittolerationSeconds.
5.4. View the default DNS Copia collegamentoCollegamento copiato negli appunti!
Every new OpenShift Container Platform installation has a
dns.operator
default
Procedure
Use the
command to view the defaultoc describe:dns$ oc describe dns.operator/defaultExample output
Name: default Namespace: Labels: <none> Annotations: <none> API Version: operator.openshift.io/v1 Kind: DNS ... Status: Cluster Domain: cluster.local1 Cluster IP: 172.30.0.102 ...To find the service CIDR of your cluster, use the
command:oc get$ oc get networks.config/cluster -o jsonpath='{$.status.serviceNetwork}'
Example output
[172.30.0.0/16]
5.5. Using DNS forwarding Copia collegamentoCollegamento copiato negli appunti!
You can use DNS forwarding to override the default forwarding configuration in the
/etc/resolv.conf
- Specify name servers for every 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.
- Provide a list of upstream DNS servers.
- Change the default forwarding policy.
A DNS forwarding configuration for the default domain can have both the default servers specified in the
/etc/resolv.conf
Procedure
Modify the DNS Operator object named
:default$ oc edit dns.operator/defaultAfter you issue the previous command, the Operator creates and updates the config map named
with additional server configuration blocks based ondns-default. If none of the servers have a zone that matches the query, then name resolution falls back to the upstream DNS servers.ServerConfiguring DNS forwarding
apiVersion: operator.openshift.io/v1 kind: DNS metadata: name: default spec: servers: - name: example-server1 zones:2 - example.com forwardPlugin: policy: Random3 upstreams:4 - 1.1.1.1 - 2.2.2.2:5353 upstreamResolvers:5 policy: Random6 upstreams:7 - type: SystemResolvConf8 - type: Network address: 1.2.3.49 port: 5310 - 1
- Must comply with the
rfc6335service name syntax. - 2
- Must conform to the definition of a subdomain in the
rfc1123service name syntax. The cluster domain,cluster.local, is an invalid subdomain for thezonesfield. - 3
- Defines the policy to select upstream resolvers. Default value is
Random. You can also use the valuesRoundRobin, andSequential. - 4
- A maximum of 15
upstreamsis allowed perforwardPlugin. - 5
- 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. - 6
- Determines the order in which upstream servers are selected for querying. You can specify one of these values:
Random,RoundRobin, orSequential. The default value isSequential. - 7
- Optional. You can use it to provide upstream resolvers.
- 8
- You can specify two types of
upstreams-SystemResolvConfandNetwork.SystemResolvConfconfigures the upstream to use/etc/resolv.confandNetworkdefines aNetworkresolver. You can specify one or both. - 9
- If the specified type is
Network, you must provide an IP address. Theaddressfield must be a valid IPv4 or IPv6 address. - 10
- If the specified type is
Network, you can optionally provide a port. Theportfield must have a value between1and65535. If you do not specify a port for the upstream, by default port 853 is tried.
Optional: 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. Cluster administrators can configure transport layer security (TLS) for forwarded DNS queries.
Configuring DNS forwarding with TLS
apiVersion: operator.openshift.io/v1 kind: DNS metadata: name: default spec: servers: - name: example-server1 zones:2 - example.com forwardPlugin: transportConfig: transport: TLS3 tls: caBundle: name: mycacert serverName: dnstls.example.com4 policy: Random5 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: Network8 address: 1.2.3.49 port: 5310 - 1
- Must comply with the
rfc6335service name syntax. - 2
- Must conform to the definition of a subdomain in the
rfc1123service name syntax. The cluster domain,cluster.local, is an invalid subdomain for thezonesfield. The cluster domain,cluster.local, is an invalidsubdomainforzones. - 3
- When configuring TLS for forwarded DNS queries, set the
transportfield to have the valueTLS. By default, 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. - 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 valuesRoundRobin, andSequential. - 6
- Required. You can use it to provide upstream resolvers. A maximum of 15
upstreamsentries are allowed perforwardPluginentry. - 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
Networktype indicates that this upstream resolver should handle forwarded requests separately from the upstream resolvers listed in/etc/resolv.conf. Only theNetworktype is allowed when using TLS and you must provide an IP address.- 9
- The
addressfield must be a valid IPv4 or IPv6 address. - 10
- You can optionally provide a port. The
portmust have a value between1and65535. If you do not specify a port for the upstream, by default port 853 is tried.
NoteIf
is undefined or invalid, the config map only contains the default server.servers
Verification
View the config map:
$ oc get configmap/dns-default -n openshift-dns -o yamlSample DNS ConfigMap based on previous sample DNS
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:54541 } .: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
forwardPlugintriggers a rolling update of the CoreDNS daemon set.
5.6. DNS Operator status Copia collegamentoCollegamento copiato negli appunti!
You can inspect the status and view the details of the DNS Operator using the
oc describe
Procedure
View the status of the DNS Operator:
$ oc describe clusteroperators/dns
5.7. DNS Operator logs Copia collegamentoCollegamento copiato negli appunti!
You can view DNS Operator logs by using the
oc logs
Procedure
View the logs of the DNS Operator:
$ oc logs -n openshift-dns-operator deployment/dns-operator -c dns-operator
5.8. Setting the CoreDNS log level Copia collegamentoCollegamento copiato negli appunti!
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
Trace
logLevel
Normal
The errors plugin is always enabled. The following
logLevel
-
:
logLevelenables the "errors" class:Normal.log . { class error } -
:
logLevelenables the "denial" class:Debug.log . { class denial error } -
:
logLevelenables the "all" class:Trace.log . { class all }
Procedure
To set
tologLevel, enter the following command:Debug$ oc patch dnses.operator.openshift.io/default -p '{"spec":{"logLevel":"Debug"}}' --type=mergeTo set
tologLevel, enter the following command:Trace$ oc patch dnses.operator.openshift.io/default -p '{"spec":{"logLevel":"Trace"}}' --type=merge
Verification
To ensure the desired log level was set, check the config map:
$ oc get configmap/dns-default -n openshift-dns -o yaml
5.9. Setting the CoreDNS Operator log level Copia collegamentoCollegamento copiato negli appunti!
Cluster administrators can configure the Operator log level to more quickly track down OpenShift DNS issues. The valid values for
operatorLogLevel
Normal
Debug
Trace
Trace
operatorlogLevel
Normal
-
sets
operatorLogLevel: "Normal".logrus.SetLogLevel("Info") -
sets
operatorLogLevel: "Debug".logrus.SetLogLevel("Debug") -
sets
operatorLogLevel: "Trace".logrus.SetLogLevel("Trace")
Procedure
To set
tooperatorLogLevel, enter the following command:Debug$ oc patch dnses.operator.openshift.io/default -p '{"spec":{"operatorLogLevel":"Debug"}}' --type=mergeTo set
tooperatorLogLevel, enter the following command:Trace$ oc patch dnses.operator.openshift.io/default -p '{"spec":{"operatorLogLevel":"Trace"}}' --type=merge