Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dns caching #64

Merged
merged 1 commit into from
Sep 18, 2024
Merged

add dns caching #64

merged 1 commit into from
Sep 18, 2024

Conversation

aojea
Copy link
Owner

@aojea aojea commented Sep 6, 2024

Pass through cache for A and AAAA records with ttl 30 seconds
Only captures Pods requests

TODO:

  • autopath
  • nxdomain caching
  • cache dns requests or request content?

@aojea aojea force-pushed the dnscache branch 2 times, most recently from 1833460 to 20eff25 Compare September 6, 2024 14:29
@BenTheElder
Copy link

oh no

@aojea
Copy link
Owner Author

aojea commented Sep 9, 2024

oh no

/hold

@aojea aojea force-pushed the dnscache branch 2 times, most recently from 9f91d60 to 4ba36e7 Compare September 13, 2024 09:20
Comment on lines +644 to +688
func (d *DNSCacheAgent) lookupIP(ctx context.Context, network, host string) ([]net.IP, error) {
ips, ok := d.cache.get(network, host, expireTimeout)
if ok {
klog.V(4).Infof("Cached entries for %s %s : %v", network, host, ips)
return ips, nil
}
ips, err := d.resolver.LookupIP(ctx, network, host)
if err != nil {
// cache empty answers
if e, ok := err.(*net.DNSError); !ok || !e.IsNotFound {
return nil, err
}
}
d.cache.add(network, host, ips)
klog.V(4).Infof("Caching new entries for %s %s : %v", network, host, ips)
return ips, nil
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the important thing to solve:

  • cache agent has the pod parameters ndots and searches (it is deployed as a hostnetwork pod with dnsPoliyc: ClusterFirstWithHostNet)
  • when pod ask for kubernetes.default the resolver on the pod will append all searches until the number of ndots
I0913 09:47:13.869272       1 dnscache.go:249] UDP connection from 100.96.1.14:59154
I0913 09:47:13.869338       1 dnscache.go:283] dialing from 100.64.0.10:53 to 100.96.1.14:59154
I0913 09:47:13.869435       1 dnscache.go:444] starting parsing packet
I0913 09:47:13.869469       1 dnscache.go:559] DNS A request for kubernetes.default.default.svc.cluster.local.
I0913 09:47:13.869484       1 dnscache.go:658] Cached entries for ip4 kubernetes.default.default.svc.cluster.local. : []
I0913 09:47:13.869498       1 dnscache.go:496] answer correct
I0913 09:47:13.870417       1 dnscache.go:249] UDP connection from 100.96.1.14:52573
I0913 09:47:13.870465       1 dnscache.go:283] dialing from 100.64.0.10:53 to 100.96.1.14:52573
I0913 09:47:13.870550       1 dnscache.go:444] starting parsing packet
I0913 09:47:13.870578       1 dnscache.go:559] DNS A request for kubernetes.default.svc.cluster.local.
I0913 09:47:13.871531       1 dnscache.go:669] Caching new entries for ip4 kubernetes.default.svc.cluster.local. : [100.64.0.1]
I0913 09:47:13.871627       1 dnscache.go:568] DNS A request for kubernetes.default.svc.cluster.local. ips: [100.64.0.1]
I0913 09:47:13.871640       1 dnscache.go:496] answer correct
I0913 09:47:13.874943       1 dnscache.go:249] UDP connection from 100.96.1.14:55191
I0913 09:47:13.874996       1 dnscache.go:283] dialing from 100.64.0.10:53 to 100.96.1.14:55191
I0913 09:47:13.875084       1 dnscache.go:444] starting parsing packet
I0913 09:47:13.875150       1 dnscache.go:589] DNS AAAA request for kubernetes.default.svc.cluster.local.
I0913 09:47:13.876114       1 dnscache.go:669] Caching new entries for ip6 kubernetes.default.svc.cluster.local. : []
I0913 09:47:13.876212       1 dnscache.go:496] answer correct

This means that the cache CAN know the original question of the pod and can deduplicate all these queries to answer on the first query ... this will be a big improvement since it will allow to remove all the amplification added by searches @thockin

@aojea aojea force-pushed the dnscache branch 2 times, most recently from bff7c81 to 18da2f0 Compare September 16, 2024 22:02
Change-Id: If90379e54b08ffab3c909b889e9dd532931aaf3e
@aojea aojea merged commit bed264b into main Sep 18, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants