昇腾社区首页
中文
注册

准备yaml文件

该示例主要基于k8s集群训练场景,通过配置yaml文件,指定宿主机挂载目录、容器内日志存储路径,以及容器内目录路径和宿主机路径映射关系等。具体如下:

配置容器内环境变量

为训练容器配置环境变量,指定JOB NAME的环境变量与日志挂载目录。
containers:
   - name: ${训练容器名}
     .....                                        # 其他配置项
     env:
     - name: GROUP_NAME
       valueFrom:
         fieldRef:
           fieldPath: metadata.annotations['scheduling.k8s.io/group-name']
     - name: HOST_IP
       valueFrom:
         fieldRef:
           fieldPath: status.hostIP
     - name: ASCEND_LOG_ROTATE_SCRIPT_DIR
       value: /var/log/ascend_log/script
     .....  

scheduling.k8s.io/group-name为Volcano调度器设置的注解键,用户可根据实际情况自定义GROUP_NAME。

配置宿主机与容器目录挂载关系

配置PoD挂载宿主机目录与容器内路径映射关系,挂载容器内日志目录至宿主机。以下示例中,以/var/log/ascend_log为挂载路径名。
containers:
   - name: ${训练容器名}
     .....                                        # 其他配置项
     volumeMounts:
     # 映射到容器目录
     - name: ascend-log-path
       mountPath: /var/log/ascend_log
     - name: ascend-script-path
       mountPath: /var/log/ascend_log/script
     - name: host-log-path
       mountPath: /var/log/messages
     volumes:
     # 挂载本地目录
     - name: ascend-log-path
       hostPath:
         path: /var/log/ascend_log
     - name: ascend-script-path
       hostPath:
         path: /var/log/ascend_log/script
     - name: host-log-path
       hostPath:
         path: /var/log/messages    # 部分OS系统日志保存在/var/log/syslog,请根据实际情况调整

配置训练容器执行命令

为训练容器配置执行命令。在训练脚本启动前、结束后分别执行日志转储脚本。

containers:
   - name: ${训练容器名}
     .....                                          # 其他配置项
     command:
     - "/bin/bash"
     - "-c"
     - |      
       source /var/log/ascend_log/scripts/ascend_log_rotate.sh 1
       bash ${训练脚本}
       source /var/log/ascend_log/scripts/ascend_log_rotate.sh 0

该步骤主要用于执行训练脚本启动前、结束后分别执行日志转储脚本,进行日志采集。

  • source /var/log/ascend_log/scripts/ascend_log_rotate.sh 1/0 中的参数1代表训练前收集,参数0代表训练后收集,请严格按照执行顺序执行,否则会导致日志采集失败。