tencent cloud

Tencent Kubernetes Engine

eNP (ebpf Network Policies) Usage Instructions

Unduh
Mode fokus
Ukuran font
Terakhir diperbarui: 2026-10-23 16:19:16
Diterjemahkan oleh AI

Introduction

Network Policies

If you want to control network traffic for protocols such as TCP, UDP, and SCTP at the IP address or port level, you can use Kubernetes NetworkPolicy for specific applications in a cluster. NetworkPolicy is an application-centric policy mechanism that precisely defines how Pods communicate with other entities in the network, and it is especially suitable for network connection scenarios involving Pods.
You can use the following three identifiers to specify the entities that are allowed to communicate with a Pod:
1. Other Pods that are already allowed (Note: A Pod cannot block access to itself).
2. An allowed namespace.
3. IP address blocks (Note: Communication between a Pod and its node is always allowed, regardless of the IP addresses of the Pod or the node).
When defining a NetworkPolicy based on Pods or namespaces, you can use a Label selector to determine which traffic can enter or leave Pods that match the selector. For a NetworkPolicy based on IP addresses, you can control traffic by specifying IP address blocks (CIDR ranges).

eNP

The eNP (eBPF Network Policies) component is a NetworkPolicy implementation based on eBPF technology. It attaches eBPF programs to the tc of the veth on the host where the Pod resides. When the NIC processes packets, it matches NetworkPolicy rules based on the five-tuple (source address, source port, destination address, destination port, and transport protocol) to determine whether to allow or drop each packet.

Architecture

Limit

1. Supported OS versions are TencentOS Server 3.1 and TencentOS Server 3.2.
2. TKE 1.22 or later.
3. The network plugin is the shared ENI VPC-CNI.
4. Only IPv4 clusters are supported. IPv4/IPv6 dual-stack clusters are not supported yet.

Component Architecture

The following figure shows the architecture of the eNP component.

1. The eNP component introduces a CRD (Custom Resource Definition) to store entities associated with NetworkPolicy.
2. The tke-network-policy-controller is deployed as a deployment on the control plane. It lists and watches NetworkPolicy resources and calculates and generates Policy-CRDs for each Pod.
3. The tke-network-policy-agent attaches filter eBPF programs to the default NIC (eth0) in the network namespace of each business Pod through DaemonSet injection.
4. The agent maintains allow rules in eBPF maps based on Policy-CRDs. The attached eBPF programs allow or drop packets based on the rules in the allow eBPF maps.

e2e Test Status of eNP Components

