|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * scalability_and_performance/psap-driver-toolkit.adoc |
| 4 | + |
| 5 | +[id="using-the-driver-toolkit"] |
| 6 | += Using the Driver Toolkit |
| 7 | + |
| 8 | +As an example, the Driver Toolkit can be used as the base image for building a very simple kernel module called simple-kmod. |
| 9 | + |
| 10 | +[id="create-simple-kmod-image"] |
| 11 | +== Build and run the simple-kmod driver container on a cluster |
| 12 | + |
| 13 | +.Prerequisites |
| 14 | + |
| 15 | +* An {product-title} cluster |
| 16 | +* Install the OpenShift CLI (`oc`). |
| 17 | +* Log in as a user with `cluster-admin` privileges. |
| 18 | + |
| 19 | +.Procedure |
| 20 | + |
| 21 | +Create a namespace. For example: |
| 22 | +[source,terminal] |
| 23 | +----- |
| 24 | +$ oc new-project simple-kmod-demo |
| 25 | +----- |
| 26 | + |
| 27 | +. The YAML defines an `ImageStream` for storing the `simple-kmod` driver container image, and a `BuildConfig` for building the container. Save this YAML as `0000-buildconfig.yaml.template`. |
| 28 | ++ |
| 29 | +[source,yaml] |
| 30 | +---- |
| 31 | +apiVersion: image.openshift.io/v1 |
| 32 | +kind: ImageStream |
| 33 | +metadata: |
| 34 | + labels: |
| 35 | + app: simple-kmod-driver-container |
| 36 | + name: simple-kmod-driver-container |
| 37 | + namespace: simple-kmod-demo |
| 38 | +spec: {} |
| 39 | +--- |
| 40 | +apiVersion: build.openshift.io/v1 |
| 41 | +kind: BuildConfig |
| 42 | +metadata: |
| 43 | + labels: |
| 44 | + app: simple-kmod-driver-build |
| 45 | + name: simple-kmod-driver-build |
| 46 | + namespace: simple-kmod-demo |
| 47 | +spec: |
| 48 | + nodeSelector: |
| 49 | + node-role.kubernetes.io/worker: "" |
| 50 | + runPolicy: "Serial" |
| 51 | + triggers: |
| 52 | + - type: "ConfigChange" |
| 53 | + - type: "ImageChange" |
| 54 | + source: |
| 55 | + git: |
| 56 | + ref: "master" |
| 57 | + uri: "https://github.com/openshift-psap/kvc-simple-kmod.git" |
| 58 | + type: Git |
| 59 | + dockerfile: | |
| 60 | + FROM DRIVER_TOOLKIT_IMAGE |
| 61 | +
|
| 62 | + WORKDIR /build/ |
| 63 | +
|
| 64 | + RUN yum -y install git make sudo gcc \ |
| 65 | + && yum clean all \ |
| 66 | + && rm -rf /var/cache/dnf |
| 67 | +
|
| 68 | + # Expecting kmod software version as an input to the build |
| 69 | + ARG KMODVER |
| 70 | +
|
| 71 | + # Grab the software from upstream |
| 72 | + RUN git clone https://github.com/openshift-psap/simple-kmod.git |
| 73 | + WORKDIR simple-kmod |
| 74 | +
|
| 75 | + # Prep and build the module |
| 76 | + RUN make buildprep KVER=$(rpm -q --qf "%{VERSION}-%{RELEASE}.%{ARCH}" kernel-core) KMODVER=${KMODVER} \ |
| 77 | + && make all KVER=$(rpm -q --qf "%{VERSION}-%{RELEASE}.%{ARCH}" kernel-core) KMODVER=${KMODVER} \ |
| 78 | + && make install KVER=$(rpm -q --qf "%{VERSION}-%{RELEASE}.%{ARCH}" kernel-core) KMODVER=${KMODVER} |
| 79 | +
|
| 80 | + # Add the helper tools |
| 81 | + WORKDIR /root/kvc-simple-kmod |
| 82 | + ADD Makefile . |
| 83 | + ADD simple-kmod-lib.sh . |
| 84 | + ADD simple-kmod-wrapper.sh . |
| 85 | + ADD simple-kmod.conf . |
| 86 | + RUN mkdir -p /usr/lib/kvc/ \ |
| 87 | + && mkdir -p /etc/kvc/ \ |
| 88 | + && make install |
| 89 | +
|
| 90 | + RUN systemctl enable kmods-via-containers@simple-kmod |
| 91 | + strategy: |
| 92 | + dockerStrategy: |
| 93 | + buildArgs: |
| 94 | + - name: KMODVER |
| 95 | + value: DEMO |
| 96 | + output: |
| 97 | + to: |
| 98 | + kind: ImageStreamTag |
| 99 | + name: simple-kmod-driver-container:demo |
| 100 | +---- |
| 101 | + |
| 102 | +. Substitute the correct driver toolkit image for the {product-title} version you are running in place of “DRIVER_TOOLKIT_IMAGE” with the following commands. |
| 103 | ++ |
| 104 | +[source,terminal] |
| 105 | +---- |
| 106 | +$ OCP_VERSION=$(oc get clusterversion/version -ojsonpath={.status.desired.version}) |
| 107 | +---- |
| 108 | ++ |
| 109 | +[source,terminal] |
| 110 | +---- |
| 111 | +$ DRIVER_TOOLKIT_IMAGE=$(oc adm release info $OCP_VERSION --image-for=driver-toolkit) |
| 112 | +---- |
| 113 | ++ |
| 114 | +[source,terminal] |
| 115 | +---- |
| 116 | +$ sed "s#DRIVER_TOOLKIT_IMAGE#${DRIVER_TOOLKIT_IMAGE}#" 0000-buildconfig.yaml.template > 0000-buildconfig.yaml |
| 117 | +---- |
| 118 | ++ |
| 119 | +[NOTE] |
| 120 | +==== |
| 121 | +The driver toolkit was introduced to {product-title} 4.6 as of version 4.6.30, in 4.7 as of version 4.7.11, and in 4.8. |
| 122 | +==== |
| 123 | + |
| 124 | +. Create the image stream and build config with |
| 125 | ++ |
| 126 | +[source,terminal] |
| 127 | +---- |
| 128 | +$ oc create -f 0000-buildconfig.yaml |
| 129 | +---- |
| 130 | + |
| 131 | +. Once the builder pod completes successfully, deploy the driver container image as a `DaemonSet`. |
| 132 | + |
| 133 | +.. The driver container must run with the privileged security context in order to load the kernel modules on the host. The following YAML file contains the RBAC rules and the `DaemonSet` for running the driver container. Save this YAML as `1000-driver-container.yaml`. |
| 134 | ++ |
| 135 | +[source,yaml] |
| 136 | +---- |
| 137 | +apiVersion: v1 |
| 138 | +kind: ServiceAccount |
| 139 | +metadata: |
| 140 | + name: simple-kmod-driver-container |
| 141 | +--- |
| 142 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 143 | +kind: Role |
| 144 | +metadata: |
| 145 | + name: simple-kmod-driver-container |
| 146 | +rules: |
| 147 | +- apiGroups: |
| 148 | + - security.openshift.io |
| 149 | + resources: |
| 150 | + - securitycontextconstraints |
| 151 | + verbs: |
| 152 | + - use |
| 153 | + resourceNames: |
| 154 | + - privileged |
| 155 | +--- |
| 156 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 157 | +kind: RoleBinding |
| 158 | +metadata: |
| 159 | + name: simple-kmod-driver-container |
| 160 | +roleRef: |
| 161 | + apiGroup: rbac.authorization.k8s.io |
| 162 | + kind: Role |
| 163 | + name: simple-kmod-driver-container |
| 164 | +subjects: |
| 165 | +- kind: ServiceAccount |
| 166 | + name: simple-kmod-driver-container |
| 167 | +userNames: |
| 168 | +- system:serviceaccount:simple-kmod-demo:simple-kmod-driver-container |
| 169 | +--- |
| 170 | +apiVersion: apps/v1 |
| 171 | +kind: DaemonSet |
| 172 | +metadata: |
| 173 | + name: simple-kmod-driver-container |
| 174 | +spec: |
| 175 | + selector: |
| 176 | + matchLabels: |
| 177 | + app: simple-kmod-driver-container |
| 178 | + template: |
| 179 | + metadata: |
| 180 | + labels: |
| 181 | + app: simple-kmod-driver-container |
| 182 | + spec: |
| 183 | + serviceAccount: simple-kmod-driver-container |
| 184 | + serviceAccountName: simple-kmod-driver-container |
| 185 | + containers: |
| 186 | + - image: image-registry.openshift-image-registry.svc:5000/simple-kmod-demo/simple-kmod-driver-container:demo |
| 187 | + name: simple-kmod-driver-container |
| 188 | + imagePullPolicy: Always |
| 189 | + command: ["/sbin/init"] |
| 190 | + lifecycle: |
| 191 | + preStop: |
| 192 | + exec: |
| 193 | + command: ["/bin/sh", "-c", "systemctl stop kmods-via-containers@simple-kmod"] |
| 194 | + securityContext: |
| 195 | + privileged: true |
| 196 | + nodeSelector: |
| 197 | + node-role.kubernetes.io/worker: "" |
| 198 | +---- |
| 199 | + |
| 200 | +.. Create the RBAC rules and daemon set: |
| 201 | ++ |
| 202 | +[source,terminal] |
| 203 | +---- |
| 204 | +$ oc create -f 1000-drivercontainer.yaml |
| 205 | +---- |
| 206 | + |
| 207 | +. Once the pods are running on the worker nodes, verify that the `simple_kmod` kernel module is loaded successfully on the host machines with `lsmod`. |
| 208 | + |
| 209 | +.. Verify that the pods are running: |
| 210 | ++ |
| 211 | +[source,terminal] |
| 212 | +---- |
| 213 | +$ oc get pod -n simple-kmod-demo |
| 214 | +---- |
| 215 | ++ |
| 216 | +.Example output |
| 217 | +[source,terminal] |
| 218 | +---- |
| 219 | +NAME READY STATUS RESTARTS AGE |
| 220 | +simple-kmod-driver-build-1-build 0/1 Completed 0 6m |
| 221 | +simple-kmod-driver-container-b22fd 1/1 Running 0 40s |
| 222 | +simple-kmod-driver-container-jz9vn 1/1 Running 0 40s |
| 223 | +simple-kmod-driver-container-p45cc 1/1 Running 0 40s |
| 224 | +---- |
| 225 | + |
| 226 | +.. Execute the `lsmod` command in the driver container pod: |
| 227 | ++ |
| 228 | +[source,terminal] |
| 229 | +---- |
| 230 | +$ oc exec -it pod/simple-kmod-driver-container-p45cc -- lsmod | grep simple |
| 231 | +---- |
| 232 | ++ |
| 233 | +.Example output |
| 234 | +[source,terminal] |
| 235 | +---- |
| 236 | +simple_procfs_kmod 16384 0 |
| 237 | +simple_kmod 16384 0 |
| 238 | +---- |
0 commit comments