Add a local DNS zone to your k3s CoreDNS
In your private cluster, you may want to access resources located in your local network with a local DNS name, which is in some configurations not possible out of the box.
Althogh it is possible to change the CoreDNS configuration, that the cluster DNS server will resolve the declared zones using a specific DNS resolver.
To achieve this, it is required to add a line to the CoreDNS Corefile for each DNS zone with the corresponding DNS resolver ip address by setting forward myzone.local 10.0.0.255
To apply this configuration in your k3s, where CoreDNS is provided using a manifest file on each k3s master node, create a override file at /var/lib/rancher/k3s/server/manifests/coredns.override.yaml
with the following content (which is basically a copy of the original ConfigMap with just the additional changes)
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns
namespace: kube-system
data:
Corefile: |
.:53 {
errors
health
ready
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
fallthrough in-addr.arpa ip6.arpa
}
hosts /etc/coredns/NodeHosts {
ttl 60
reload 15s
fallthrough
}
prometheus :9153
forward myzone.local 10.0.0.255
forward . /etc/resolv.conf
log
cache 60
loop
reload
loadbalance
}
Make sure to create this file on every master node in your k3s cluster, otherwise it will not be applied or only applied temporarly.