@@ -54,7 +54,7 @@ The entities that a Pod can communicate with are identified through a combinatio
54
54
-->
55
55
Pod 可以与之通信的实体是通过如下三个标识符的组合来辩识的:
56
56
57
- 1 . 其他被允许的 Pods (例外:Pod 无法阻塞对自身的访问)
57
+ 1 . 其他被允许的 Pod (例外:Pod 无法阻塞对自身的访问)
58
58
2 . 被允许的名字空间
59
59
3 . IP 组块(例外:与 Pod 运行所在的节点的通信总是被允许的,
60
60
无论 Pod 或节点的 IP 地址)
@@ -68,6 +68,7 @@ Meanwhile, when IP based NetworkPolicies are created, we define policies based o
68
68
-->
69
69
在定义基于 Pod 或名字空间的 NetworkPolicy 时,
70
70
你会使用{{< glossary_tooltip text="选择算符" term_id="selector">}}来设定哪些流量可以进入或离开与该算符匹配的 Pod。
71
+
71
72
另外,当创建基于 IP 的 NetworkPolicy 时,我们基于 IP 组块(CIDR 范围)来定义策略。
72
73
73
74
<!-- body -->
@@ -106,13 +107,15 @@ By default, a pod is non-isolated for egress; all outbound connections are allow
106
107
A pod is isolated for egress if there is any NetworkPolicy that both selects the pod and has
107
108
"Egress" in its `policyTypes`; we say that such a policy applies to the pod for egress.
108
109
When a pod is isolated for egress, the only allowed connections from the pod are those allowed by
109
- the `egress` list of some NetworkPolicy that applies to the pod for egress.
110
+ the `egress` list of some NetworkPolicy that applies to the pod for egress. Reply traffic for those
111
+ allowed connections will also be implicitly allowed.
110
112
The effects of those `egress` lists combine additively.
111
113
-->
112
114
默认情况下,一个 Pod 的出口是非隔离的,即所有外向连接都是被允许的。如果有任何的 NetworkPolicy
113
115
选择该 Pod 并在其 ` policyTypes ` 中包含 “Egress”,则该 Pod 是出口隔离的,
114
116
我们称这样的策略适用于该 Pod 的出口。当一个 Pod 的出口被隔离时,
115
117
唯一允许的来自 Pod 的连接是适用于出口的 Pod 的某个 NetworkPolicy 的 ` egress ` 列表所允许的连接。
118
+ 针对那些允许连接的应答流量也将被隐式允许。
116
119
这些 ` egress ` 列表的效果是相加的。
117
120
118
121
<!--
@@ -121,13 +124,14 @@ A pod is isolated for ingress if there is any NetworkPolicy that both selects th
121
124
has "Ingress" in its `policyTypes`; we say that such a policy applies to the pod for ingress.
122
125
When a pod is isolated for ingress, the only allowed connections into the pod are those from
123
126
the pod's node and those allowed by the `ingress` list of some NetworkPolicy that applies to
124
- the pod for ingress. The effects of those `ingress` lists combine additively.
127
+ the pod for ingress. Reply traffic for those allowed connections will also be implicitly allowed.
128
+ The effects of those `ingress` lists combine additively.
125
129
-->
126
130
默认情况下,一个 Pod 对入口是非隔离的,即所有入站连接都是被允许的。如果有任何的 NetworkPolicy
127
131
选择该 Pod 并在其 ` policyTypes ` 中包含 “Ingress”,则该 Pod 被隔离入口,
128
132
我们称这种策略适用于该 Pod 的入口。当一个 Pod 的入口被隔离时,唯一允许进入该 Pod
129
133
的连接是来自该 Pod 节点的连接和适用于入口的 Pod 的某个 NetworkPolicy 的 ` ingress `
130
- 列表所允许的连接。这些 ` ingress ` 列表的效果是相加的。
134
+ 列表所允许的连接。针对那些允许连接的应答流量也将被隐式允许。 这些 ` ingress ` 列表的效果是相加的。
131
135
132
136
<!--
133
137
Network policies do not conflict; they are additive. If any policy or policies apply to a given
@@ -142,8 +146,8 @@ either side does not allow the connection, it will not happen.
142
146
Pod 在对应方向所允许的连接是适用的网络策略所允许的集合。
143
147
因此,评估的顺序不影响策略的结果。
144
148
145
- 要允许从源 Pod 到目的 Pod 的连接 ,源 Pod 的出口策略和目的 Pod 的入口策略都需要允许连接 。
146
- 如果任何一方不允许连接,建立连接将会失败 。
149
+ 要允许从源 Pod 到目的 Pod 的某个连接 ,源 Pod 的出口策略和目的 Pod 的入口策略都需要允许此连接 。
150
+ 如果任何一方不允许此连接,则连接将会失败 。
147
151
148
152
<!--
149
153
## The NetworkPolicy resource {#networkpolicy-resource}
@@ -158,7 +162,7 @@ An example NetworkPolicy might look like this:
158
162
参阅 [ NetworkPolicy] (/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#networkpolicy-v1-networking-k8s-io)
159
163
来了解资源的完整定义。
160
164
161
- 下面是一个 NetworkPolicy 的示例:
165
+ 下面是一个 NetworkPolicy 的示例:
162
166
163
167
{{< code_sample file="service/networking/networkpolicy.yaml" >}}
164
168
@@ -167,7 +171,7 @@ An example NetworkPolicy might look like this:
167
171
POSTing this to the API server for your cluster will have no effect unless your chosen networking
168
172
solution supports network policy.
169
173
-->
170
- 除非选择支持网络策略的网络解决方案,否则将上述示例发送到API服务器没有任何效果 。
174
+ 除非选择支持网络策略的网络解决方案,否则将上述示例发送到 API 服务器没有任何效果 。
171
175
{{< /note >}}
172
176
173
177
<!--
@@ -245,7 +249,7 @@ So, the example NetworkPolicy:
245
249
See the [Declare Network Policy](/docs/tasks/administer-cluster/declare-network-policy/)
246
250
walkthrough for further examples.
247
251
-->
248
- 所以,该网络策略示例:
252
+ 所以,该网络策略示例:
249
253
250
254
1 . 隔离 ` default ` 名字空间下 ` role=db ` 的 Pod (如果它们不是已经被隔离的话)。
251
255
2 . (Ingress 规则)允许以下 Pod 连接到 ` default ` 名字空间下的带有 ` role=db `
@@ -469,7 +473,7 @@ creating the following NetworkPolicy in that namespace.
469
473
-->
470
474
### 默认拒绝所有入站和所有出站流量 {#default-deny-all-ingress-and-all-egress-traffic}
471
475
472
- 你可以为名字空间创建“默认” 策略,以通过在该名字空间中创建以下 NetworkPolicy
476
+ 你可以为名字空间创建 “default” 策略,以通过在该名字空间中创建以下 NetworkPolicy
473
477
来阻止所有入站和出站流量。
474
478
475
479
{{< code_sample file="service/networking/network-policy-default-deny-all.yaml" >}}
@@ -573,20 +577,20 @@ NetworkPolicy 规约中使用 `endPort` 字段。
573
577
In this scenario, your `Egress` NetworkPolicy targets more than one namespace using their
574
578
label names. For this to work, you need to label the target namespaces. For example:
575
579
-->
576
- ## 按标签选择多个命名空间 {#targeting-multiple-namespaces-by-label}
580
+ ## 按标签选择多个名字空间 {#targeting-multiple-namespaces-by-label}
577
581
578
582
在这种情况下,你的 ` Egress ` NetworkPolicy 使用名字空间的标签名称来将多个名字空间作为其目标。
579
583
为此,你需要为目标名字空间设置标签。例如:
580
584
581
585
``` shell
582
- kubectl label namespace frontend namespace=frontend
583
- kubectl label namespace backend namespace=backend
586
+ kubectl label namespace frontend namespace=frontend
587
+ kubectl label namespace backend namespace=backend
584
588
```
585
589
586
590
<!--
587
591
Add the labels under `namespaceSelector` in your NetworkPolicy document. For example:
588
592
-->
589
- 在 NetworkPolicy 文档中的 namespaceSelector 下添加标签。例如:
593
+ 在 NetworkPolicy 文档中的 ` namespaceSelector ` 下添加标签。例如:
590
594
591
595
``` yaml
592
596
apiVersion : networking.k8s.io/v1
@@ -614,9 +618,9 @@ It is not possible to directly specify the name of the namespaces in a NetworkPo
614
618
You must use a ` namespaceSelector` with `matchLabels` or `matchExpressions` to select the
615
619
namespaces based on their labels.
616
620
-->
617
- 你不可以在 NetworkPolicy 中直接指定命名空间的名称 。
621
+ 你不可以在 NetworkPolicy 中直接指定名字空间的名称 。
618
622
你必须使用带有 `matchLabels` 或 `matchExpressions` 的 `namespaceSelector`
619
- 来根据标签选择命名空间 。
623
+ 来根据标签选择名字空间 。
620
624
{{< /note >}}
621
625
622
626
<!--
@@ -834,14 +838,33 @@ implemented using the NetworkPolicy API.
834
838
- The ability to prevent loopback or incoming host traffic (Pods cannot currently block localhost
835
839
access, nor do they have the ability to block access from their resident node).
836
840
-->
837
- - 实现适用于所有名字空间或 Pods 的默认策略(某些第三方 Kubernetes 发行版本或项目可以做到这点);
841
+ - 实现适用于所有名字空间或 Pod 的默认策略(某些第三方 Kubernetes 发行版本或项目可以做到这点);
838
842
- 高级的策略查询或者可达性相关工具;
839
843
- 生成网络安全事件日志的能力(例如,被阻塞或接收的连接请求);
840
844
- 显式地拒绝策略的能力(目前,NetworkPolicy 的模型默认采用拒绝操作,
841
845
其唯一的能力是添加允许策略);
842
846
- 禁止本地回路或指向宿主的网络流量(Pod 目前无法阻塞 localhost 访问,
843
847
它们也无法禁止来自所在节点的访问请求)。
844
848
849
+ <!--
850
+ # # NetworkPolicy's impact on existing connections
851
+
852
+ When the set of NetworkPolicies that applies to an existing connection changes - this could happen
853
+ either due to a change in NetworkPolicies or if the relevant labels of the namespaces/pods selected by the
854
+ policy (both subject and peers) are changed in the middle of an existing connection - it is
855
+ implementation defined as to whether the change will take effect for that existing connection or not.
856
+ Example : A policy is created that leads to denying a previously allowed connection, the underlying network plugin
857
+ implementation is responsible for defining if that new policy will close the existing connections or not.
858
+ It is recommended not to modify policies/pods/namespaces in ways that might affect existing connections.
859
+ -->
860
+ # # NetworkPolicy 对现有连接的影响 {#networkpolicys-impact-on-existing-connections}
861
+
862
+ 当应用到现有连接的 NetworkPolicy 集合发生变化时,这可能是由于 NetworkPolicy
863
+ 发生变化或者在现有连接过程中(主体和对等方)策略所选择的名字空间或 Pod 的相关标签发生变化,
864
+ 此时是否对该现有连接生效是由实现定义的。例如:某个策略的创建导致之前允许的连接被拒绝,
865
+ 底层网络插件的实现负责定义这个新策略是否会关闭现有的连接。
866
+ 建议不要以可能影响现有连接的方式修改策略、Pod 或名字空间。
867
+
845
868
# # {{% heading "whatsnext" %}}
846
869
847
870
<!--
0 commit comments