You can create a cluster-specific PodNetworking ConfigMap on a virtual node to specify separate vSwitches and security groups for each pod on the virtual node. This topic describes how to configure separate vSwitches and security groups for a pod by creating a PodNetworking ConfigMap in scenarios where ACK Serverless clusters are used.
Table of contents
Step 1: Create a PodNetworking ConfigMap
In an ACK Serverless cluster, you can create multiple PodNetworking ConfigMaps to define different network planes. Before you start, you must create at least one PodNetworking ConfigMap to specify network configurations. The following code block shows a sample PodNetworking ConfigMap:
apiVersion: network.alibabacloud.com/v1beta1
kind: PodNetworking
metadata:
name: example
spec:
allocationType:
type: Elastic
selector:
podSelector:
matchLabels:
foo: bar
namespaceSelector:
matchLabels:
foo: bar
securityGroupIDs:
- sg-bpxxxx
vSwitchOptions:
- vsw-bpxxxxThe following table describes the parameters.
Parameter | Type | Description |
allocationType | type | Valid values:
Important Pods deployed in ACK Serverless clusters do not support static IP addresses. When the type parameter is set to Fixed, the corresponding PodNetworking ConfigMap takes effect on all pods that match the selectors of the PodNetworking ConfigMap, including pods created by StatefulSets. In this case, the PodNetworking ConfigMap does not support the |
selector | podSelector |
|
namespaceSelector |
| |
securityGroupIDs | N/A | Specify multiple security group IDs. In an ACK Serverless cluster, only the first security group ID takes effect. You can specify at most five security groups. |
vSwitchOptions | N/A |
|
Step 2: Create a pod
When ACK creates a pod, ACK matches the labels of the pod with PodNetworking ConfigMaps. If the pod does not match any PodNetworking ConfigMap, the pod uses an IP address allocated from a shared elastic network interface (ENI) by default. If the pod matches a PodNetworking ConfigMap, an IP address is allocated from an ENI to the pod based on the network configurations in the PodNetworking ConfigMap. For more information about pod labels, see Labels.
Example
The following code block shows how ACK allocates network resources to pods with specific labels, and uses Deployments to create the desired number of pods.
---
apiVersion: network.alibabacloud.com/v1beta1
kind: PodNetworking
metadata:
name: example
spec:
allocationType:
type: Elastic
selector:
podSelector:
matchLabels:
foo: bar
# Security groups that are created in the same virtual private cloud (VPC).
securityGroupIDs:
- sg-2zee386juyk226k1cb5h
# vSwitches that reside in the same VPC.
vSwitchOptions:
- vsw-2zewh0vanjx3vmjisna6z
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: elastic-podnetworking
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
# Match the pod selector of a PodNetworking ConfigMap.
foo: bar
spec:
containers:
- name: my-container
image: nginxFAQ
How do I check whether a pod uses the network configurations specified in a PodNetworking ConfigMap?
If a pod uses the network configurations specified in a PodNetworking ConfigMap, an annotation whose value is k8s.aliyun.com/pod-networking is added to the pod after the pod is created.
apiVersion: v1
kind: Pod
metadata:
annotations:
k8s.aliyun.com/pod-eni: "true"
k8s.aliyun.com/pod-networking: podnetworking
labels:
app: example
pod-ip: elasticWhy does a pod not use the network configurations specified in the desired PodNetworking ConfigMap after the pod is created?
Make sure that the labels of the pod match only one PodNetworking ConfigMap.