Sub topic 1
Why Pods Can Reach Each Other by Default
Prerequisites
This chapter assumes you can:
- Run pods, Deployments and Services and read their YAML.
- Use namespaces and labels.
- Apply manifests with
kubectl. - Read basic TCP/UDP port numbers and CIDR notation.
The Kubernetes network model
Kubernetes sets a few simple rules for pod networking:
- Every pod gets its own IP address.
- Any pod can reach any other pod by that IP, with no NAT in between.
- This works across nodes and across namespaces.
The cluster is effectively one flat network. A pod in dev can open a connection to a database pod in prod if it knows the address. Namespaces group objects for naming and access control. They do not separate network traffic.
Default allow
A pod with no network policy selecting it is called non-isolated. It accepts traffic from any source and can send traffic to any destination. The default is open on purpose. It keeps first deployments simple, because nothing needs configuring before pods can talk to each other.
The cost is that one compromised pod can scan and attack everything else. Network policies exist to narrow this down.
See the default in action
Create a backend and test it from an unrelated pod. The nginx image listens on port 80, so the Service maps port 8080 to it.
kubectl create namespace demo
kubectl create deployment backend --image=nginx:1.27 -n demo
kubectl label deployment backend app=backend -n demo --overwrite
kubectl expose deployment backend --port=8080 --target-port=80 -n demo
kubectl wait --for=condition=available deployment/backend -n demo --timeout=60s
kubectl run test --rm -it --image=busybox:1.36 --restart=Never --labels=app=frontend -n demo -- wget -qO- -T 3 http://backend:8080The last command prints the nginx welcome page. The test pod has no special permission. Nothing blocks it.
What a network policy changes
A NetworkPolicy is a Kubernetes object that selects pods by label and lists the traffic those pods may send or receive. Once a policy selects a pod for a given direction, that pod becomes isolated for that direction. It accepts only what policies explicitly allow. Pods that no policy selects keep the default behavior.
The chapters that follow build on this: how policies are written, how they are enforced, and how to combine them.
Common mistakes at this stage
- Assuming namespaces isolate traffic. They do not.
- Assuming a Service restricts who can call it. A Service only provides a stable address.
- Applying a policy on a cluster whose network plugin ignores it, then concluding the cluster is protected.
Exercise
A pod in the dev namespace tries to connect to a pod IP in the prod namespace, and no NetworkPolicy exists in the cluster. Does the connection succeed, and why?
Show answer
Yes. Without any policy selecting the target pod, the pod is non-isolated and accepts traffic from any source. The Kubernetes network model gives every pod a reachable IP across namespaces, and namespaces do not separate network traffic.