16.7 Service CIDR vs Pod CIDR

Right, let’s settle this. You’ve seen --service-cidr and --pod-cidr flags thrown around, and if you’re anything like me, you initially thought, “A CIDR is a CIDR, what’s the big deal?” I’m here to tell you the distinction is one of the most fundamental, yet initially confusing, parts of Kubernetes networking. Mixing them up is like confusing the highway (Pod CIDR) with the highway’s on-ramp signage system (Service CIDR). One carries the actual traffic, the other is a brilliant abstraction to find that traffic.

16.6 kube-proxy: iptables, IPVS, and nftables Modes

Right, let’s talk about kube-proxy. You’ve probably heard it’s the thing that makes Kubernetes Services work, and that’s mostly true. But if you think it’s a traditional proxy—some daemon sitting in the middle of the data path, inspecting packets and making decisions—I’ve got news for you. That would be horrifically inefficient. Instead, kube-proxy is a gloriously clever (and sometimes gloriously convoluted) system-level programmer. Its job isn’t to proxy traffic, but to manipulate the networking rules on the host (the iptables, IPVS, or nftables we’re about to dive into) so that traffic heading for a virtual Service IP gets magically redirected to an actual healthy Pod.

16.5 Cilium: eBPF-Powered Networking, Observability, and Security

Alright, let’s roll up our sleeves and talk about Cilium. If the basic CNI plugins we’ve discussed are like reliable, simple sedans, Cilium is a fully-loaded, self-driving concept car from the future. It still connects your pods to the network, which is its job as a CNI plugin, but it throws out the old, cumbersome iptables-based plumbing and replaces it with eBPF. This isn’t just an incremental upgrade; it’s a fundamental rewrite of the kernel’s networking and security logic, and it changes everything.

16.4 Calico: BGP-Based Networking and Network Policy

Alright, let’s get our hands dirty with Calico. If you’ve been around the Kubernetes block, you’ve heard the name. It’s not just another CNI plugin; it’s more like the opinionated, highly-capable network engineer of the container world. While many CNIs slap a big virtual switch (VXLAN, I’m looking at you) over everything and call it a day, Calico often takes a different, radically sensible approach: it treats your data center like what it actually is—a network—and uses the Border Gateway Protocol (BGP) to have intelligent conversations with it.

16.3 Flannel: Simple Overlay Network

Alright, let’s talk about Flannel. If Kubernetes networking were a high school clique, Flannel would be the reliable, unassuming friend who shows up with a six-pack and knows how to get the router working. It’s not the flashiest, it won’t brag about its features, but it will get the job done with a minimum of fuss. Its entire reason for existence is to solve one problem: making sure every Pod in your cluster gets a unique IP address that every other Pod (and Node) can talk to, regardless of which physical machine it’s sitting on. It does this using one of the oldest tricks in the networking book: an overlay network.

16.2 CNI: How Kubernetes Delegates Networking

Right, so you’ve got a Kubernetes cluster humming along. Pods are scheduled, the API server is doing its thing, and then… a new Pod lands on a node. It has an IP address, but how did it get there? The kubelet didn’t fuss with any ip commands. That’s because it outsourced the entire messy business of networking to a bunch of smaller, specialized programs through a standard contract called the Container Network Interface (CNI).

16.1 The Pod Network Model: Every Pod Gets Its Own IP

Alright, let’s get our hands dirty with the one networking concept Kubernetes absolutely nails: the Pod Network Model. Forget everything you know about Docker’s janky port-mapping circus. In Kubernetes, every pod—yes, every single pod—gets its own, bona fide IP address. This isn’t a suggestion; it’s the entire foundation of the network model, and it’s brilliant in its simplicity. Think about it. If every pod has a unique IP on a flat network, your application doesn’t need to care about where it’s running. It just needs to know the IP of the pod it wants to talk to. No more wrestling with environment variables for port numbers or some convoluted discovery service just to find a neighboring container. A frontend pod can connect to a backend pod at 10.244.1.15:8080 just as easily as you can ping 8.8.8.8. This eliminates a massive class of network address translation (NAT) headaches and makes debugging a dream. You can curl a pod’s IP directly from any node, or even from your laptop if your network is set up right. It’s the network as it was meant to be: dumb, predictable, and transparent.

