Skip to content

Build and load Kernel Model

Note

We need an entitlement to install kernel sources.

Service account & privileges

oc apply -f https://examples.openshift.pub/cluster-configuration/build-load-kernel-module/service-account-and-rbac.yaml.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: privileged
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: privileged
rules:
- apiGroups:
  - security.openshift.io
  resourceNames:
  - privileged
  resources:
  - securitycontextconstraints
  verbs:
  - use
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: sa-to-privileged
subjects:
  - kind: ServiceAccount
    name: privileged
roleRef:
  kind: Role
  name: privileged
  apiGroup: rbac.authorization.k8s.io

Entitlement

1
2
3
oc create secret generic etc-pki-entitlement \
  --from-file=entitlement.pem=./export/entitlement_certificates/xxx.pem
  --from-file entitlement-key.pem=./export/entitlement_certificates/xxx.pem

DaemonSet / Deployment (Build & Run/Load)

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: nuc-led-kernel-module
spec:
  updateStrategy:
    type: OnDelete
  selector:
    matchLabels:
      name: nuc-led-kernel-module
  template:
    metadata:
      labels:
        name: nuc-led-kernel-module
    spec:
      tolerations:
        - operator: Exists
      hostname: nuc-led-kernel-module
      serviceAccount: privileged
      serviceAccountName: privileged
      volumes:
      - name: etc-pki-entitlement
        secret:
          defaultMode: 420
          secretName: etc-pki-entitlement
      containers:
        - name: rhel
          image: registry.access.redhat.com/ubi8/s2i-base:latest
          lifecycle:
            preStop:
              exec:
                command:
                  - /usr/bin/bash
                  - -c
                  - |
                    set -euxo pipefail
                    rmmod nuc_led
          command:
            - /usr/bin/bash
            - -c
            - |

              set -euxo pipefail

              rm /etc/rhsm-host

              dnf install -y gcc-toolset-10-gcc kernel-devel \
                             kernel-headers kernel-modules \
                             elfutils-libelf-devel


              git clone https://github.com/nomego/intel_nuc_led
              cd intel_nuc_led

              make
              make install
              modprobe nuc_led

              while true; do
                date
                cat  /proc/acpi/nuc_led
                sleep 60
              done

              sleep infinity

          securityContext:
            privileged: true
            runAsUser: 0

          volumeMounts:
          - mountPath: /etc/pki/entitlement
            name: etc-pki-entitlement
oc apply -f https://examples.openshift.pub/cluster-configuration/build-load-kernel-module/daemonset.yaml

2021-08-03 2021-08-03 Contributors: Robert Bohne