Use Terway Trunk ENI to assign per-pod static IPs, vSwitches, or security groups for network isolation.
Background
ACK provides an ENI-based solution for per-pod network configuration. Two ENI modes are available:
-
Exclusive ENI mode: Each pod binds to an exclusive ENI with dedicated network resources. Provides strong isolation but consumes more ENI quotas. Suitable for high-performance, isolation-sensitive applications.
To use this mode, configure Exclusive ENI network mode when creating a node pool.
-
Trunk ENI mode: A Trunk ENI on a node dynamically provides auxiliary ENIs for multiple pods. Increases per-node pod density and suits large-scale custom network configurations.
Enable the Trunk ENI feature in your cluster first. The terway-controlplane component is then auto-deployed to manage custom network configuration lifecycle and policy delivery. Architecture:
Trunk ENI mode also supports custom network configurations, assigning dedicated vSwitches, security groups, and static IPs to critical pods on demand while other pods use the default shared configuration.
Limitations
-
If you use an ACK dedicated cluster, go to the Quota Center to apply for the quota named
Container network supports Terway ENI Trunking mode. -
Each node has a pod hosting limit. See Use the Terway network plugin.
-
Security group rules do not apply to intra-node pod traffic or pod-to-host traffic. Use a NetworkPolicy for these scenarios.
-
Terway version requirements:
To upgrade Terway, see Add-ons.
-
Trunk ENI mode: Terway v1.3.0 or later
-
Exclusive ENI mode: Terway v1.11.0 or later
-
-
This feature supports only ECS instances.
Data path
The following diagram shows the data path difference between Trunk ENI and exclusive ENI modes.
Scope of dedicated pod configurations
With a dedicated pod configuration, each pod gets an exclusive ENI with its own vSwitch and security group.
Two node configuration modes support dedicated pod configurations:
|
Nodes that support Trunk ENIs |
Nodes that support elastic network interfaces (See Configure exclusive ENI network mode for a node pool) |
|
|
Supported cluster types |
ACK managed cluster |
ACK managed cluster, ACK dedicated cluster |
|
Deployment density |
Regular pods share an ENI; specified pods use exclusive ENIs. High overall density. |
All pods use exclusive ENIs. Low density. |
|
Supported node types |
ECS nodes |
ECS nodes |
|
Instance type |
Select an instance type that supports Trunk ENI and returns |
Instance types that support ENIs. |
|
Use cases |
Cost-sensitive and low-concurrency services. |
High-performance, low-latency, and high-concurrency services. |
|
Kubernetes resource limits |
|
|
Step 1: Enable the Trunk ENI feature for a cluster
New cluster
When creating an ACK cluster, set Network Plug-in to Terway and select Support for ENI Trunking in the Terway Mode section (network plugin type: terway-eniip). See Create an ACK dedicated cluster (discontinued) and Create an ACK managed cluster.
From Kubernetes 1.31, Trunk ENI is enabled by default for new ACK managed clusters.
Once enabled, Trunk ENI cannot be disabled.
Existing cluster
Prerequisites
Your existing cluster must use the terway-eniip network plugin. See Use the Terway network plugin.
Check your network plugin on the cluster's Add-ons page.
Limitations
-
ACK managed clusters created before June 2020 may not support this feature. Follow Step 1 to check for compatibility.
-
Once enabled, the static IP, dedicated vSwitch, and security group features cannot be disabled.
Step 1: Check for Trunk ENI support
-
For an ACK dedicated cluster, you must apply for permissions to use ECS instances that support Trunk ENIs. To apply, submit a ticket.
-
For an existing ACK managed cluster or an ACK managed cluster migrated from an ACK dedicated cluster, check Trunk ENI support and modify the configuration. No ECS instance permissions required.
Check the token configuration:
kubectl get secret -nkube-system addon.network.token
Expected output if the configuration exists:
NAME TYPE DATA AGE
addon.network.token Opaque 1 69m
If the token configuration exists, proceed to the next step. If not, create a new cluster with Trunk ENI support.
Step 2: Enable terway-eniip and Trunk ENI
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of your cluster. In the left navigation pane, click Components and Add-ons.
-
On the Add-ons page, click the Network tab and find the terway-eniip component.
-
On the terway-eniip card, click Upgrade to update the terway-eniip component to the latest version.
If no Upgrade button appears, the component is already up to date. Skip this step.
-
Enable terway-eniip.
-
Edit the eni-config ConfigMap:
kubectl edit cm -nkube-system eni-config -
Edit the eni-config parameters in the YAML file:
Parameter
Value
Description
enable_eni_trunking
true
Enables Trunk ENI. Cannot be disabled once enabled.
credential_path
/var/addon/token-config
For an ACK managed cluster, add this parameter if not already present.
Important-
Do not modify other parameters.
-
The content of the eni-config ConfigMap must be valid JSON.
Sample configuration:
apiVersion: v1 data: eni_conf: | { "min_pool_size": 0, "enable_eni_trunking": true, "credential_path": "/var/addon/token-config", ... } kind: ConfigMap -
-
Restart the Terway pods to apply the configuration:
kubectl delete pod -n kube-system -l app=terway-eniip
-
-
After you configure the terway-eniip parameters, go to the Network tab on the Add-ons page and install the terway-controlplane component.
After installation, the terway-controlplane card shows Installed.
Step 2: Create a PodNetworking custom resource
Terway uses a PodNetworking custom resource (CR) to describe network configurations. Create multiple PodNetworking objects to define different network planes.
Log on to the ACK console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of your cluster, and then choose in the left-side navigation pane.
-
On the Custom Resources page, click the CRDs tab, and then click Create from YAML.
Sample PodNetworking YAML:
apiVersion: network.alibabacloud.com/v1beta1 kind: PodNetworking metadata: name: example spec: allocationType: type: Fixed # The pod IP address allocation policy. Valid values: Elastic and Fixed. releaseStrategy: TTL # This parameter is valid only when type is set to Fixed. If type is set to Elastic, you do not need to configure releaseStrategy and releaseAfter. releaseAfter: "1h" # This parameter is valid only when releaseStrategy is set to TTL. selector: podSelector: matchLabels: foo: bar namespaceSelector: matchLabels: foo: bar securityGroupIDs: - sg-bpxxxx vSwitchOptions: - vsw-bpxxxx eniOptions: eniType: DefaultParameter descriptions:
Parameter
Description
allocationType
(The pod IP address allocation policy)
type
Valid values:
-
Elastic: IP resources are released after the pod is deleted.
-
Fixed: The static IP address policy.
When
typeisFixed, this applies to pods with fixed names (StatefulSets and pods without ownerReferences by default). For custom workloads, configure terway-controlplane on the Add-ons page.NoteWith the static IP policy, recreated pods are constrained to the same zone as the original.
releaseStrategy
Valid only when
typeisFixed. Valid values:-
TTL: Delayed release. IP released after a specified time post-pod-deletion. Minimum: 5 minutes. -
Never: IP never released. Manually delete the PodENI resource when no longer needed.
releaseAfter
The delayed release time. Valid only when
releaseStrategyisTTL. Uses Go time type format withhandmunits, such as2h45mor5m0s.selector
(Label selector. Matched pods use this network configuration.)
podSelector
-
Matches pod labels. Matched pods use this network configuration.
-
If both
podSelectorandnamespaceSelectorare configured, pods matching all rules use this configuration. -
Ensure a unique match. If a pod matches multiple PodNetworking configurations, the system arbitrarily applies one.
namespaceSelector
-
Labels to match a Namespace. Pods in matched Namespaces use this configuration.
-
If both
podSelectorandnamespaceSelectorare configured, pods matching all rules use this configuration. -
Ensure a unique match. Multiple matches result in arbitrary selection.
vSwitchOptions
-
-
The vSwitches for pods. If multiple IDs are provided, Terway selects one that meets conditions.
-
Pods are constrained to the same zones as the specified vSwitches.
-
The vSwitch zones must match the zones of the target nodes, and sufficient IP addresses must be available. Otherwise, pod creation fails.
NoteWith auto scaling enabled, vSwitchOptions zone constraints may prevent node pool scale-out. See Auto scaling FAQ.
vSwitchSelectOptions
(Configures the vSwitch selection policy)
vSwitchSelectionPolicy
Valid values:
-
ordered(default): Selects in the order entered. -
most: Prioritizes the vSwitch with the most available IPs. -
random: Randomly selects a vSwitch.
NoteSupported in Terway v1.11.0 and later.
securityGroupIDs
-
Supports multiple security group IDs (all take effect). Maximum: 10.
NoteTerway v1.13.6 and later supports up to 10 security groups.
eniOptions
(Configures the ENI type used by the pod)
eniType
Valid values:
-
Default: Trunk ENI for shared-ENI clusters, exclusive ENI for exclusive-ENI clusters. -
ENI: Uses an exclusive ENI. -
Trunk: Uses a Trunk ENI.
NoteSupported in Terway v1.11.0 and later.
-
-
Click Create.
The PodNetworking takes effect only after its
statusbecomesReady.Check whether the resource status is
ready:kubectl describe PodNetworking example # Replace example with the name of your custom resource.
(Optional) Step 3: Add matching labels to a namespace
To apply PodNetworking rules via label matching, add the corresponding labels to the target namespace.
-
Create a test namespace named example:
kubectl create ns example -
Add the
foo=barlabel to the namespace:kubectl label namespaces example foo=bar # Replace example with your target namespace name. -
View the labels of the namespace:
kubectl get namespace example --show-labels # Replace example with your target namespace name.Expected output:
NAME STATUS AGE LABELS example Active 24s foo=bar,kubernetes.io/metadata.name=example
(Optional) Step 4: Create an application pod
When a pod is created, the system matches its labels against PodNetworking resources. Matched pods receive an ENI per the matched configuration; unmatched pods use the default ENI.
Terway creates a PodENI custom resource to track each matched pod's network resources. See Labels and Selectors.
-
Create a file named my-nginx.yaml with the following YAML content:
apiVersion: apps/v1 kind: StatefulSet metadata: name: my-nginx # The name of the sample application. namespace: example # Specify the namespace as example. labels: app: nginx spec: serviceName: "nginx-service" replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx foo: bar # Add the foo:bar label to the pod. spec: containers: - name: nginx image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6 ports: - containerPort: 80 # If the StatefulSet requires persistent storage, you must define volumeClaimTemplates. # Example: # volumeClaimTemplates: # - metadata: # name: nginx-storage # spec: # accessModes: ["ReadWriteOnce"] # storageClassName: "my-storage-class" # resources: # requests: # storage: 1Gi -
Deploy the my-nginx sample application. After deployment, see Verify PodNetworking usage to verify the network configuration.
kubectl apply -f my-nginx.yaml
Stop terway-controlplane for migration
An ACK dedicated cluster with custom pod configurations cannot directly migrate to an ACK managed Pro cluster. Stop terway-controlplane before migration and re-enable it afterward.
-
Prepare for migration.
-
Stop terway-controlplane:
kubectl scale deploy -nkube-system terway-controlplane --replicas 0 -
Configure the webhook:
# Back up the webhook configuration. kubectl get mutatingwebhookconfigurations.admissionregistration.k8s.io terway-controlplane -oyaml > terway-controlplane.mutatingwebhookconfigurations.yaml kubectl get validatingwebhookconfigurations.admissionregistration.k8s.io terway-controlplane -oyaml > terway-controlplane.validatingwebhookconfigurations.yaml # Clean up the webhook configuration. kubectl delete -f terway-controlplane.mutatingwebhookconfigurations.yaml kubectl delete -f terway-controlplane.validatingwebhookconfigurations.yaml -
Configure the service:
# Back up the original service configuration. kubectl get service -nkube-system terway-controlplane -oyaml > terway-controlplane.service.yaml # Clean up the original service configuration. kubectl delete -f terway-controlplane.service.yaml
-
-
After migration, check the result.
-
If migration fails, restore the webhook and terway-controlplane:
# Restore the service configuration. kubectl apply -f terway-controlplane.service.yaml # Restore the webhook configuration. kubectl apply -f terway-controlplane.mutatingwebhookconfigurations.yaml kubectl apply -f terway-controlplane.validatingwebhookconfigurations.yaml # Restore terway-controlplane. kubectl scale deploy -nkube-system terway-controlplane --replicas 1 -
If migration succeeds, clean up resources:
kubectl delete deploy -nkube-system terway-controlplane
-
-
Install terway-controlplane from the Add-ons page. See Manage add-ons.
FAQ
Verify PodNetworking usage
-
After creation, the pod's
annotationsincludek8s.aliyun.com/pod-networkingto indicate PodNetworking usage.apiVersion: v1 kind: Pod metadata: annotations: k8s.aliyun.com/pod-eni: "true" k8s.aliyun.com/pod-networking: podnetworking labels: app: example pod-ip: elastic -
Terway creates a PodENI resource (same name/namespace as the pod) to record its network configuration.
kubectl get podenis.network.alibabacloud.com <my-nginx-0> -n <example> -o yaml # Replace <my-nginx-0> with the pod name and <example> with the pod's namespace.Expected output showing PodNetworking in use:
apiVersion: network.alibabacloud.com/v1beta1 kind: PodENI metadata: finalizers: - pod-eni generation: 1 name: <my-nginx-0> namespace: default spec: allocations: - allocationType: type: Elastic eni: id: eni-bp1xxxx mac: 00:16:xx:xx:xx:xx securityGroupIDs: - sg-bp1xxxx vSwitchID: vsw-bp1xxxx zone: cn-hangzhou-h ipv4: 192.168.x.x ipv4CIDR: 192.168.x.x/19 ipv6: 2408:x:x:x:x:x:x:x ipv6CIDR: 2408:x:x:x::/64 zone: cn-hangzhou-h status: eniInfos: eni-bp1xxxx: id: eni-bp1xxxx status: Bind vid: 1001 instanceID: i-bp1xxxx phase: Bind podLastSeen: "2021-xx-xxT00:00:00Z" trunkENIID: eni-bp1xxxx
Pod does not use the PodNetworking configuration
-
Verify the PodNetworking status is
Ready. -
Verify the pod's labels uniquely match the PodNetworking selector.
-
The static IP policy applies only to StatefulSet-managed pods.
Related documents
-
For flexible pod firewall policies, configure multiple security groups for an ENI.
-
For container network issues, see Container network FAQ.