Run the Kubernetes community e2e tests for NetworkPolicy (release-1.26). The test cases in this version come from two test suites with different network models, but the test cases between the two suites overlap. Here, the test cases in network_policy.go are marked as network_policy, and the test cases in network_legacy.go are marked as network_legacy. The passed cases are as follows:
No.
Feature
Source
1
should support a 'default-deny-ingress' policy [Feature:NetworkPolicy]
network_legacy
2
should support a 'default-deny-all' policy [Feature:NetworkPolicy]
network_legacy
3
should enforce policy to allow traffic from pods within server namespace based on PodSelector [Feature:NetworkPolicy]
network_legacy
4
should enforce policy to allow traffic only from a different namespace, based on NamespaceSelector [Feature:NetworkPolicy]
network_legacy
5
should enforce policy based on PodSelector with MatchExpressions[Feature:NetworkPolicy]
network_legacy
6
should enforce policy based on NamespaceSelector with MatchExpressions[Feature:NetworkPolicy]
network_legacy
7
should enforce policy based on PodSelector or NamespaceSelector [Feature:NetworkPolicy]
network_legacy
8
should enforce policy based on PodSelector and NamespaceSelector [Feature:NetworkPolicy]
network_legacy
9
should enforce policy to allow traffic only from a pod in a different namespace based on PodSelector and NamespaceSelector [Feature:NetworkPolicy]
network_legacy
10
should enforce policy based on Ports [Feature:NetworkPolicy]
network_legacy
11
should enforce multiple, stacked policies with overlapping podSelectors [Feature:NetworkPolicy]
network_legacy
12
should support allow-all policy [Feature:NetworkPolicy]
network_legacy
13
should allow ingress access on one named port [Feature:NetworkPolicy]
network_legacy
14
should allow ingress access from namespace on one named port [Feature:NetworkPolicy]
network_legacy
15
should allow egress access on one named port [Feature:NetworkPolicy]
network_legacy
16
should enforce updated policy [Feature:NetworkPolicy]
network_legacy
17
should allow ingress access from updated namespace [Feature:NetworkPolicy]
network_legacy
18
should allow ingress access from updated pod [Feature:NetworkPolicy]
network_legacy
19
should deny ingress access to updated pod [Feature:NetworkPolicy]
network_legacy
20
should work with Ingress,Egress specified together [Feature:NetworkPolicy]
network_legacy
21
should enforce egress policy allowing traffic to a server in a different namespace based on PodSelector and NamespaceSelector [Feature:NetworkPolicy]
network_legacy
22
should enforce multiple ingress policies with ingress allow-all policy taking precedence [Feature:NetworkPolicy]
network_legacy
23
should enforce multiple egress policies with egress allow-all policy taking precedence [Feature:NetworkPolicy]
network_legacy
24
should stop enforcing policies after they are deleted [Feature:NetworkPolicy]
network_legacy
25
should enforce policies to check ingress and egress policies can be controlled independently based on PodSelector [Feature:NetworkPolicy]
network_legacy
26
should not allow access by TCP when a policy specifies only SCTP [Feature:NetworkPolicy]
network_legacy
27
should support a 'default-deny' policy [Feature:NetworkPolicy]
network_legacy
28
should enforce policy based on Ports [Feature:NetworkPolicy]
network_legacy
29
should enforce policy to allow traffic only from a pod in a different namespace based on PodSelector and NamespaceSelector [Feature:NetworkPolicy]
network_legacy
30
should support a 'default-deny-ingress' policy [Feature:NetworkPolicy]
network_policy
31
should support a 'default-deny-all' policy [Feature:NetworkPolicy]
network_policy
32
should enforce policy to allow traffic from pods within server namespace based on PodSelector [Feature:NetworkPolicy]
network_policy
33
should enforce policy to allow ingress traffic for a target [Feature:NetworkPolicy]
network_policy
34
should enforce policy to allow ingress traffic from pods in all namespaces [Feature:NetworkPolicy]
network_policy
35
should enforce policy to allow traffic only from a different namespace, based on NamespaceSelector [Feature:NetworkPolicy]
network_policy
36
should enforce policy based on PodSelector with MatchExpressions[Feature:NetworkPolicy]
network_policy
37
should enforce policy based on NamespaceSelector with MatchExpressions[Feature:NetworkPolicy]
network_policy
38
should enforce policy based on PodSelector or NamespaceSelector [Feature:NetworkPolicy]
network_policy
39
should enforce policy based on PodSelector and NamespaceSelector [Feature:NetworkPolicy]
network_policy
40
should enforce policy based on Multiple PodSelectors and NamespaceSelectors [Feature:NetworkPolicy]
network_policy
41
should enforce policy based on any PodSelectors [Feature:NetworkPolicy]
network_policy
42
should enforce policy to allow traffic only from a pod in a different namespace based on PodSelector and NamespaceSelector [Feature:NetworkPolicy]
network_policy
43
should enforce policy based on Ports [Feature:NetworkPolicy]
network_policy
44
should enforce multiple, stacked policies with overlapping podSelectors [Feature:NetworkPolicy]
network_policy
45
should support allow-all policy [Feature:NetworkPolicy]
network_policy
46
should allow ingress access on one named port [Feature:NetworkPolicy]
network_policy
47
should allow ingress access from namespace on one named port [Feature:NetworkPolicy]
network_policy
48
should enforce updated policy [Feature:NetworkPolicy]
network_policy
49
should allow ingress access from updated namespace [Feature:NetworkPolicy]
network_policy
50
should allow ingress access from updated pod [Feature:NetworkPolicy]
network_policy
51
should deny ingress from pods on other namespaces [Feature:NetworkPolicy]
network_policy
52
should deny ingress access to updated pod [Feature:NetworkPolicy]
network_policy
53
should deny egress from pods based on PodSelector [Feature:NetworkPolicy]
network_policy
54
should deny egress from all pods in a namespace [Feature:NetworkPolicy]
network_policy
55
should work with Ingress, Egress specified together [Feature:NetworkPolicy]
network_policy
56
should support denying of egress traffic on the client side (even if the server explicitly allows this traffic) [Feature:NetworkPolicy]
network_policy
57
should enforce egress policy allowing traffic to a server in a different namespace based on PodSelector and NamespaceSelector [Feature:NetworkPolicy]
network_policy
58
should enforce ingress policy allowing any port traffic to a server on a specific protocol [Feature:NetworkPolicy] [Feature:UDP]
network_policy
59
should enforce multiple ingress policies with ingress allow-all policy taking precedence [Feature:NetworkPolicy]
network_policy
60
should enforce multiple egress policies with egress allow-all policy taking precedence [Feature:NetworkPolicy]
network_policy
61
should stop enforcing policies after they are deleted [Feature:NetworkPolicy]
network_policy
62
should enforce policies to check ingress and egress policies can be controlled independently based on PodSelector [Feature:NetworkPolicy]
network_policy
63
should not mistakenly treat 'protocol: SCTP' as 'protocol: TCP', even if the plugin doesn't support SCTP [Feature:NetworkPolicy]
network_policy
64
should properly isolate pods that are selected by a policy allowing SCTP, even if the plugin doesn't support SCTP [Feature:NetworkPolicy]
network_policy
65
should not allow access by TCP when a policy specifies only UDP [Feature:NetworkPolicy]
network_policy
66
should enforce policy to allow traffic based on NamespaceSelector with MatchLabels using default ns label [Feature:NetworkPolicy]
network_policy
67
should enforce policy based on NamespaceSelector with MatchExpressions using default ns label [Feature:NetworkPolicy]
network_policy
68
should support a 'default-deny-ingress' policy [Feature:NetworkPolicy]
network_policy
69
should enforce policy based on Ports [Feature:NetworkPolicy]
network_policy
70
should enforce policy to allow traffic only from a pod in a different namespace based on PodSelector and NamespaceSelector [Feature:NetworkPolicy]
network_policy
71
should support a 'default-deny-ingress' policy [Feature:NetworkPolicy]
network_policy
72
should enforce policy based on Ports [Feature:NetworkPolicy]
network_policy
73
should enforce policy to allow traffic only from a pod in a different namespace based on PodSelector and NamespaceSelector [Feature:NetworkPolicy]
network_policy
The following scenarios are not supported:
1. When a Pod serves as the backend of a Service, access to the Pod is allowed through egress. However, access to the Pod through the Service IP address is denied. This differs from the original Network Policy component, where the Pod can be accessed through the Service IP address.
2. Rules of the named port type are not supported.
The specific e2e test cases are as follows:
case
Symptom
Reason
should enforce except clause while egress access to server in CIDR block
When an IP address CIDR of a Pod is allowed in a NetworkPolicy, the Service IP address associated with the Pod cannot be allowed.
Because the underlying ebpf is implemented at the Pod NIC egress, the Service IP address of the packet has not been DNATed to the Pod IP address by iptables/ipvs yet, so the packet is dropped by the attached ebpf program.
should allow egress access to server in CIDR block
should ensure an IP overlapping both IPBlock.CIDR and IPBlock.Except is allowed
should allow egress access on one named port
The named port for egress does not take effect.
(Not supported yet)
If the egress peer is a public IP address, the named port has no source to obtain, so it is not supported yet.


Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan