@@ -28,8 +28,8 @@ description: >-
28
28
<!--
29
29
If you want to control traffic flow at the IP address or port level for TCP, UDP, and SCTP protocols,
30
30
then you might consider using Kubernetes NetworkPolicies for particular applications in your cluster.
31
- NetworkPolicies are an application-centric construct which allow you to specify how a {{<
32
- glossary_tooltip text="pod" term_id="pod">}} is allowed to communicate with various network
31
+ NetworkPolicies are an application-centric construct which allow you to specify how a
32
+ {{< glossary_tooltip text="pod" term_id="pod">}} is allowed to communicate with various network
33
33
"entities" (we use the word "entity" here to avoid overloading the more common terms such as
34
34
"endpoints" and "services", which have specific Kubernetes connotations) over the network.
35
35
NetworkPolicies apply to a connection with a pod on one or both ends, and are not relevant to
@@ -45,11 +45,11 @@ NetworkPolicy 适用于一端或两端与 Pod 的连接,与其他连接无关
45
45
46
46
<!--
47
47
The entities that a Pod can communicate with are identified through a combination of the following
48
- 3 identifiers:
48
+ three identifiers:
49
49
50
50
1. Other pods that are allowed (exception: a pod cannot block access to itself)
51
- 2 . Namespaces that are allowed
52
- 3 . IP blocks (exception: traffic to and from the node where a Pod is running is always allowed,
51
+ 1 . Namespaces that are allowed
52
+ 1 . IP blocks (exception: traffic to and from the node where a Pod is running is always allowed,
53
53
regardless of the IP address of the Pod or the node)
54
54
-->
55
55
Pod 可以与之通信的实体是通过如下三个标识符的组合来辩识的:
@@ -60,11 +60,11 @@ Pod 可以与之通信的实体是通过如下三个标识符的组合来辩识
60
60
无论 Pod 或节点的 IP 地址)
61
61
62
62
<!--
63
- When defining a pod- or namespace- based NetworkPolicy, you use a
63
+ When defining a pod- or namespace-based NetworkPolicy, you use a
64
64
{{< glossary_tooltip text="selector" term_id="selector">}} to specify what traffic is allowed to
65
65
and from the Pod(s) that match the selector.
66
66
67
- Meanwhile, when IP based NetworkPolicies are created, we define policies based on IP blocks (CIDR ranges).
67
+ Meanwhile, when IP- based NetworkPolicies are created, we define policies based on IP blocks (CIDR ranges).
68
68
-->
69
69
在定义基于 Pod 或名字空间的 NetworkPolicy 时,
70
70
你会使用{{< glossary_tooltip text="选择算符" term_id="selector">}}来设定哪些流量可以进入或离开与该算符匹配的 Pod。
@@ -87,17 +87,17 @@ Creating a NetworkPolicy resource without a controller that implements it will h
87
87
创建一个 NetworkPolicy 资源对象而没有控制器来使它生效的话,是没有任何作用的。
88
88
89
89
<!--
90
- ## The Two Sorts of Pod Isolation
90
+ ## The two Sorts of Pod isolation
91
91
92
92
There are two sorts of isolation for a pod: isolation for egress, and isolation for ingress.
93
93
They concern what connections may be established. "Isolation" here is not absolute, rather it
94
94
means "some restrictions apply". The alternative, "non-isolated for $direction", means that no
95
- restrictions apply in the stated direction. The two sorts of isolation (or not) are declared
95
+ restrictions apply in the stated direction. The two sorts of isolation (or not) are declared
96
96
independently, and are both relevant for a connection from one pod to another.
97
97
-->
98
98
## Pod 隔离的两种类型 {#the-two-sorts-of-pod-isolation}
99
99
100
- Pod 有两种隔离: 出口的隔离和入口的隔离。它们涉及到可以建立哪些连接。
100
+ Pod 有两种隔离: 出口的隔离和入口的隔离。它们涉及到可以建立哪些连接。
101
101
这里的“隔离”不是绝对的,而是意味着“有一些限制”。
102
102
另外的,“非隔离方向”意味着在所述方向上没有限制。这两种隔离(或不隔离)是独立声明的,
103
103
并且都与从一个 Pod 到另一个 Pod 的连接有关。
@@ -112,7 +112,7 @@ allowed connections will also be implicitly allowed.
112
112
The effects of those `egress` lists combine additively.
113
113
-->
114
114
默认情况下,一个 Pod 的出口是非隔离的,即所有外向连接都是被允许的。如果有任何的 NetworkPolicy
115
- 选择该 Pod 并在其 ` policyTypes ` 中包含 “ Egress” ,则该 Pod 是出口隔离的,
115
+ 选择该 Pod 并在其 ` policyTypes ` 中包含 " Egress" ,则该 Pod 是出口隔离的,
116
116
我们称这样的策略适用于该 Pod 的出口。当一个 Pod 的出口被隔离时,
117
117
唯一允许的来自 Pod 的连接是适用于出口的 Pod 的某个 NetworkPolicy 的 ` egress ` 列表所允许的连接。
118
118
针对那些允许连接的应答流量也将被隐式允许。
@@ -176,7 +176,7 @@ solution supports network policy.
176
176
177
177
<!--
178
178
__Mandatory Fields__: As with all other Kubernetes config, a NetworkPolicy needs `apiVersion`,
179
- `kind`, and `metadata` fields. For general information about working with config files, see
179
+ `kind`, and `metadata` fields. For general information about working with config files, see
180
180
[Configure a Pod to Use a ConfigMap](/docs/tasks/configure-pod-container/configure-pod-configmap/),
181
181
and [Object Management](/docs/concepts/overview/working-with-objects/object-management).
182
182
@@ -192,7 +192,8 @@ which the policy applies. The example policy selects pods with the label "role=d
192
192
请参考[ 配置 Pod 以使用 ConfigMap] ( /zh-cn/docs/tasks/configure-pod-container/configure-pod-configmap/ )
193
193
和[ 对象管理] ( /zh-cn/docs/concepts/overview/working-with-objects/object-management ) 。
194
194
195
- ** spec** :NetworkPolicy [ 规约] ( https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status )
195
+ ** spec** :NetworkPolicy
196
+ [ 规约] ( https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status )
196
197
中包含了在一个名字空间中定义特定网络策略所需的所有信息。
197
198
198
199
** podSelector** :每个 NetworkPolicy 都包括一个 ` podSelector ` ,
@@ -257,13 +258,13 @@ walkthrough for further examples.
257
258
258
259
* ` default ` 名字空间下带有 ` role=frontend ` 标签的所有 Pod
259
260
* 带有 ` project=myproject ` 标签的所有名字空间中的 Pod
260
- * IP 地址范围为 172.17.0.0–172.17.0.255 和 172.17.2.0–172.17.255.255
261
- (即,除了 172.17.1.0/24 之外的所有 172.17.0.0/16)
261
+ * IP 地址范围为 ` 172.17.0.0–172.17.0.255 ` 和 ` 172.17.2.0–172.17.255.255 `
262
+ (即,除了 ` 172.17.1.0/24 ` 之外的所有 ` 172.17.0.0/16 ` )
262
263
263
264
3 . (Egress 规则)允许 ` default ` 名字空间中任何带有标签 ` role=db ` 的 Pod 到 CIDR
264
- 10.0.0.0/24 下 5978 TCP 端口的连接。
265
+ ` 10.0.0.0/24 ` 下 5978 TCP 端口的连接。
265
266
266
- 参阅 [ 声明网络策略] ( /zh-cn/docs/tasks/administer-cluster/declare-network-policy/ ) 演练了解更多示例 。
267
+ 有关更多示例,请参阅 [ 声明网络策略] ( /zh-cn/docs/tasks/administer-cluster/declare-network-policy/ ) 演练 。
267
268
268
269
<!--
269
270
## Behavior of `to` and `from` selectors
@@ -393,7 +394,7 @@ You can create a "default" ingress isolation policy for a namespace by creating
393
394
that selects all pods but does not allow any ingress traffic to those pods.
394
395
-->
395
396
你可以通过创建选择所有 Pod 但不允许任何进入这些 Pod 的入站流量的 NetworkPolicy
396
- 来为名字空间创建 “ default” 隔离策略。
397
+ 来为名字空间创建 " default" 隔离策略。
397
398
398
399
{{< code_sample file="service/networking/network-policy-default-deny-ingress.yaml" >}}
399
400
@@ -419,7 +420,7 @@ that explicitly allows that.
419
420
420
421
<!--
421
422
With this policy in place, no additional policy or policies can cause any incoming connection to
422
- those pods to be denied. This policy has no effect on isolation for egress from any pod.
423
+ those pods to be denied. This policy has no effect on isolation for egress from any pod.
423
424
-->
424
425
有了这个策略,任何额外的策略都不会导致到这些 Pod 的任何入站连接被拒绝。
425
426
此策略对任何 Pod 的出口隔离没有影响。
@@ -433,7 +434,7 @@ that selects all pods but does not allow any egress traffic from those pods.
433
434
### 默认拒绝所有出站流量 {#default-deny-all-egress-traffic}
434
435
435
436
你可以通过创建选择所有容器但不允许来自这些容器的任何出站流量的 NetworkPolicy
436
- 来为名字空间创建 “ default” 隔离策略。
437
+ 来为名字空间创建 " default" 隔离策略。
437
438
438
439
{{< code_sample file="service/networking/network-policy-default-deny-egress.yaml" >}}
439
440
@@ -460,7 +461,7 @@ explicitly allows all outgoing connections from pods in that namespace.
460
461
461
462
<!--
462
463
With this policy in place, no additional policy or policies can cause any outgoing connection from
463
- those pods to be denied. This policy has no effect on isolation for ingress to any pod.
464
+ those pods to be denied. This policy has no effect on isolation for ingress to any pod.
464
465
-->
465
466
有了这个策略,任何额外的策略都不会导致来自这些 Pod 的任何出站连接被拒绝。
466
467
此策略对进入任何 Pod 的隔离没有影响。
@@ -473,7 +474,7 @@ creating the following NetworkPolicy in that namespace.
473
474
-->
474
475
### 默认拒绝所有入站和所有出站流量 {#default-deny-all-ingress-and-all-egress-traffic}
475
476
476
- 你可以为名字空间创建 “ default” 策略,以通过在该名字空间中创建以下 NetworkPolicy
477
+ 你可以为名字空间创建 " default" 策略,以通过在该名字空间中创建以下 NetworkPolicy
477
478
来阻止所有入站和出站流量。
478
479
479
480
{{< code_sample file="service/networking/network-policy-default-deny-all.yaml" >}}
@@ -487,8 +488,8 @@ ingress or egress traffic.
487
488
<!--
488
489
## Network traffic filtering
489
490
490
- NetworkPolicy is defined for [layer 4](https://en.wikipedia.org/wiki/OSI_model#Layer_4:_Transport_layer)
491
- connections (TCP, UDP, and optionally SCTP). For all the other protocols, the behaviour may vary
491
+ NetworkPolicy is defined for [layer 4](https://en.wikipedia.org/wiki/OSI_model#Layer_4:_Transport_layer)
492
+ connections (TCP, UDP, and optionally SCTP). For all the other protocols, the behaviour may vary
492
493
across network plugins.
493
494
-->
494
495
## 网络流量过滤 {#network-traffic-filtering}
@@ -508,7 +509,7 @@ protocol NetworkPolicies.
508
509
When a `deny all` network policy is defined, it is only guaranteed to deny TCP, UDP and SCTP
509
510
connections. For other protocols, such as ARP or ICMP, the behaviour is undefined.
510
511
The same applies to allow rules: when a specific pod is allowed as ingress source or egress destination,
511
- it is undefined what happens with (for example) ICMP packets. Protocols such as ICMP may be allowed by some
512
+ it is undefined what happens with (for example) ICMP packets. Protocols such as ICMP may be allowed by some
512
513
network plugins and denied by others.
513
514
-->
514
515
当 ` deny all ` 网络策略被定义时,此策略只能保证拒绝 TCP、UDP 和 SCTP 连接。
@@ -536,8 +537,8 @@ This is achievable with the usage of the `endPort` field, as the following examp
536
537
{{< code_sample file="service/networking/networkpolicy-multiport-egress.yaml" >}}
537
538
538
539
<!--
539
- The above rule allows any Pod with label `role=db` on the namespace `default` to communicate
540
- with any IP within the range `10.0.0.0/24` over TCP, provided that the target
540
+ The above rule allows any Pod with label `role=db` on the namespace `default` to communicate
541
+ with any IP within the range `10.0.0.0/24` over TCP, provided that the target
541
542
port is between the range 32000 and 32768.
542
543
-->
543
544
上面的规则允许名字空间 ` default ` 中所有带有标签 ` role=db ` 的 Pod 使用 TCP 协议与
@@ -560,7 +561,7 @@ The following restrictions apply when using this field:
560
561
<!--
561
562
Your cluster must be using a {{< glossary_tooltip text="CNI" term_id="cni" >}} plugin that
562
563
supports the `endPort` field in NetworkPolicy specifications.
563
- If your [network plugin](/docs/concepts/extend-kubernetes/compute-storage-net/network-plugins/)
564
+ If your [network plugin](/docs/concepts/extend-kubernetes/compute-storage-net/network-plugins/)
564
565
does not support the `endPort` field and you specify a NetworkPolicy with that,
565
566
the policy will be applied only for the single `port` field.
566
567
-->
@@ -658,7 +659,7 @@ NetworkPolicy.
658
659
When a new NetworkPolicy object is created, it may take some time for a network plugin
659
660
to handle the new object. If a pod that is affected by a NetworkPolicy
660
661
is created before the network plugin has completed NetworkPolicy handling,
661
- that pod may be started unprotected, and isolation rules will be applied when
662
+ that pod may be started unprotected, and isolation rules will be applied when
662
663
the NetworkPolicy handling is completed.
663
664
-->
664
665
当新的 NetworkPolicy 对象被创建时,网络插件可能需要一些时间来处理这个新对象。
@@ -669,11 +670,11 @@ the NetworkPolicy handling is completed.
669
670
Once the NetworkPolicy is handled by a network plugin,
670
671
671
672
1. All newly created pods affected by a given NetworkPolicy will be isolated before
672
- they are started.
673
- Implementations of NetworkPolicy must ensure that filtering is effective throughout
674
- the Pod lifecycle, even from the very first instant that any container in that Pod is started.
675
- Because they are applied at Pod level, NetworkPolicies apply equally to init containers,
676
- sidecar containers, and regular containers.
673
+ they are started.
674
+ Implementations of NetworkPolicy must ensure that filtering is effective throughout
675
+ the Pod lifecycle, even from the very first instant that any container in that Pod is started.
676
+ Because they are applied at Pod level, NetworkPolicies apply equally to init containers,
677
+ sidecar containers, and regular containers.
677
678
-->
678
679
一旦 NetworkPolicy 被网络插件处理,
679
680
@@ -684,8 +685,8 @@ sidecar containers, and regular containers.
684
685
685
686
<!--
686
687
2. Allow rules will be applied eventually after the isolation rules (or may be applied at the same time).
687
- In the worst case, a newly created pod may have no network connectivity at all when it is first started, if
688
- isolation rules were already applied, but no allow rules were applied yet.
688
+ In the worst case, a newly created pod may have no network connectivity at all when it is first started, if
689
+ isolation rules were already applied, but no allow rules were applied yet.
689
690
690
691
Every created NetworkPolicy will be handled by a network plugin eventually, but there is no
691
692
way to tell from the Kubernetes API when exactly that happens.
@@ -694,11 +695,12 @@ way to tell from the Kubernetes API when exactly that happens.
694
695
在最糟的情况下,如果隔离规则已被应用,但 allow 规则尚未被应用,
695
696
那么新建的 Pod 在初始启动时可能根本没有网络连接。
696
697
697
- 用户所创建的每个 NetworkPolicy 最终都会被网络插件处理,但无法使用 Kubernetes API 来获知确切的处理时间。
698
+ 用户所创建的每个 NetworkPolicy 最终都会被网络插件处理,但无法使用 Kubernetes API
699
+ 来获知确切的处理时间。
698
700
699
701
<!--
700
702
Therefore, pods must be resilient against being started up with different network
701
- connectivity than expected. If you need to make sure the pod can reach certain destinations
703
+ connectivity than expected. If you need to make sure the pod can reach certain destinations
702
704
before being started, you can use an [init container](/docs/concepts/workloads/pods/init-containers/)
703
705
to wait for those destinations to be reachable before kubelet starts the app containers.
704
706
-->
@@ -709,7 +711,7 @@ kubelet 启动应用容器之前等待这些目的地变得可达。
709
711
710
712
<!--
711
713
Every NetworkPolicy will be applied to all selected pods eventually.
712
- Because the network plugin may implement NetworkPolicy in a distributed manner,
714
+ Because the network plugin may implement NetworkPolicy in a distributed manner,
713
715
it is possible that pods may see a slightly inconsistent view of network policies
714
716
when the pod is first created, or when pods or policies change.
715
717
For example, a newly-created pod that is supposed to be able to reach both Pod A
@@ -742,9 +744,9 @@ NetworkPolicy behaviour for `hostNetwork` pods is undefined, but it should be li
742
744
网络插件还可以像处理 Pod 网络流量一样,对 `hostNetwork` Pod 应用 NetworkPolicy。
743
745
744
746
<!--
745
- - The network plugin cannot properly distinguish `hostNetwork` pod traffic,
746
- and so it ignores `hostNetwork` pods when matching `podSelector` and `namespaceSelector`.
747
- Traffic to/from `hostNetwork` pods is treated the same as all other traffic to/from the node IP.
747
+ - The network plugin cannot properly distinguish `hostNetwork` pod traffic,
748
+ and so it ignores `hostNetwork` pods when matching `podSelector` and `namespaceSelector`.
749
+ Traffic to/from `hostNetwork` pods is treated the same as all other traffic to/from the node IP.
748
750
(This is the most common implementation.)
749
751
-->
750
752
- 网络插件无法正确辨别 `hostNetwork` Pod 流量,因此在匹配 `podSelector` 和 `namespaceSelector`
@@ -771,9 +773,10 @@ This applies when
771
773
` ` `
772
774
773
775
<!--
774
- 2 . a `hostNetwork` pod is selected by a `podSelector` or `namespaceSelector` in an `ingress` or `egress` rule.
776
+ 1 . a `hostNetwork` pod is selected by a `podSelector` or `namespaceSelector` in an `ingress` or `egress` rule.
775
777
-->
776
- 2. `hostNetwork` Pod 在 `ingress` 或 `egress` 规则中被 `podSelector` 或 `namespaceSelector` 选中。
778
+ 2. `hostNetwork` Pod 在 `ingress` 或 `egress` 规则中被 `podSelector` 或
779
+ ` namespaceSelector` 选中。
777
780
778
781
` ` ` yaml
779
782
...
@@ -799,7 +802,7 @@ from a `hostNetwork` Pod using an `ipBlock` rule.
799
802
As of Kubernetes {{< skew currentVersion >}}, the following functionality does not exist in the
800
803
NetworkPolicy API, but you might be able to implement workarounds using Operating System
801
804
components (such as SELinux, OpenVSwitch, IPTables, and so on) or Layer 7 technologies (Ingress
802
- controllers, Service Mesh implementations) or admission controllers. In case you are new to
805
+ controllers, Service Mesh implementations) or admission controllers. In case you are new to
803
806
network security in Kubernetes, its worth noting that the following User Stories cannot (yet) be
804
807
implemented using the NetworkPolicy API.
805
808
-->
@@ -873,6 +876,6 @@ It is recommended not to modify policies/pods/namespaces in ways that might affe
873
876
- See more [recipes](https://github.com/ahmetb/kubernetes-network-policy-recipes) for common
874
877
scenarios enabled by the NetworkPolicy resource.
875
878
-->
876
- - 参阅 [声明网络策略](/zh-cn/docs/tasks/administer-cluster/declare-network-policy/)演练了解更多示例;
879
+ - 有关更多示例,请参阅 [声明网络策略](/zh-cn/docs/tasks/administer-cluster/declare-network-policy/)演练。
877
880
- 有关 NetworkPolicy 资源所支持的常见场景的更多信息,
878
881
请参见[此指南](https://github.com/ahmetb/kubernetes-network-policy-recipes)。
0 commit comments