Bỏ qua đến nội dung
DevOps Lab

CoreDNS vs Route53 — Zonal affinity

Scenario A: ClusterIP / Topology Aware Routing. Scenario B: Internal NLB + Route53.

Scenario A: Pod gọi ClusterIP service — CoreDNS + Topology Aware Routing Pod-A resolve tên service qua CoreDNS, kube-proxy DNAT đến endpoint, Topology Aware Routing giữ traffic cùng AZ AZ-a AZ-b Pod A caller AZ-a CoreDNS pod AZ-a ClusterIP kube-proxy selects endpoint Pod B endpoint AZ-a (preferred) Pod B endpoint AZ-b (skipped) DNS PreferClose $0 skipped returns ClusterIP (virtual) CoreDNS chỉ resolve tên → ClusterIP. kube-proxy mới quyết định endpoint nào.
Topology Aware RoutingEast-west trafficClusterIP service
CoreDNS role: Resolve my-svc.namespace.svc.cluster.local → trả về ClusterIP (là virtual IP, không đổi theo AZ)
Ai quyết định AZ? kube-proxy — nó giữ bảng endpoint list và dùng topology-mode: Auto để ưu tiên endpoint cùng AZ
Config cần bật:
service.kubernetes.io/topology-mode: "Auto" trên ClusterIP service

CoreDNS trong scenario này không cần thay đổi gì — nó trả ClusterIP như bình thường.

Scenario B: Pod gọi Internal NLB — Route53 Zonal Affinity Pod resolve NLB DNS qua CoreDNS forward lên Route53. Route53 trả NLB ENI IP theo AZ của source. Zonal Affinity ở Route53 level. AZ-a AZ-b Pod A caller AZ-a CoreDNS just a forwarder Route53 Resolver Zonal Affinity ON — picks ENI by src IP NLB ENI AZ-a ← Route53 picks this NLB ENI AZ-b skipped Target Pod AZ-a $0 Target Pod AZ-b not reached DNS forward returns ENI IP AZ-a not returned $0 Route53 dùng source IP của CoreDNS pod/node để detect AZ
NLB Zonal AffinityRoute53 levelNorth-south traffic
CoreDNS role: Chỉ là forwarder — nhận DNS query từ Pod, forward lên Route53 resolver (169.254.169.253)
Ai quyết định AZ? Route53 — dựa vào source IP của DNS query (là IP của CoreDNS pod hoặc node) để detect AZ, rồi trả về NLB ENI IP cùng AZ
Caveat quan trọng: Nếu CoreDNS pod chạy ở AZ-a nhưng Pod caller ở AZ-b → Route53 trả ENI AZ-a → vẫn cross-AZ! Đây là lý do cần topologySpreadConstraints cho cả CoreDNS deployment.

Config cần bật:
dns_record.client_routing_policy: availability_zone_affinity — trên NLB
topologySpreadConstraints — cho CoreDNS pods phân bổ đều 3 AZ
CoreDNS service không cần thêm topology-mode — nó không route traffic, chỉ forward DNS.