Sub topic 16
Gateway API compared with Ingress, and CNI plugins
This chapter assumes you can write a Service and an Ingress, and that you know what a Pod CIDR is. It compares Ingress with its successor, Gateway API. It then looks at the layer below Services: the CNI plugin that gives each Pod its network.
Gateway API compared with Ingress
Ingress has one resource and a small spec. Anything beyond host and path routing, such as header matching, traffic splitting or timeouts, goes into controller-specific annotations. Those annotations are not portable between controllers.
Gateway API splits the job into separate resources, each with its own owner:
| Resource | Typical owner | Purpose |
|---|---|---|
| GatewayClass | Infrastructure provider | Names a controller implementation |
| Gateway | Cluster operator | Defines listeners (port, protocol) |
| HTTPRoute | Application developer | Maps hosts and paths to Services |
Routes attach to a Gateway through parentRefs. A Gateway can control which namespaces may attach routes, so teams can share one load balancer safely.
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: public
spec:
gatewayClassName: example-class
listeners:
- name: http
protocol: HTTP
port: 80
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: web
spec:
parentRefs:
- name: public
hostnames:
- example.com
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: web
port: 80Header matching and weighted backendRefs are part of the standard API. Gateway API also covers TCP and gRPC routes, which Ingress does not. Ingress still works and is simpler for basic HTTP. Choose Gateway API when several teams share infrastructure or you need portable advanced routing.
CNI plugins and how Pod networking is built
Kubernetes requires every Pod to reach every other Pod by IP, but it does not implement that itself. A Container Network Interface (CNI) plugin does.
When the kubelet asks the container runtime to start a Pod, the runtime calls the CNI plugin:
- The runtime creates the Pod's network namespace.
- The plugin creates a virtual Ethernet pair (veth). One end goes inside the Pod and the other stays on the node.
- The plugin's IP address management (IPAM) step picks an address from the node's Pod CIDR.
- The plugin sets up routes so other nodes can reach that address.
Plugins differ in how traffic crosses nodes. Overlay plugins wrap packets in VXLAN or similar tunnels and work on almost any network. Routed plugins advertise Pod CIDRs with BGP and avoid encapsulation. Cloud-native plugins give Pods addresses from the VPC itself. By default, the runtime reads plugin configuration from /etc/cni/net.d and finds plugin binaries in /opt/cni/bin.
Exercise
A teammate applies a NetworkPolicy and sees no change in traffic. Name two possible causes covered in this chapter or earlier.
Show answer
The cluster's CNI plugin may not enforce NetworkPolicy, so the object is stored but ignored. The policy's podSelector may also not match the intended Pods' labels.