Skip to main content
To improve the DNS performance in a Managed Service for Kubernetes cluster, you can use the NodeLocal DNSCache feature. With this feature, a DNS caching agent runs on each cluster node to resolve DNS requests locally on the same nodes as the Pods. In this tutorial, you will learn to configure a NodeLocal DNSCache for the Cilium network policy controller by using local redirect policy.

Costs

Nebius AI Cloud charges you only for running a Managed Kubernetes cluster. For more details, see the Managed Kubernetes pricing.

Prerequisites

Steps

Prepare manifests for NodeLocal DNSCache and local redirect policy

  1. Retrieve the service IP address for coredns:
  2. Create a manifest file named node-local-dns.yaml. In the DaemonSet specification (spec.template.spec.containers.args), replace the coredns_IP_address with the IP address of the coredns service you obtained in the previous step.
    This manifest declares a DaemonSet for NodeLocal DNSCache and a service account, service and ConfigMap needed for its operation.
  3. Create a manifest file named node-local-dns-lrp.yaml.
    This manifest declares a local redirect policy that directs DNS requests at the node-local-dns DaemonSet for resolution.

Apply the manifests and create resources

  1. Create resources for NodeLocal DNSCache:
  2. Create the local redirect policy:

Test NodeLocal DNSCache

Create a test environment

  1. Create a manifest file named dnsutils.yaml.
  2. Launch the dnsutils Pod:
  3. Find out which node is running the dnsutils Pod:
    The result looks like the following:
    Once the Pod status is Running, get the ID of the node from the NODE column.
  4. Use the ID of the node to find out the IP address of the Pod that runs NodeLocal DNSCache on this node:

Run tests

  1. Get the values of the metrics for DNS requests before testing:
    The result looks like the following:
  2. Run several DNS requests:
  3. Now check the metrics again:
    The values of the metrics should increase, for example:
    If the tests don’t show the expected metrics increase, there may be an error in your configuration.

Troubleshoot issues and inspect logs

  • Check that the local redirect policy is enabled in the Cilium configuration:
    The expected result is:
  • Check that the node-local-dns local redirect policy declared earlier is properly applied:
    The expected result is something like the following:
  • Check the local redirect policy rules on any of the Cilium Pods:
    • Get the list of Cilium Pods:
    • Get the local redirect policy rules on one of these Pods:
      The expected result is something like the following:
  • Check the contents of the resolv.conf file in the dnsutils Pod:
    The expected result is something like the following:
  • Check DNS logs. To enable logs for Pods running DNS services, create a custom ConfigMap coredns-custom.yaml that contains a log.override key:
    Apply the custom ConfigMap:
    To enable logs for the node-local-dns service, edit the ConfigMap:
    Add the log config parameter within the Corefile section:
    Now you can get the logs of the Pods running DNS services:

Delete testing resources

Delete the dnsutils Pod:

How to disable NodeLocal DNSCache

If you no longer want to use NodeLocal DNSCache in your cluster, you can disable it:
  1. Delete the local redirect policy:
  2. Delete the resources you created for NodeLocal DNSCache:

How to delete the created resources\

The Managed Kubernetes cluster you used in this tutorial is chargeable. If you do not need it, delete this resource, so Nebius AI Cloud does not charge for it.