Network Policies
What applies by default#
- Your namespaces accept traffic from every pod in the cluster. Nothing is restricted until you add a
NetworkPolicy. - Platform namespaces (starting with
k7e-) don't accept connections from your pods. Reach platform services through their public addresses. - Outgoing traffic is not restricted.
Restricting traffic to your application#
A common setup: allow traffic from inside the namespace, from the ingress controller and from Prometheus, and nothing else. Both the ingress controller and Prometheus run in the platform namespace k7e-system:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-own-namespace-and-platform
namespace: my-app
spec:
podSelector: {}
policyTypes:
- Ingress
ingress:
- from:
- podSelector: {}
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: k7e-system
Network policies add up: a pod accepts a connection if any policy that selects it allows it. See the Kubernetes documentation for all options.