13.2. 为批处理操作创建 ConfigMap

创建一个 ConfigMap,以便为批处理操作使用其他文件,如 Data Grid 缓存配置。

先决条件

出于演示目的,您应该在开始操作前将一些配置工件添加到主机文件系统中:

  • 创建一个 /tmp/mybatch 目录,您可以在其中添加一些文件。

    $ mkdir -p /tmp/mybatch
  • 创建 Data Grid 缓存配置。

    $ cat > /tmp/mybatch/mycache.xml<<EOF
    <distributed-cache name="mycache" mode="SYNC">
      <encoding media-type="application/x-protostream"/>
      <memory max-count="1000000" when-full="REMOVE"/>
    </distributed-cache>
    EOF

流程

  1. 创建包含您要运行的所有命令的 批处理 文件。

    例如,以下 批处理 文件会创建一个名为"mycache"的缓存,并为它添加两个条目:

    create cache mycache --file=/etc/batch/mycache.xml
    put --cache=mycache hello world
    put --cache=mycache hola mundo
    重要

    ConfigMap 挂载到位于 /etc/batch 的 Data Grid pod 中。您必须使用该路径在批处理操作中添加所有 --file= 指令。

  2. 确保批处理操作所需的所有配置工件与 批处理文件位于同一个目录中

    $ ls /tmp/mybatch
    
    batch
    mycache.xml
  3. 从 目录创建 ConfigMap

    $ oc create configmap mybatch-config-map --from-file=/tmp/mybatch