Skip to content
LinkState
Go back

Pod to CoreDNS packet walk that explains silent lookup failure

Introduction to Kubernetes Networking

Kubernetes networking is a complex and multifaceted system that enables communication between pods, services, and external networks. Understanding the components and communication flows within Kubernetes is crucial for troubleshooting and optimizing DNS resolution.

Overview of Kubernetes Components

Kubernetes consists of several components that work together to provide networking functionality:

DNS Query Flow

The DNS query flow in Kubernetes involves several components and hops.

Initiation of DNS Query from Pod

A pod initiates a DNS query by sending a UDP packet to the CoreDNS server. The packet contains the service name to be resolved.

# Example DNS query packet
tcpdump -i any -n -vv -s 0 -c 1 -W 100 port 53

The packet is sent to the CoreDNS server, which is typically running on a cluster node.

Packet Flow through veth and Bridge

The packet is received by the veth interface of the pod and forwarded to the bridge.

# Example packet flow through veth and bridge
bridge link show
ip link show veth*

The bridge forwards the packet to the Kube-Proxy or eBPF component for service VIP translation.

Service VIP Translation and Kube-Proxy

Kube-Proxy or eBPF translates the service VIP address to a pod IP address.

# Example Kube-Proxy configuration
kubectl get configmap kube-proxy -o yaml

The translated packet is then forwarded to the destination pod.

Kube-Proxy Service Handling

Kube-Proxy is a component that implements service VIP translation and load balancing.

Overview of Kube-Proxy

Kube-Proxy runs on each node and watches the API server for changes to services and endpoints.

# Example Kube-Proxy logs
kubectl logs -f kube-proxy

Kube-Proxy supports several modes: User Space Proxy, IPTABLES, and IPVS.

User Space Proxy Mode

In User Space Proxy mode, Kube-Proxy runs as a userspace program and forwards packets to the destination pod.

# Example User Space Proxy configuration
kubectl get configmap kube-proxy -o yaml | grep mode

IPTABLES Mode

In IPTABLES mode, Kube-Proxy uses iptables rules to translate the service VIP address to a pod IP address.

# Example IPTABLES configuration
iptables -n -t nat -L

IPVS Mode

In IPVS mode, Kube-Proxy uses IPVS (IP Virtual Server) to load balance traffic to multiple pods.

# Example IPVS configuration
ipvsadm -L

eBPF Service Handling

eBPF (extended Berkeley Packet Filter) is a technology that allows running sandboxed programs in the kernel.

Introduction to eBPF

eBPF provides a way to extend the kernel functionality without modifying the kernel code.

# Example eBPF program
bpftool prog show

eBPF Service Handling in Kubernetes

In Kubernetes, eBPF can be used to implement service VIP translation and load balancing.

# Example eBPF service handling configuration
kubectl get configmap ebpf-service -o yaml

Cilium and eBPF

Cilium is a networking platform that uses eBPF to provide networking functionality in Kubernetes.

# Example Cilium configuration
kubectl get configmap cilium-config -o yaml

CoreDNS

CoreDNS is a DNS server that provides name resolution for pods and services.

Overview of CoreDNS

CoreDNS is a flexible and extensible DNS server that supports multiple plugins.

# Example CoreDNS configuration
kubectl get configmap coredns -o yaml

CoreDNS Configuration

CoreDNS configuration is stored in a ConfigMap and can be updated dynamically.

# Example CoreDNS configuration update
kubectl patch configmap coredns -p='[{"op": "replace", "path": "/Corefile", "value": "example.com:53 { ... }"}]'

CoreDNS Plugins

CoreDNS supports multiple plugins, including the Kubernetes plugin.

# Example CoreDNS plugin configuration
kubectl get configmap coredns -o yaml | grep plugin

Troubleshooting DNS Resolution Issues

Troubleshooting DNS resolution issues involves identifying the root cause of the problem.

Identifying Issues in the DNS Query Flow

Identifying issues in the DNS query flow involves checking the packet flow and DNS server logs.

# Example DNS query flow debugging
tcpdump -i any -n -vv -s 0 -c 1 -W 100 port 53
kubectl logs -f coredns

Debugging Kube-Proxy and eBPF

Debugging Kube-Proxy and eBPF involves checking the logs and configuration.

# Example Kube-Proxy and eBPF debugging
kubectl logs -f kube-proxy
kubectl get configmap kube-proxy -o yaml
bpftool prog show

CoreDNS Logging and Debugging

CoreDNS logging and debugging involves checking the logs and configuration.

# Example CoreDNS logging and debugging
kubectl logs -f coredns
kubectl get configmap coredns -o yaml

Code Examples

Code examples for Kube-Proxy, eBPF, and CoreDNS configuration are provided below.

Kube-Proxy Configuration

Kube-Proxy configuration example:

apiVersion: v1
kind: ConfigMap
metadata:
  name: kube-proxy
data:
  config.conf: |
    apiVersion: kubeproxy.config.k8s.io/v1alpha1
    kind: KubeProxyConfiguration
    mode: "iptables"

eBPF Configuration

eBPF configuration example:

apiVersion: v1
kind: ConfigMap
metadata:
  name: ebpf-service
data:
  config.yaml: |
    apiVersion: ebpf.io/v1
    kind: EBPFService
    spec:
      programs:
      - name: example
        type: socket
        socketCreate: true

CoreDNS Configuration

CoreDNS configuration example:

apiVersion: v1
kind: ConfigMap
metadata:
  name: coredns
data:
  Corefile: |
    example.com:53 {
      kubernetes cluster.local in-addr.arpa ip6.arpa {
        pods insecure
        fallthrough in-addr.arpa ip6.arpa
      }
      prometheus :9153
      proxy . /etc/resolv.conf
      cache 30
    }

CLI Examples

CLI examples for debugging and troubleshooting DNS resolution issues are provided below.

Using kubectl to Debug DNS Issues

Using kubectl to debug DNS issues:

kubectl get pods -o wide
kubectl get svc -o wide
kubectl get ep -o wide

Using tcpdump to Capture DNS Traffic

Using tcpdump to capture DNS traffic:

tcpdump -i any -n -vv -s 0 -c 1 -W 100 port 53

Using dig and nslookup for DNS Troubleshooting

Using dig and nslookup for DNS troubleshooting:

dig example.com
nslookup example.com

Share this post on:

Previous Post
Why only large DNS answers fail behind policy
Next Post
Walking a SYN through every stall point