Disable CoreDNS host forwarding when DNS is not configured #7306
Replies: 8 comments
-
Most airgap environments I've worked with have some sort of stub resolver available. I'm not sure that adding code to actively rewrite the CoreDNS manifest to handle this corner case is worth it? Kubernetes also requires a default route (even if it just just a black-hole default route) to function properly, so I would probably lean towards leaving this as something that needs to be set up properly for airgap scenarios. |
Beta Was this translation helpful? Give feedback.
-
@brandond Very good points. I did in fact run into the default route issue and solved that as you described with a blackhole default route. The DNS configuration proved to be trickier. I had initially configured a
These timeouts caused poor performance and ultimately prevented readiness probes from executing successfully. Unfortunately, the issue was intermittent, and I never was able to determine root cause. In an effort to bring the system back to a working state, I ended up removing (IIRC, I ran into different issues with At the end of the day, the experience did not give me much confidence. I felt that I was hacking around things that I expected to work out-of-the-box. I never really wanted a stub resolver, I just wanted to make K3s (CoreDNS) happy 😂. I'd like to leave this open to discussion and am happy to provide more information if needed. Hopefully others can chime in with their DNS resolver workarounds. If we feel that rewriting the CoreDNS manifest isn't worth it, maybe we can at least update the K3s Airgap documentation to address some of these requirements? Maybe with examples of supported resolver configurations? |
Beta Was this translation helpful? Give feedback.
-
Yeah, I'm happy to leave it open. I will also add that most of the air-gap environments we target are air-gapped in the traditional sense that they do not have a connection to the internet. They usually do have a local network environment with functioning routing/dns/dhcp. Think secure office, remote lab, airplane, or ship. If your air-gap environment is more of a "this box isn't plugged in to anything at all" type setup, then then our docs probably don't cover your use case. |
Beta Was this translation helpful? Give feedback.
-
I have added a section to the docs about needing a default route https://docs.k3s.io/installation/airgap#prerequisites |
Beta Was this translation helpful? Give feedback.
-
Could you explain what you did in "configuring CoreDNS as described above." |
Beta Was this translation helpful? Give feedback.
-
@thooooooomas Here's the hack I threw together to comment out the "forward" line in the Corefile after the CoreDNS manifest has been generated. This change is only made when there are no nameservers defined in /etc/resolv.conf. I'm executing it an ExecStartPost for the "k3s" systemd service:
Not very elegant, but it works 🤷♂️ |
Beta Was this translation helpful? Give feedback.
-
Just going to convert this to a discussion for now |
Beta Was this translation helpful? Give feedback.
-
The hack of commenting out the “forward” line in the CoreDns manifest is a good solution, but I was able to fix this problem by adding |
Beta Was this translation helpful? Give feedback.
-
Is your feature request related to a problem? Please describe.
When there are no DNS servers defined in
/etc/resolv.conf
, CoreDNS will not properly start -- it will remain in CrashLoopBackoff with the following error:The error from
plugin/forward
is encountered because CoreDNS is configured to forward DNS requests to the host's resolv.conf nameservers:Describe the solution you'd like
I don't expect this to be a common scenario for most, but the default Corefile prevents K3s from starting properly in an air-gapped environment where DNS is not available (and nameservers are intentionally omitted from
/etc/resolv.conf
).I think it would be reasonable for CoreDNS forwarding to be dynamically configured based on whether or not nameservers have been defined on the host -- i.e., if nameservers are present in
resolv.conf
, add theforward . /etc/resolv.conf
line; otherwise, do not. Then, if the configMap changes, trigger a rollout restart of thecoredns
deployment.Describe alternatives you've considered
As a very (VERY) crude workaround, I was able to implement the desired behavior in an
ExecStartPost
scriptlet ink3s.service
. The logic is as follows:/run/k3s/containerd/containerd.sock
to be created – this tells me that K3s has started./var/lib/rancher/k3s/server/manifests/coredns.yaml
to be created – this file has to exist before we can change it.coredns.yaml
to be newer thancontainerd.sock
(as determined by mtime) – when the manifest is newer than the containerd socket, assume K3s has touched it on startup and will not be touched again. (Probably a bad assumption?)/etc/resolv.conf
, comment out the “forward” line in the Corefile to prevent DNS requests from being forwarded to the host’s nameservers.kubectl -n kube-system rollout restart deployment coredns
.Unfortunately, I do not know Go well enough to implement this change properly 😝
Additional context
I am running K3s v1.24 in an "air-gapped" environment with an empty
/etc/resolv.conf
.Airgap images have been dropped onto the filesystem:
Beta Was this translation helpful? Give feedback.
All reactions