Skip to main content
Calico Open Source 3.33 (latest) documentation

Staged Kubernetes network policy

A staged Kubernetes network policy resource (StagedKubernetesNetworkPolicy) represents a staged version of Kubernetes network policy. This is used to preview network behavior before actually enforcing the network policy. Once persisted, this is converted to a Calico network policy that is not enforced. StagedKubernetesNetworkPolicy is a namespaced resource.

For kubectl commands, you can use the aliases stagedkubernetesnetworkpolicy.projectcalico.org, stagedkubernetesnetworkpolicies.projectcalico.org, stagedkubernetesnetworkpolicy.p, and stagedkubernetesnetworkpolicies.p.

Sample YAML​

This sample is the example policy from the Kubernetes NetworkPolicy documentation, with only the apiVersion and kind changed to make it a staged Kubernetes network policy.

apiVersion: projectcalico.org/v3
kind: StagedKubernetesNetworkPolicy
metadata:
name: test-network-policy
namespace: default
spec:
podSelector:
matchLabels:
role: db
policyTypes:
- Ingress
- Egress
ingress:
- from:
- ipBlock:
cidr: 172.17.0.0/16
except:
- 172.17.1.0/24
- namespaceSelector:
matchLabels:
project: myproject
- podSelector:
matchLabels:
role: frontend
ports:
- protocol: TCP
port: 6379
egress:
- to:
- ipBlock:
cidr: 10.0.0.0/24
ports:
- protocol: TCP
port: 5978

Definition​

Metadata​

FieldDescriptionAccepted ValuesSchemaDefault
nameThe name of this staged Kubernetes network policy. Required.Lowercase alphanumeric characters, -, or .. Must start and end with an alphanumeric character. Up to 253 characters.string
namespaceThe namespace this staged Kubernetes network policy belongs to.string

Spec​

StagedKubernetesNetworkPolicy adds the stagedAction field to the Kubernetes NetworkPolicy spec. It inherits the other spec fields, podSelector, ingress, egress, and policyTypes, and their nested types from Kubernetes. For those fields, see NetworkPolicySpec in the Kubernetes API reference.

FieldDescriptionAccepted ValuesSchemaDefault
stagedActionThe staged action. With Delete, leave every other spec field empty, and the policy is not sent to Felix.Set, Delete, Learn, IgnorestringSet

Default policy types​

If you omit policyTypes and the policy has no egress rules, the policy applies to ingress traffic only. If the policy has egress rules, set this field: when it is omitted, clusters that use native v3 CRDs store Ingress, Egress, but clusters that use the Calico API server apply the policy to ingress traffic only.

Additional resources​