4.8. 构建并签署 ModuleLoader 容器镜像
如果您有源代码且必须首先构建镜像,请使用这个流程。
以下 YAML 文件使用存储库中的源代码构建新容器镜像。生成的镜像将保存到带有临时名称的 registry 中,然后使用
sign
部分中的参数来签名此临时镜像。
临时镜像名称基于最终镜像名称,设置为
<containerImage>:<tag>-<namespace>_<module name>_kmm_unsigned
。
例如,使用以下 YAML 文件,内核模块管理 (KMM) 构建一个名为
example.org/repository/minimal-driver:final-default_example-module_kmm_unsigned
的镜像,其中包含带有未签名的 kmods 的构建并将其推送到 registry。然后,它创建一个名为
example.org/repository/minimal-driver:final
的第二个镜像,其中包含签名的 kmod。它是
DaemonSet
对象载入的第二个镜像,并将 kmods 部署到集群节点。
签名后,可以从 registry 中安全地删除临时镜像。如果需要,它将被重建。
keySecret
和
certSecret
secret 已创建。
应用 YAML 文件:
apiVersion: v1
kind: ConfigMap
metadata:
name: example-module-dockerfile
namespace: default
1
data:
Dockerfile: |
ARG DTK_AUTO
ARG KERNEL_VERSION
FROM ${DTK_AUTO} as builder
WORKDIR /build/
RUN git clone -b main --single-branch https://github.com/rh-ecosystem-edge/kernel-module-management.git
WORKDIR kernel-module-management/ci/kmm-kmod/
RUN make
FROM registry.access.redhat.com/ubi8/ubi:latest
ARG KERNEL_VERSION
RUN yum -y install kmod && yum clean all
RUN mkdir -p /opt/lib/modules/${KERNEL_VERSION}
COPY --from=builder /build/kernel-module-management/ci/kmm-kmod/*.ko /opt/lib/modules/${KERNEL_VERSION}/
RUN /usr/sbin/depmod -b /opt
apiVersion: kmm.sigs.x-k8s.io/v1beta1
kind: Module
metadata:
name: example-module
namespace: default
2
spec:
moduleLoader:
serviceAccountName: default
3
container:
modprobe:
moduleName: simple_kmod
kernelMappings:
- regexp: '^.*\.x86_64$'
containerImage: < the name of the final driver container to produce>
build:
dockerfileConfigMap:
name: example-module-dockerfile
sign:
keySecret:
name: <private key secret name>
certSecret:
name: <certificate secret name>
filesToSign:
- /opt/lib/modules/4.18.0-348.2.1.el8_5.x86_64/kmm_ci_a.ko
imageRepoSecret:
4
name: repo-pull-secret
selector: # top-level selector
kubernetes.io/arch: amd64