kubernetesrustdnskube-rs

How to listen for Kubernetes DNS changes


I have a controller using the kube crate that manages various worker resources (services/deployments). In those containers, I receive updates from the controller via a ConfigMap and make downstream requests to other Kubernetes services. As part of this, I do DNS queries, via the hickory-resolver crate, to resolve the IP of those down stream services. I'm concerned a bit about the DNS caching.

What event/resource do I need to subscribe to from the controller to initiate a dump the DNS cache in Hickory (it has a method off its resolver to do so)? Or am I over thinking this and the TTL will solve this for me?


Solution

  • After some more research and chatting with ChatGPT, I learned about the EndpointSlice resources. These resources hold pages of the IP addresses (both v4/v6) for a given Service. Since I have the service names I require elsewhere, I can watch for EndpointSlice events and collect what I need. Additional benefits include:

    Overall, this is much more robust than DNS!