|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * networking/hardware_networks/configuring-sriov-device.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | +[id="nw-configuring-sriov-in-app-namespace_{context}"] |
| 7 | += Configuring SriovNetwork in application namespaces |
| 8 | + |
| 9 | +When an SriovNetwork custom resource (CR) is deployed in an application namespace, do not define or populate the `spec.networkNamespace` field. In this scenario, the NetworkAttachmentDefinition will be created in the same namespace as the SriovNetwork CR. |
| 10 | + |
| 11 | +The SR-IOV Network Operator webhook rejects the creation of an `SriovNetwork` resource in an application namespace if the `spec.networkNamespace` field is defined. |
| 12 | + |
| 13 | +Follow this procedure to create an `SriovNetwork` resource in an application namespace and attach a pod to the additional network. |
| 14 | + |
| 15 | +.Prerequisites |
| 16 | + |
| 17 | +The following steps must be completed by a cluster administrator before an application owner can configure a namespaced SriovNetwork resource: |
| 18 | + |
| 19 | +* The SR-IOV Network Operator is installed in the `openshift-sriov-network-operator` namespace. |
| 20 | +* Nodes with SR-IOV hardware are labeled for the operator to identify the nodes. |
| 21 | +
|
| 22 | +As an application owner you need to have administrator privileges on the application namespace. |
| 23 | + |
| 24 | +.Procedure |
| 25 | + |
| 26 | +. Specify the SR-IOV network device configuration for a node by creating an SR-IOV network node policy. The `SriovNetworkNodePolicy` object is created in the `openshift-sriov-network-operator` namespace to define the SR-IOV network device configuration for nodes. Example configuration for Intel DPK is as follows: |
| 27 | ++ |
| 28 | +[source,yaml] |
| 29 | +---- |
| 30 | +apiVersion: sriovnetwork.openshift.io/v1 |
| 31 | +kind: SriovNetworkNodePolicy |
| 32 | +metadata: |
| 33 | + name: intel-dpdk-node-policy |
| 34 | + namespace: openshift-sriov-network-operator |
| 35 | +spec: |
| 36 | + resourceName: intelnics |
| 37 | + nodeSelector: |
| 38 | + feature.node.kubernetes.io/network-sriov.capable: "true" |
| 39 | + priority: 10 |
| 40 | + numVfs: 4 |
| 41 | + nicSelector: |
| 42 | + vendor: "8086" |
| 43 | + deviceID: "158b" |
| 44 | + pfNames: [""] |
| 45 | + deviceType: netdevice |
| 46 | +---- |
| 47 | + |
| 48 | +. Create an application namespace. For example, create a namespace named `sriov-app` by running the following command: |
| 49 | ++ |
| 50 | +[source,terminal] |
| 51 | +---- |
| 52 | +$ cat <<EOF | oc create -f - |
| 53 | +apiVersion: v1 |
| 54 | +kind: Namespace |
| 55 | +metadata: |
| 56 | + name: sriov-app |
| 57 | +EOF |
| 58 | +---- |
| 59 | + |
| 60 | +. Create a YAML file, for example, `sriovnetwork.yaml`, to define the `SriovNetwork` object in the application namespace. |
| 61 | ++ |
| 62 | +[source,yaml] |
| 63 | +---- |
| 64 | +apiVersion: sriovnetwork.openshift.io/v1 |
| 65 | +kind: SriovNetwork |
| 66 | +metadata: |
| 67 | + name: test-network |
| 68 | + namespace: sriov-app |
| 69 | +spec: |
| 70 | + resourceName: intelnics |
| 71 | + ipam: |
| 72 | + type: host-local |
| 73 | + subnet: "10.0.0.0/24" |
| 74 | + routes: |
| 75 | + - dst: "0.0.0.0/0" |
| 76 | + gw: "10.0.0.1" |
| 77 | + vlan: 10 |
| 78 | +---- |
| 79 | +* `namespace`: The value must match the name of the application namespace, for example, `sriov-app`. |
| 80 | +* `resourceName`: This value must match the `spec.resourceName` defined in the `SriovNetworkNodePolicy` created by the cluster administrator, which in the example is `intelnics`. |
| 81 | +
|
| 82 | +. Apply the YAML file to create the `SriovNetwork` object in the application namespace. |
| 83 | ++ |
| 84 | +[source,terminal] |
| 85 | +---- |
| 86 | +$ oc create -f sriovnetwork.yaml |
| 87 | +---- |
| 88 | ++ |
| 89 | +After an application owner has created the SriovNetwork resource, they can create a pod that uses the newly defined network. You attach a pod to the additional network by adding a specific annotation to the pod's YAML manifest. |
| 90 | + |
| 91 | +. Create a YAML file, for example, `test-pod.yaml`, to define a pod that uses the new network attachment: |
| 92 | ++ |
| 93 | +[source,yaml] |
| 94 | +---- |
| 95 | +apiVersion: v1 |
| 96 | +kind: Pod |
| 97 | +metadata: |
| 98 | + name: test-pod |
| 99 | + namespace: sriov-app |
| 100 | + annotations: |
| 101 | + k8s.v1.cni.cncf.io/networks: test-network |
| 102 | +spec: |
| 103 | + containers: |
| 104 | + - name: test-pod-container |
| 105 | + image: centos/tools |
| 106 | + command: ["/bin/bash", "-c", "sleep 3600"] |
| 107 | +---- |
| 108 | ++ |
| 109 | +* `namespace`: The namespace where the pod is created. This must be the same namespace where the `SriovNetwork` object is created. |
| 110 | +* `annotations`: `k8s.v1.cni.cncf.io/networks` specifies the additional network that the pod connects to. The value must match the `metadata.name` of the `SriovNetwork` object. |
| 111 | +
|
| 112 | +. Apply the YAML file to create the pod in the application namespace by running the following command: |
| 113 | ++ |
| 114 | +[source,terminal] |
| 115 | +---- |
| 116 | +$ oc create -f test-pod.yaml |
| 117 | +---- |
| 118 | + |
| 119 | +.Verification |
| 120 | + |
| 121 | +. Verify that the NetworkAttachmentDefinition has been created in the same namespace by running the following command: |
| 122 | ++ |
| 123 | +[source,terminal] |
| 124 | +---- |
| 125 | +$ oc get net-attach-def -n sriov-app |
| 126 | +---- |
| 127 | ++ |
| 128 | +Where `sriov-app` is the application namespace where the `SriovNetwork` object is created. |
| 129 | ++ |
| 130 | +.Example output |
| 131 | ++ |
| 132 | +[source,terminal] |
| 133 | +---- |
| 134 | +NAME AGE |
| 135 | +test-network 2m |
| 136 | +---- |
| 137 | + |
| 138 | +. Verify the pod is running and get its network status by describing the pod with the following command: |
| 139 | ++ |
| 140 | +[source,terminal] |
| 141 | +---- |
| 142 | +$ oc describe pod test-pod -n sriov-app |
| 143 | +---- |
| 144 | ++ |
| 145 | +Where `sriov-app` is the application namespace where the pod is created. |
| 146 | ++ |
| 147 | +In the output, look for the `k8s.v1.cni.cncf.io/network-status` annotation. This shows the name of the network and the IP assigned to the pod on that interface. |
| 148 | + |
| 149 | +. Check that the pod has the additional network interface by running the following command: |
| 150 | ++ |
| 151 | +[source,terminal] |
| 152 | +---- |
| 153 | +$ oc exec -it test-pod -n sriov-app -- ip a |
| 154 | +---- |
| 155 | ++ |
| 156 | +Look for a secondary network interface, for example `net1` or `eth1`, in addition to the default eth0 interface. The `net1` interface should have an IP address from the subnet you defined in the SriovNetwork object, for example `10.0.0.0/24`. This confirms the pod is using the new network attachment definition. |
| 157 | + |
0 commit comments