- Demo App Overview
- Default Kubernetes NetworkPolicy
- Cilium Layer 3 Policy
- Cilium Layer 4 Policy
- Cilium Layer 7 HTTP Policy
- Adding an API Key Header
- Further Reading
Demo App Overview
Our demo application runs as a single Pod with two containers listening on ports 5000 and 80. It exposes two corresponding ClusterIP Services.app=admin can communicate.
1. Default Kubernetes NetworkPolicy
We begin with a basic Kubernetes NetworkPolicy nameddemo-netpol. It selects Pods labeled app=demo and allows ingress from Pods labeled app=admin on all ports.
Verifying the Default Policy
-
Allowed: Pod with
app=admincan reach both ports. -
Denied: Pod without the label is blocked.
Before applying Cilium policies, delete the existing Kubernetes NetworkPolicy so that Cilium’s default behavior (allow all) is restored.
2. Cilium Layer 3 Policy
Createcilium-l3.yaml to reimplement the same L3 selector using Cilium’s CRD:
3. Cilium Layer 4 Policy
Tighten access to only TCP port 80. Update tocilium-l4.yaml:
4. Cilium Layer 7 HTTP Policy
Leverage Cilium’s L7 HTTP inspection to allow onlyGET /healthz and GET /api. Define cilium-l7.yaml:
5. Adding an API Key Header
Finally, require anX-API-KEY header for the /api endpoint. Update to cilium-l7-header.yaml: