From cb9a7cf806d7405e7cb029c49e785abc6dab6c6c Mon Sep 17 00:00:00 2001 From: a73x Date: Mon, 24 Mar 2025 11:43:25 +0000 Subject: feat(post): kubernetes networking --- public/posts.html | 3 + public/posts/2025-01-12-01.html | 119 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 public/posts/2025-01-12-01.html (limited to 'public') diff --git a/public/posts.html b/public/posts.html index bfb4a94..daa9570 100644 --- a/public/posts.html +++ b/public/posts.html @@ -73,6 +73,9 @@
  • Ghostty - 2024-12-28

  • +
  • +

    Kubernetes Networking - 2025-01-12

    +
  • diff --git a/public/posts/2025-01-12-01.html b/public/posts/2025-01-12-01.html new file mode 100644 index 0000000..d6453ee --- /dev/null +++ b/public/posts/2025-01-12-01.html @@ -0,0 +1,119 @@ + + + + + + + + + + a73x + + + + + + +
    +
    +
    +

    a73x

    + high effort, low reward +
    + +
    +
    + +← Posts +

    Kubernetes Networking

    +

    Every Pod in a Kubernetes cluster is given a cluster IP address. This cluster IP
    +address is unique within the entire cluster, and allows pod within the same
    +cluster to communicate with each other. However we rarely deploy just a pod, as a
    +pod is considered ephemeral, and is the most basic units of compute. We often use
    +a deployment instead, providing us with horizontal scaling and a promise
    +that a minimum number of pods will be maintained. When a pod goes down, it could
    +be recreated on any node, with a completely different IP address.

    +

    Kubernetes Services abstracts us away from the IP addresses of the pod, and
    +provides a stable IP address we can utilise instead. Services come in several types:

    + +

    A Service uses Kubernetes selectors to determine which Pods are valid backends
    +for the created service. A Service is backed by an EndpointSlice, a list of
    +valid IP address that the service's virtual IP address should route to. This
    +routing of traffic is, by default, handled by kube-proxy.

    +

    kube-proxy is a component that runs on each node that is part of the cluster. It can operate using two different backends

    + +

    It watches Services and EndpointSlices to determine how to configure the
    +backend to redirect traffic from the Service's virtual IP to one of the IP
    +addresses in the EndpointSlice.

    +

    The Pods networking is established by a CNI plugin (Container Network Interface
    +plugin). The plugin is responsible for

    + +

    A CNI plugin like Flannel, uses a vxlan backend by default.
    +vxlan wraps a MAC frame in a UDP datagram for transport across an IP network,
    +creating an overlay network that spans all nodes.

    +

    To prevent collisions, the Service CIDR and the Pod CIDR are separate.

    +

    Example

    +

    To demonstrate some of this, here is output from a kind cluster of 3 nodes.

    +
    ❯ k get nodes -o=custom-columns='NAME:.metadata.name,CIDR:.spec.podCIDR,ExternalIP:.status.addresses[0].address'
    +NAME                 CIDR            ExternalIP
    +kind-control-plane   10.244.0.0/24   172.18.0.3
    +kind-worker          10.244.1.0/24   172.18.0.2
    +kind-worker2         10.244.2.0/24   172.18.0.4
    +

    On a node, running ip route shows how traffic for Pods on other nodes is routed.

    +
    > docker exec -it kind-worker ip route
    +default via 172.18.0.1 dev eth0
    +10.244.0.0/24 via 172.18.0.3 dev eth0
    +10.244.1.2 dev vethf0b11f5a scope host
    +10.244.2.0/24 via 172.18.0.4 dev eth0
    +172.18.0.0/16 dev eth0 proto kernel scope link src 172.18.0.2
    +

    Inside a Pod, ip route returns:

    +
    root@my-shell:/# ip route
    +default via 10.244.1.1 dev eth0
    +10.244.1.0/24 via 10.244.1.1 dev eth0 src 10.244.1.2
    +10.244.1.1 dev eth0 scope link src 10.244.1.2
    +
    +

    Showing how Pod traffic is routed: traffic for Pods on the same node go directly through the Pod's eth0 interface, while traffic for Pods on the other nodes get sent to the node first, which then forwards it appropriately. Since these CIDRs overlap, the more specific route (longest prefix) takes precedence.

    + + + +
    + + + + -- cgit v1.2.3