You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
__podSelector__: Each `NetworkPolicy` includes a `podSelector` which selects the grouping of pods to which the policy applies. Since `NetworkPolicy` currently only supports defining `ingress` rules, this `podSelector` essentially defines the "destination pods" for the policy. The example policy selects pods with the label "role=db". An empty `podSelector` selects all pods in the namespace.
62
72
63
-
__ingress__: Each `NetworkPolicy` includes a list of whitelist `ingress` rules. Each rule allows traffic which matches both the `from` and `ports` sections. The example policy contains a single rule, which matches traffic on a single port, from either of two sources, the first specified via a `namespaceSelector` and the second specified via a `podSelector`.
73
+
__policyTypes__: Each `NetworkPolicy` includes a `policyTypes` list which may include either `Ingress`, `Egress`, or both. The `policyTypes` field indicates whether or not the given policy applies to ingress traffic to selected pod, egress traffic from selected pods, or both.
74
+
75
+
__ingress__: Each `NetworkPolicy` may include a list of whitelist `ingress` rules. Each rule allows traffic which matches both the `from` and `ports` sections. The example policy contains a single rule, which matches traffic on a single port, from either of two sources, the first specified via a `namespaceSelector` and the second specified via a `podSelector`.
76
+
77
+
__egress__: Each `NetworkPolicy` may include a list of whitelist `egress` rules. Each rule allows traffic which matches both the `to` and `ports` sections. The example policy contains a single rule, which matches traffic on a single port to any destination in `10.0.0.0/24`.
64
78
65
79
So, the example NetworkPolicy:
66
80
@@ -72,7 +86,12 @@ See the [NetworkPolicy getting started guide](/docs/getting-started-guides/netwo
72
86
73
87
## Default policies
74
88
75
-
You can create a "default" isolation policy for a Namespace by creating a NetworkPolicy that selects all pods but does not allow any traffic:
89
+
By default, if no policies exist in a namespace, then all ingress and egress traffic is allowed to and from pods in that Namespace. The following examples let you change the default behavior
90
+
for a given namespace.
91
+
92
+
### Default deny all ingress traffic
93
+
94
+
You can create a "default" isolation policy for a Namespace by creating a NetworkPolicy that selects all pods but does not allow any ingress traffic:
76
95
77
96
```yaml
78
97
apiVersion: networking.k8s.io/v1
@@ -81,11 +100,16 @@ metadata:
81
100
name: default-deny
82
101
spec:
83
102
podSelector:
103
+
policyTypes:
104
+
- Ingress
84
105
```
85
106
86
-
This ensures that even pods that aren't selected by any other NetworkPolicy will still be isolated.
107
+
This ensures that even pods that aren't selected by any other NetworkPolicy will still be isolated. This policy does not change
108
+
the default egress isolation behavior.
87
109
88
-
Alternatively, if you want to allow all traffic for all pods in a Namespace (even if policies are added that cause some pods to be treated as "isolated"), you can create a policy that explicitly allows all traffic:
110
+
### Default allow all ingress traffic
111
+
112
+
If you want to allow all traffic for all pods in a Namespace (even if policies are added that cause some pods to be treated as "isolated"), you can create a policy that explicitly allows all traffic:
89
113
90
114
```yaml
91
115
apiVersion: networking.k8s.io/v1
@@ -98,6 +122,42 @@ spec:
98
122
- {}
99
123
```
100
124
125
+
### Default deny all egress traffic.
126
+
127
+
You can create a "default" egress isolation policy for a Namespace by creating a NetworkPolicy that selects all pods but does not allow any egress traffic:
128
+
129
+
```yaml
130
+
apiVersion: networking.k8s.io/v1
131
+
kind: NetworkPolicy
132
+
metadata:
133
+
name: default-deny
134
+
spec:
135
+
podSelector:
136
+
policyTypes:
137
+
- Egress
138
+
```
139
+
140
+
This ensures that even pods that aren't selected by any other NetworkPolicy will not be allowed egress traffic. This policy does not
141
+
change the default ingress isolation behavior.
142
+
143
+
### Default deny all ingress and all egress traffic
144
+
145
+
You can create a "default" policy for a Namespace which prevents all ingress AND egress traffic by creating the following NetworkPolicy:
146
+
147
+
```yaml
148
+
apiVersion: networking.k8s.io/v1
149
+
kind: NetworkPolicy
150
+
metadata:
151
+
name: default-deny
152
+
spec:
153
+
podSelector:
154
+
policyTypes:
155
+
- Ingress
156
+
- Egress
157
+
```
158
+
159
+
This ensures that even pods that aren't selected by any other NetworkPolicy will not be allowed ingress or egress traffic.
160
+
101
161
## What's next?
102
162
103
163
- See the [Declare Network Policy](/docs/tasks/administer-cluster/declare-network-policy/)
0 commit comments