The OSI Model
The OSI model comprises seven layers:- Application Layer: Determines how applications access network services.
- Presentation Layer: Ensures data is in a usable format, including handling encryption.
- Session Layer: Manages connections and controls ports and sessions.
- Transport Layer: Transmits data using protocols like TCP or UDP.
- Network Layer: Defines the physical path for data transfer through routing.
- Data Link Layer: Specifies how data is formatted for transmission over the network.
- Physical Layer: Transmits raw bitstreams over physical media.


Understanding the OSI model is crucial not only in Kubernetes but in networking as a whole. Network policies leverage the OSI layers to enforce secure and efficient traffic control.
Understanding Kubernetes Network Policies
Network policies in Kubernetes allow you to define how pods communicate with each other, as well as with external resources. These policies specify which endpoints (including pods, services, or entire namespaces) are allowed to exchange traffic, functioning similarly to rules enforced by routers or firewalls. Imagine a scenario where you have two pods and require controlled traffic flow between them. Network policies let you set restrictions and permissions based on factors such as IP addresses, namespaces, and pod labels. For example, consider the following requirements:- Allow ingress traffic to a pod from a specific CIDR range (172.17.0.0/16), except for the subset 172.17.1.0/24.
- Permit additional traffic from pods within the namespace labeled
project: myprojectand pods with the labelrole: frontend. - Restrict ingress traffic to only TCP port 6379 (commonly used by Redis).
- Limit egress traffic so that the pod can only communicate with IP addresses in the 10.0.0.0/24 range.
- Ingress:
- Allows traffic from the CIDR range 172.17.0.0/16, with the exception of 172.17.1.0/24.
- Permits traffic from pods in the namespace with the label
project: myprojectand pods with the labelrole: frontend. - Restricts allowed traffic to TCP port 6379.
- Egress:
- Limits outbound connections to IP addresses within the 10.0.0.0/24 range.