modify the contents of /etc/resolv.conf when the pod is running
Kubernetes provides a method to modify the configuration of the /etc/resolv.conf
file for pods using the spec.dnsConfig
and spec.dnsPolicy
fields. You can find specific information on this in the Customizing DNS Service documentation. However, this approach leads to the recreation of pods.
In our specific business scenario, we need pods to use local DNS instead of the centralized CoreDNS, even for pods created before the change in cluster DNS configuration. We need to update the nameserver for these existing pods to point to the local DNS server. However, we cannot actively delete pods or restart containers. This practice is not considered ideal in container usage, but it aligns with our company culture, as the business application doesn’t support graceful termination.