14.7 Visualizing and Testing Network Policies

Right, so you’ve written a NetworkPolicy. You’ve stared at the YAML, you’ve run kubectl apply -f, and it returned without an error. Fantastic. Now for the multi-million dollar question: is it actually doing what you think it’s doing? This is where most people’s eyes glaze over and they just hope for the best. Don’t be that person. Hope is not a strategy; it’s a prelude to a 3 AM page. Let’s get tactical and verify our work.

14.6 CNI Plugin Requirements: Calico, Cilium, Weave

Right, let’s talk about the plumbing. You’ve got your shiny Network Policies written, a set of perfect, declarative rules telling your pods exactly who they can and can’t talk to. You apply them…and nothing happens. The traffic flows merrily along, completely ignoring your carefully crafted security intentions. Welcome to the most common “oh crap” moment with Network Policies. The truth they don’t lead with in the marketing docs is this: Network Policies are not a feature of Kubernetes itself. They are a specification. It’s a wish list you hand off to the actual entity running your cluster’s network: the Container Network Interface (CNI) plugin.

14.5 Default Deny All: The Secure Baseline

Right, let’s talk about the single most important concept in securing your Kubernetes cluster’s network: starting from a position of “absolutely nothing is allowed.” This isn’t just a good idea; it’s the only sane way to begin. You wouldn’t build a castle and just leave the drawbridge down with a welcome mat, would you? Default Deny All is that raised drawbridge. It’s the security baseline that says, “Until I explicitly say a pod can talk to something, it lives in solitary confinement.”

14.4 Restricting Egress to Specific CIDRs and Ports

Right, so you’ve got your pods running, but letting them talk to anything on the internet is like giving a toddler your credit card and telling them to go wild on Amazon. It’s a bad idea, and you’re going to get a nasty surprise. We need to lock down what they can call out to. This is where egress rules in Network Policies come in, and they’re your first, best line of defense against data exfiltration, crypto-mining pods, or just plain old “oops, that pod called the wrong API 50,000 times a second.”

14.3 Restricting Ingress from Specific Pods and Namespaces

Right, so you’ve got a cluster up and running, pods are chatting away happily, and now you need to introduce some law and order. You don’t want every pod in the dev namespace being able to poke at your super-secret payment-processor pod, do you? Of course not. This is where you stop being a benevolent creator and start being a traffic cop with a badge and a serious attitude. Network Policies are your Kubernetes-native tool for this job. They’re not some add-on; they’re first-class citizens that define how pods are allowed to communicate with each other and other network endpoints. Think of them as firewall rules for your cluster, but way more pod-aware. The crucial thing to remember is that by default, if no Network Policies are present, all traffic is allowed. It’s a “default allow” world. The moment you slap a Network Policy on a pod, you shift it into a “default deny” mode for that direction (ingress/egress), and you must explicitly allow what you want. This trips up everyone at least once.

14.2 NetworkPolicy Spec: podSelector, policyTypes, ingress, egress

Alright, let’s get our hands dirty with the actual spec of a NetworkPolicy. This is where the rubber meets the road. Think of a NetworkPolicy as a very specific, very powerful bouncer for your Pod’s network traffic. It doesn’t just let anything in or out; it checks the guest list. The spec is how you write that list. The core blueprint looks like this: apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: my-detail-oriented-bouncer spec: podSelector: {} # Which Pods does this bouncer guard? policyTypes: # What kind of rules are we defining? - Ingress - Egress ingress: [] # The fine-print rules for incoming traffic egress: [] # The fine-print rules for outgoing traffic Let’s break down each part of this bouncer’s contract.

14.1 Default Allow-All and Why It Is Dangerous

Right out of the box, your Kubernetes cluster is a model of reckless optimism. It operates on a principle of “default allow-all.” This is the networking equivalent of leaving your front door wide open with a sign that says, “All valuables are in the upstairs safe, which is also unlocked.” Every pod can talk to every other pod, and every pod can initiate egress traffic to the entire internet. It’s convenient for getting started, but it’s a security nightmare waiting to happen.

— joke —

...