[
{
"name": "<name>", (1)
"mac": "<mac_address>", (2)
"ips": ["<cidr_range>"] (3)
}
]
You can add a pod to an existing Single Root I/O Virtualization (SR-IOV) network.
Before you perform any tasks in the following documentation, ensure that you installed the SR-IOV Network Operator.
When attaching a pod to an additional network, you can specify a runtime configuration to make specific customizations for the pod. For example, you can request a specific MAC hardware address.
You specify the runtime configuration by setting an annotation in the pod specification. The annotation key is k8s.v1.cni.cncf.io/networks
, and it accepts a JSON object that describes the runtime configuration.
The following JSON describes the runtime configuration options for an Ethernet-based SR-IOV network attachment.
[
{
"name": "<name>", (1)
"mac": "<mac_address>", (2)
"ips": ["<cidr_range>"] (3)
}
]
1 | The name of the SR-IOV network attachment definition CR. |
2 | Optional: The MAC address for the SR-IOV device that is allocated from the resource type defined in the SR-IOV network attachment definition CR. To use this feature, you also must specify { "mac": true } in the SriovNetwork object. |
3 | Optional: IP addresses for the SR-IOV device that is allocated from the resource type defined in the SR-IOV network attachment definition CR. Both IPv4 and IPv6 addresses are supported. To use this feature, you also must specify { "ips": true } in the SriovNetwork object. |
apiVersion: v1
kind: Pod
metadata:
name: sample-pod
annotations:
k8s.v1.cni.cncf.io/networks: |-
[
{
"name": "net1",
"mac": "20:04:0f:f1:88:01",
"ips": ["192.168.10.1/24", "2001::1/64"]
}
]
spec:
containers:
- name: sample-container
image: <image>
imagePullPolicy: IfNotPresent
command: ["sleep", "infinity"]
The following JSON describes the runtime configuration options for an InfiniBand-based SR-IOV network attachment.
[
{
"name": "<network_attachment>", (1)
"infiniband-guid": "<guid>", (2)
"ips": ["<cidr_range>"] (3)
}
]
1 | The name of the SR-IOV network attachment definition CR. |
2 | The InfiniBand GUID for the SR-IOV device. To use this feature, you also must specify { "infinibandGUID": true } in the SriovIBNetwork object. |
3 | The IP addresses for the SR-IOV device that is allocated from the resource type defined in the SR-IOV network attachment definition CR. Both IPv4 and IPv6 addresses are supported. To use this feature, you also must specify { "ips": true } in the SriovIBNetwork object. |
apiVersion: v1
kind: Pod
metadata:
name: sample-pod
annotations:
k8s.v1.cni.cncf.io/networks: |-
[
{
"name": "ib1",
"infiniband-guid": "c2:11:22:33:44:55:66:77",
"ips": ["192.168.10.1/24", "2001::1/64"]
}
]
spec:
containers:
- name: sample-container
image: <image>
imagePullPolicy: IfNotPresent
command: ["sleep", "infinity"]
You can add a pod to an additional network. The pod continues to send normal cluster-related network traffic over the default network.
When a pod is created additional networks are attached to it. However, if a pod already exists, you cannot attach additional networks to it.
The pod must be in the same namespace as the additional network.
The SR-IOV Network Resource Injector adds the If you are using an Intel network interface controller (NIC) in Data Plane Development Kit (DPDK) mode, only the first container in your pod is configured to access the NIC. Your SR-IOV additional network is configured for DPDK mode if the You can work around this issue by either ensuring that the container that needs access to the NIC is the first container defined in the |
Install the OpenShift CLI (oc
).
Log in to the cluster.
Install the SR-IOV Operator.
Create either an SriovNetwork
object or an SriovIBNetwork
object to attach the pod to.
Add an annotation to the Pod
object. Only one of the following annotation formats can be used:
To attach an additional network without any customization, add an annotation with the following format. Replace <network>
with the name of the additional network to associate with the pod:
metadata:
annotations:
k8s.v1.cni.cncf.io/networks: <network>[,<network>,...] (1)
1 | To specify more than one additional network, separate each network with a comma. Do not include whitespace between the comma. If you specify the same additional network multiple times, that pod will have multiple network interfaces attached to that network. |
To attach an additional network with customizations, add an annotation with the following format:
metadata:
annotations:
k8s.v1.cni.cncf.io/networks: |-
[
{
"name": "<network>", (1)
"namespace": "<namespace>", (2)
"default-route": ["<default-route>"] (3)
}
]
1 | Specify the name of the additional network defined by a NetworkAttachmentDefinition object. |
2 | Specify the namespace where the NetworkAttachmentDefinition object is defined. |
3 | Optional: Specify an override for the default route, such as 192.168.17.1 . |
To create the pod, enter the following command. Replace <name>
with the name of the pod.
$ oc create -f <name>.yaml
Optional: To Confirm that the annotation exists in the Pod
CR, enter the following command, replacing <name>
with the name of the pod.
$ oc get pod <name> -o yaml
In the following example, the example-pod
pod is attached to the net1
additional network:
$ oc get pod example-pod -o yaml
apiVersion: v1
kind: Pod
metadata:
annotations:
k8s.v1.cni.cncf.io/networks: macvlan-bridge
k8s.v1.cni.cncf.io/network-status: |- (1)
[{
"name": "ovn-kubernetes",
"interface": "eth0",
"ips": [
"10.128.2.14"
],
"default": true,
"dns": {}
},{
"name": "macvlan-bridge",
"interface": "net1",
"ips": [
"20.2.2.100"
],
"mac": "22:2f:60:a5:f8:00",
"dns": {}
}]
name: example-pod
namespace: default
spec:
...
status:
...
1 | The k8s.v1.cni.cncf.io/network-status parameter is a JSON array of
objects. Each object describes the status of an additional network attached
to the pod. The annotation value is stored as a plain text value. |
After adding a pod to an additional network, you can check that the MTU is available for the SR-IOV network.
Check that the pod annotation includes MTU by running the following command:
$ oc describe pod example-pod
The following example shows the sample output:
"mac": "20:04:0f:f1:88:01",
"mtu": 1500,
"dns": {},
"device-info": {
"type": "pci",
"version": "1.1.0",
"pci": {
"pci-address": "0000:86:01.3"
}
}
Verify that the MTU is available in /etc/podnetinfo/
inside the pod by running the following command:
$ oc exec example-pod -n sriov-tests -- cat /etc/podnetinfo/annotations | grep mtu
The following example shows the sample output:
k8s.v1.cni.cncf.io/network-status="[{
\"name\": \"ovn-kubernetes\",
\"interface\": \"eth0\",
\"ips\": [
\"10.131.0.67\"
],
\"mac\": \"0a:58:0a:83:00:43\",
\"default\": true,
\"dns\": {}
},{
\"name\": \"sriov-tests/sriov-nic-1\",
\"interface\": \"net1\",
\"ips\": [
\"192.168.10.1\"
],
\"mac\": \"20:04:0f:f1:88:01\",
\"mtu\": 1500,
\"dns\": {},
\"device-info\": {
\"type\": \"pci\",
\"version\": \"1.1.0\",
\"pci\": {
\"pci-address\": \"0000:86:01.3\"
}
}
}]"
You can create a NUMA aligned SR-IOV pod by restricting SR-IOV and the CPU resources allocated from the same NUMA node with restricted
or single-numa-node
Topology Manager policies.
You have installed the OpenShift CLI (oc
).
You have configured the CPU Manager policy to static
. For more information on CPU Manager, see the "Additional resources" section.
You have configured the Topology Manager policy to single-numa-node
.
When |
Create the following SR-IOV pod spec, and then save the YAML in the <name>-sriov-pod.yaml
file. Replace <name>
with a name for this pod.
The following example shows an SR-IOV pod spec:
apiVersion: v1
kind: Pod
metadata:
name: sample-pod
annotations:
k8s.v1.cni.cncf.io/networks: <name> (1)
spec:
containers:
- name: sample-container
image: <image> (2)
command: ["sleep", "infinity"]
resources:
limits:
memory: "1Gi" (3)
cpu: "2" (4)
requests:
memory: "1Gi"
cpu: "2"
1 | Replace <name> with the name of the SR-IOV network attachment definition CR. |
2 | Replace <image> with the name of the sample-pod image. |
3 | To create the SR-IOV pod with guaranteed QoS, set memory limits equal to memory requests . |
4 | To create the SR-IOV pod with guaranteed QoS, set cpu limits equals to cpu requests . |
Create the sample SR-IOV pod by running the following command:
$ oc create -f <filename> (1)
1 | Replace <filename> with the name of the file you created in the previous step. |
Confirm that the sample-pod
is configured with guaranteed QoS.
$ oc describe pod sample-pod
Confirm that the sample-pod
is allocated with exclusive CPUs.
$ oc exec sample-pod -- cat /sys/fs/cgroup/cpuset/cpuset.cpus
Confirm that the SR-IOV device and CPUs that are allocated for the sample-pod
are on the same NUMA node.
$ oc exec sample-pod -- cat /sys/fs/cgroup/cpuset/cpuset.cpus
The following testpmd
pod demonstrates container creation with huge pages, reserved CPUs, and the SR-IOV port.
testpmd
podapiVersion: v1
kind: Pod
metadata:
name: testpmd-sriov
namespace: mynamespace
annotations:
cpu-load-balancing.crio.io: "disable"
cpu-quota.crio.io: "disable"
# ...
spec:
containers:
- name: testpmd
command: ["sleep", "99999"]
image: registry.redhat.io/openshift4/dpdk-base-rhel8:v4.9
securityContext:
capabilities:
add: ["IPC_LOCK","SYS_ADMIN"]
privileged: true
runAsUser: 0
resources:
requests:
memory: 1000Mi
hugepages-1Gi: 1Gi
cpu: '2'
openshift.io/sriov1: 1
limits:
hugepages-1Gi: 1Gi
cpu: '2'
memory: 1000Mi
openshift.io/sriov1: 1
volumeMounts:
- mountPath: /dev/hugepages
name: hugepage
readOnly: False
runtimeClassName: performance-cnf-performanceprofile (1)
volumes:
- name: hugepage
emptyDir:
medium: HugePages
1 | This example assumes that the name of the performance profile is cnf-performance profile . |