L3/L4 rules in Cilium
A CiliumNetworkPolicy specifies apiVersion, kind, metadata (including namespace) and a spec that selects the endpoints (pods) to which the policy applies. Cilium uses endpointSelector to select endpoints. By default, policies are namespace-scoped: a policy created in namespacedev matches endpoints in dev unless you explicitly reference other namespaces.
Example — allow ingress to backend pods from frontend pods in the same namespace (dev):
Cilium’s endpointSelector is namespace-aware by default. If you need cross-namespace matching, include explicit namespace labels in matchLabels or use a cluster-wide policy.
- Allow frontend pods to talk only to backend pods:
- Allow all egress within the same namespace:
- Use empty lists (ingress: [] and egress: []) to explicitly deny all traffic to the selected endpoints:
To explicitly deny all ingress/egress for selected endpoints use empty lists (ingress: [] and egress: []). In contrast, a rule like
ingress: - {} allows ingress from any source because it represents a rule entry with no source constraints.- You can match traffic via service references:
k8sService(serviceName + namespace) ork8sServiceSelector(label selector + namespace). This implicitly matches the pods behind the service and can reference services across namespaces.
- Use
toCIDRandtoCIDRSetto allow traffic to IPv4/IPv6 ranges and to exclude subranges with theexceptfield.
L4 rules (ports)
You can target ports without specifying L3 selectors. If a rule matches only on ports, it applies to traffic targeting any endpoint (subject to the policy’s namespace scoping).- Allow egress on TCP port 80 to any pod (in the policy’s namespace):
- Port range example (80 through 444):
- Allow frontend -> backend only on TCP/80:
- Allow egress to a CIDR on a specific port:
L7 (application layer) capabilities
Cilium supports application-layer controls including HTTP, DNS, and FQDN-based egress. These L7 filters require L4 match criteria (port/protocol) to scope inspection. HTTP filtering example — only allow GET /products from frontend to backend on port 80:- When restricting egress, ensure your pods can still reach DNS (kube-dns) or name resolution will break. Cilium can inspect DNS L7 payloads and also support
toFQDNsso Cilium tracks DNS responses and allows the resolved IP addresses at runtime.
Entities (special keywords)
Cilium defines entities for common endpoint types such as the Kubernetes API server, host, and world (the public internet). UsetoEntities or fromEntities to reference them.
- Allow a pod to reach the kube-apiserver:

NodePort and world entity
When you expose a pod via a NodePort, the internet can reach it by default. If you attach a CiliumNetworkPolicy that denies ingress to that pod, the NodePort traffic will also be blocked unless you explicitly allow it. To permit ingress from the internet, allow theworld entity.

Deny policies
Cilium supports explicit deny lists. Deny rules take precedence over allow rules, ensuring that disallowed sources remain blocked even if they match an allow rule. Example — allow frontend but explicitly deny pods labeledtest: test (deny wins):
Cluster-wide policies
Standard Kubernetes NetworkPolicies are namespace-scoped. Cilium providesCiliumClusterwideNetworkPolicy for policies that apply across namespaces. Cluster-wide policies omit the namespace field in metadata and their endpointSelector matches endpoints cluster-wide.
- Allow all backend pods cluster-wide to accept ingress from frontend pods cluster-wide:
- Restrict source to frontends only in a specific namespace (
dev) while applying the policy cluster-wide:
- To ensure all pods can resolve DNS, create a cluster-wide policy that matches all endpoints and allows egress to kube-dns (and any DNS names / external FQDNs your workloads require):
Summary
- L3/L4 rules in Cilium operate similarly to Kubernetes NetworkPolicy, with namespace-aware endpoint selectors by default.
- L7 rules (HTTP, DNS, FQDN) offer fine-grained application-layer controls when paired with L4 scoping.
- Entities (host, world, kube-apiserver) simplify references to common external or node-local endpoints.
- Deny rules take priority over allow rules—explicit denies override allows.
- Use CiliumClusterwideNetworkPolicy to apply policies across namespaces when cross-namespace control is required.
- Cilium Network Policy docs: https://cilium.io/
- Kubernetes NetworkPolicy concepts: https://kubernetes.io/docs/concepts/services-networking/network-policies/
- Cilium L7 (HTTP, DNS, FQDN) documentation: https://docs.cilium.io/en/stable/policy/l7/