K8S CoreDNS Fall Through
2 minute read
What is fallthrough
?
fallthrough
is a directive used in CoreDNS configurations to allow queries to continue to the next plugin if no matching answer is found. Essentially, it helps in handling unresolved DNS queries by passing them to subsequent plugins in the CoreDNS chain.
How it Works:
When a DNS query is received, CoreDNS processes it through a series of plugins as specified in the CoreDNS configuration file. If one plugin cannot resolve the query, it may pass the query to the next plugin if the fallthrough
directive is used.
Example Use Case:
Consider the following CoreDNS configuration using the hosts
plugin with the fallthrough
directive:
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns-custom
namespace: kube-system
data:
appname.override: |
hosts {
10.0.0.115 appname.domain.net
fallthrough
}
What This Configuration Does:
Hosts Plugin: The
hosts
plugin is used to define static DNS entries.10.0.0.115 appname.domain.net
: Maps the IP address10.0.0.115
to the domainappname.domain.net
.
Fallthrough Directive: The
fallthrough
directive allows the query to proceed to the next plugin if no matching entry is found in thehosts
plugin.- If a query for
appname.domain.net
is received, thehosts
plugin will resolve it to10.0.0.115
. - If a query for any other domain is received (not defined in the
hosts
plugin), it will fall through to the next plugin in the CoreDNS configuration for further resolution.
- If a query for
Benefits of Using fallthrough
:
- Enhanced Flexibility: Allows combining multiple DNS sources for query resolution.
- Redundancy: Ensures that unresolved queries are not dropped but are passed to the next available resolver.
- Custom Configurations: Facilitates custom DNS setups where certain domains are resolved internally, while others are handled by external DNS servers.
Real-World Scenario:
Imagine you have a Kubernetes cluster where certain internal services are resolved using static IP addresses, but you also want to allow external domain resolution. You can configure CoreDNS with the hosts
plugin for internal services and fallthrough
to external DNS servers.
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns-custom
namespace: kube-system
data:
Corefile: |
.:53 {
errors
hosts {
10.0.0.115 appname.domain.net
fallthrough
}
forward . /etc/resolv.conf
cache 30
loop
reload
loadbalance
}
In this example:
- The
hosts
plugin resolvesappname.domain.net
to10.0.0.115
. - The
forward
plugin handles queries not resolved by thehosts
plugin, forwarding them to the external DNS servers specified in/etc/resolv.conf
.
Using fallthrough
, you can create a robust and flexible DNS setup in your Kubernetes cluster, ensuring seamless resolution of both internal and external domains.
Feedback
Was this page helpful?
Glad to hear it!
Sorry to hear that.