1. How containers communicate #
Basic networking.
Model #
- Docker: per-host bridge networks (isolation by named network), overlay networks between Swarm hosts.
- Kubernetes: each pod has an IP, all pods can reach each other by default; the CNI (Calico, Cilium, Flannel) implements this network.
- Services provide a stable address; Ingress or the Gateway API expose to the outside.
Common mistake: By default, Kubernetes isolates nothing: a compromised pod can reach every database in the cluster. The first measure is a default-deny policy.
2. The measures #
Layer by layer.
NetworkPolicies #
# Refus par défaut dans le namespace, puis ouverture explicite
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata: { name: default-deny, namespace: shop }
spec: { podSelector: {}, policyTypes: [Ingress, Egress] }
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata: { name: api-to-db, namespace: shop }
spec:
podSelector: { matchLabels: { app: postgres } }
ingress:
- from: [ { podSelector: { matchLabels: { app: api } } } ]
ports: [ { port: 5432 } ]Good to know: NetworkPolicies only apply if the CNI implements them (Calico, Cilium yes; Flannel alone no). Remember to allow DNS (port 53 to kube-dns) in egress rules.
Other layers #
| Measure | Tool | Protects against |
|---|---|---|
| mTLS between services | Istio, Linkerd, Cilium | Eavesdropping and spoofing on the cluster network |
| Egress control | Egress policies, outbound proxy | Data exfiltration, downloading tools |
| Ingress | Ingress with TLS, WAF, rate limiting | Application attacks |
| Flow observability | Hubble (Cilium), Network Performance Monitoring | Unexpected flows going undetected |
My progress
Sign in to track your progress and take notes. Sign in
💬 Questions about this lesson
No questions yet: be the first to ask for help or share your configuration.
Course Glossary
Kubernetes
An open-source container orchestration engine (sometimes called K8s) for automating the deployment, scaling, and management of containerized applicati...
Recommended Articles
Securing Kubernetes: RBAC, NetworkPolicies, container network security and Pod Security
Securing Kubernetes: RBAC (Role, ClusterRole, bindings), ServiceAccounts, NetworkPolicies, Pod Se...
Kubernetes CNI: Flannel, Calico and Cilium compared
Kubernetes CNI: understand network plugins (Container Network Interface) and compare Flannel, Cal...
Observing the Kubernetes network with Cilium Hubble
Make a Kubernetes cluster's network flows visible with Cilium Hubble: architecture, the hubble ob...
HAProxy in Kubernetes: the high-performance Ingress Controller
Discover in depth how HAProxy integrates with Kubernetes: direct-to-pod architecture, hot update ...
Container registry: choosing and securing your image registry (Docker Hub, Harbor, GHCR, ECR)
Understand container registries: Docker Hub, GitHub Container Registry, cloud registries (ECR, AC...
Kubernetes: architecture and components (control plane, nodes, objects)
Understand the Kubernetes architecture: API server, etcd, scheduler, controller manager, kubelet,...
Kubernetes Services: ClusterIP, NodePort, LoadBalancer and ExternalName
Kubernetes Services explained: the role of a Kubernetes service, the ClusterIP, NodePort, LoadBal...
Kubernetes: exposing your applications (Services, Ingress and Gateway API)
Expose applications in Kubernetes: ClusterIP/NodePort/LoadBalancer Services, Ingress, IngressClas...
ConfigMaps and Secrets
A complete guide to ConfigMaps and Secrets in Kubernetes.