How to fix Network policy not enforced in Kubernetes
Network policy errors occur when Calico policies are not enforced or configured incorrectly. Fix by verifying policy syntax, enabling enforcement mode, and checking for conflicting rules.
Quick fix
Fixes Network policy not enforced
kubectl get deployment -n calico-system calico-kube-controllers
kubectl logs -n calico-system -l app=calico-kube-controllers- Verify Calico policy controller is running
- Check NetworkPolicy YAML syntax
- Verify pod selectors match actual pods
- Enable default deny policy gradually
kubectl get deployment -n calico-system calico-kube-controllerskubectl logs -n calico-system -l app=calico-kube-controllersNetwork policy not enforced
What this error means
Calico implements Kubernetes NetworkPolicy and native Calico policy for network access control. When policies are not enforced, traffic flows despite policy rules that should block it. This happens due to misconfigured policies, incorrect enforcement mode, or issues with the policy controller.
Typical symptoms
- Traffic allowed despite NetworkPolicy rules forbidding it
- Network policies appear correctly configured but ineffective
- Pods communicate when they should be blocked
- Error CALICO-1014 in logs indicating policy enforcement failure
- Policy rules updating slowly or not at all
- Network policies work on some pods but not others
- Service mesh policies conflicting with Calico policies
- Logging shows traffic being allowed when should be denied
Common causes
- Policy enforcement mode not enabled for the namespace
- Calico policy controller not running or healthy
- Network policy YAML syntax errors
- Incorrect selector matching pods
- Missing allow rules when switching to default deny
- Rule order causing early Allow before intended Deny
- Conflict between Kubernetes NetworkPolicy and Calico policies
- Service mesh sidecar proxies bypassing network policies
How to fix "Network policy not enforced"
Ensure the policy controller deployment is healthy:
kubectl get deployment -n calico-system calico-kube-controllers
kubectl logs -n calico-system -l app=calico-kube-controllersIf not running, restart it.
Validate policy YAML for errors:
kubectl apply -f network-policy.yaml --dry-run=client
kubectl validate -f network-policy.yamlLook for indentation errors, invalid selectors, or missing required fields.
Ensure your selectors correctly identify target pods:
kubectl get pods --show-labels
kubectl get networkpolicy -o yaml | grep -A 5 "podSelector|namespaceSelector"Matching labels must be present on the target pods.
When enforcing policies, start with logging before blocking:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-ingress
spec:
podSelector: {}
policyTypes:
- Ingress
ingress:
- from:
- namespaceSelector:
matchLabels:
allow-traffic: "true"For more control, use native Calico policies:
apiVersion: projectcalico.org/v3
kind: GlobalNetworkPolicy
metadata:
name: default-deny
spec:
selector: "all()"
order: 0
types:
- IngressCalico policies have more features like policy ordering.
Policies are evaluated in order - deny rules must come after allow:
spec:
order: 10 # Lower numbers evaluated first
ingress:
- action: Allow
from:
- namespaceSelector:
matchLabels:
team: backend
- action: Deny
from:
- namespaceSelector: {}Enable flow logs to see which policies are matching:
calicoctl apply -f - << EOF
apiVersion: projectcalico.org/v3
kind: FelixConfiguration
metadata:
name: default
spec:
flowLogsFileEnabled: true
flowLogsFile: /var/log/calico/flows.log
EOFReview logs to see policy evaluations.
Force policy reload by restarting controller:
kubectl rollout restart deployment/calico-kube-controllers -n calico-system
kubectl rollout status deployment/calico-kube-controllers -n calico-systemAdvanced notes
For production, use Calico policy for precise control over deny/allow ordering and performance. Test policies in logging mode before enforcement. Document policy intent and keep rules as simple as possible. Use namespaceSelector and podSelector consistently. Monitor policy violations via logs to catch unintended blocks. For service mesh, ensure policies work with sidecar proxies or disable proxying for policy enforcement.
Frequently asked questions
- What does "Network policy not enforced" mean?
- Calico implements Kubernetes NetworkPolicy and native Calico policy for network access control. When policies are not enforced, traffic flows despite policy rules that should block it. This happens due to misconfigured policies, incorrect enforcement mode, or issues with the policy controller.
- How do I fix "Network policy not enforced"?
- Network policy errors occur when Calico policies are not enforced or configured incorrectly. Fix by verifying policy syntax, enabling enforcement mode, and checking for conflicting rules.
- What causes "Network policy not enforced"?
- Policy enforcement mode not enabled for the namespace Calico policy controller not running or healthy Network policy YAML syntax errors
- Is the "Network policy not enforced" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Kubernetes Official Documentation
- ๐Calico Network Policy(Official Docs)
- ๐Policy Enforcement Options(Official Docs)
- ๐Default Deny Policy(Official Docs)