为从 SCDF 启动的批处理作业创建的 PODS 的 ConfigMap

Posted

技术标签:

【中文标题】为从 SCDF 启动的批处理作业创建的 PODS 的 ConfigMap【英文标题】:ConfigMap for PODS created for Batch jobs launched from SCDF 【发布时间】:2020-11-14 05:17:01 【问题描述】:

我从 SCDF 启动 Spring 批处理作业。批处理应用程序在 openshift 环境中部署为 docker 映像。并且 SCDF 在与 docker 镜像相同的命名空间下运行在相同的 openshift 环境中。

为 SCDF 创建的配置映射运行良好。但是,当我将批处理项目的 application.yaml 添加到 openshift config-map 时,POD 在从 SCDF 启动时不会引用它。我为“spring.applciation.name”和 config-map 的“metadata.name”赋予了相同的名称。我还在批处理应用程序中添加了以下属性。但这没有用。 config-map 中的属性不会被读取。

application.yaml

spring:
  application:
    name: batch-app
  cloud:
    kubernetes:
      config:
        name: batch-app
        namespace: batch-app-qa
        sources:
        - name: batch-app

config-map.yaml

apiVersion: v1
kind: ConfigMap
metaData:
  name: batch-app
  namespace: batch-app-qa
  labels:
    app: batch-app
data:
  application.properties: |-
    message=In QA Environment
    spring.datasource.batch.password=**********
    spring.datasource.batch2.password=********

作业/POD 日志:

[main] WARN  org.springframework.cloud.kubernetes.config.ConfigMapPropertySource.getData - Can't read configMap with name: [batch-app] in namespace:[batch-app-qa]. Ignoring.
io.fabric8.kubernetes.client.KubernetesClientException: Operation: [get]  for kind: [ConfigMap]  with name: [batch-app]  in namespace: [batch-app-qa]  failed.
    at io.fabric8.kubernetes.client.KubernetesClientException.launderThrowable(KubernetesClientException.java:72) ~[kubernetes-client-4.4.1.jar!/:na]
    at io.fabric8.kubernetes.client.dsl.base.BaseOperation.getMandatory(BaseOperation.java:229) ~[kubernetes-client-4.4.1.jar!/:na]
    at io.fabric8.kubernetes.client.dsl.base.BaseOperation.get(BaseOperation.java:162) ~[kubernetes-client-4.4.1.jar!/:na]
    at org.springframework.cloud.kubernetes.config.ConfigMapPropertySource.getData(ConfigMapPropertySource.java:95) [spring-cloud-kubernetes-config-1.1.2.RELEASE.jar!/:1.1.2.RELEASE]
    at org.springframework.cloud.kubernetes.config.ConfigMapPropertySource.<init>(ConfigMapPropertySource.java:76) [spring-cloud-kubernetes-config-1.1.2.RELEASE.jar!/:1.1.2.RELEASE]
    at org.springframework.cloud.kubernetes.config.ConfigMapPropertySourceLocator.getMapPropertySourceForSingleConfigMap(ConfigMapPropertySourceLocator.java:95) [spring-cloud-kubernetes-config-1.1.2.RELEASE.jar!/:1.1.2.RELEASE]
    at org.springframework.cloud.kubernetes.config.ConfigMapPropertySourceLocator.lambda$locate$0(ConfigMapPropertySourceLocator.java:78) [spring-cloud-kubernetes-config-1.1.2.RELEASE.jar!/:1.1.2.RELEASE]

Caused by: javax.net.ssl.SSLException: java.net.SocketException: Broken pipe (Write failed)
    at sun.security.ssl.Alerts.getSSLException(java.base@9-internal/Alerts.java:214) ~[na:na]
    at sun.security.ssl.SSLSocketImpl.fatal(java.base@9-internal/SSLSocketImpl.java:1962) ~[na:na]

[main] INFO  org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize - Located property source: [BootstrapPropertySource name='bootstrapProperties-configmap.batch-app.batch-app-qa']

运行作业时的 SCDF 日志

2020-07-24 12:24:33.479  WARN 1 --- [-nio-80-exec-10] ApplicationConfigurationMetadataResolver : Failed to retrieve properties for resource:Docker Resource [docker:docker-registry.default.svc:5000/batch-app-qa/batch-job]   ---> **This is the Batch Application being loaded into scdf for job launch**

java.lang.NullPointerException: null
    at org.springframework.cloud.dataflow.configuration.metadata.container.DefaultContainerImageMetadataResolver.getRegistryRequest(DefaultContainerImageMetadataResolver.java:162) ~[spring-cloud-dataflow-configuration-metadata-2.5.1.RELEASE.jar!/:2.5.1.RELEASE]
    at org.springframework.cloud.dataflow.configuration.metadata.container.DefaultContainerImageMetadataResolver.getImageLabels(DefaultContainerImageMetadataResolver.java:110) ~[spring-cloud-dataflow-configuration-metadata-2.5.1.RELEASE.jar!/:2.5.1.RELEASE]
    at org.springframework.cloud.dataflow.configuration.metadata.BootApplicationConfigurationMetadataResolver.resolvePropertiesFromContainerImage(BootApplicationConfigurationMetadataResolver.java:157) ~[spring-cloud-dataflow-configuration-metadata-2.5.1.RELEASE.jar!/:2.5.1.RELEASE]
    at org.springframework.cloud.dataflow.configuration.metadata.BootApplicationConfigurationMetadataResolver.listProperties(BootApplicationConfigurationMetadataResolver.java:134) ~[spring-cloud-dataflow-configuration-metadata-2.5.1.RELEASE.jar!/:2.5.1.RELEASE]
    at org.springframework.cloud.dataflow.server.controller.WhitelistProperties.qualifyProperties(WhitelistProperties.java:62) [spring-cloud-dataflow-server-core-2.5.1.RELEASE.jar!/:2.5.1.RELEASE]
    at org.springframework.cloud.dataflow.server.service.impl.TaskServiceUtils.mergeAndExpandAppProperties(TaskServiceUtils.java:164) [spring-cloud-dataflow-server-core-2.5.1.RELEASE.jar!/:2.5.1.RELEASE]
    at org.springframework.cloud.dataflow.server.service.impl.TaskAppDeploymentRequestCreator.createRequest(TaskAppDeploymentRequestCreator.java:115) [spring-cloud-dataflow-server-core-2.5.1.RELEASE.jar!/:2.5.1.RELEASE]
    at org.springframework.cloud.dataflow.server.service.impl.DefaultTaskExecutionService.executeTask(DefaultTaskExecutionService.java:258) [spring-cloud-dataflow-server-core-2.5.1.RELEASE.jar!/:2.5.1.RELEASE]
    at org.springframework.cloud.dataflow.server.service.impl.DefaultTaskExecutionService$$FastClassBySpringCGLIB$$422cda43.invoke(<generated>) [spring-cloud-dataflow-server-core-2.5.1.RELEASE.jar!/:2.5.1.RELEASE]
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) [spring-core-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771) [spring-aop-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) [spring-aop-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:366) ~[spring-tx-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118) ~[spring-tx-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) [spring-aop-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691) ~[spring-aop-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
    at org.springframework.cloud.dataflow.server.service.impl.DefaultTaskExecutionService$$EnhancerBySpringCGLIB$$4d03bb9f.executeTask(<generated>) ~[spring-cloud-dataflow-server-core-2.5.1.RELEASE.jar!/:2.5.1.RELEASE]
    at org.springframework.cloud.dataflow.server.controller.TaskExecutionController.launch(TaskExecutionController.java:172) ~[spring-cloud-dataflow-server-core-2.5.1.RELEASE.jar!/:2.5.1.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_212]

如何为从 SCDF 启动的 pod 提供配置映射。由于 Spring 启动批处理应用程序没有/不需要部署配置文件,我如何指定启动批处理应用程序在从 scdf 作为 pod 启动时引用配置映射?

谢谢。

【问题讨论】:

是您的docker-registry.default.svc:5000(批处理应用程序qa/批处理作业是从哪里解析的)docker注册表受机密保护?他们安装了吗?有关如何配置私有 docker 注册表的一些一般信息可在此处获得:dataflow.spring.io/docs/2.6.0.SNAPSHOT/feature-guides/general/… Docker 注册表与 SCDF 运行的位置相同。我可以拉出图像在其中运行作业。但是从 SCDF 启动作业时,它们找不到或找不到配置映射。 【参考方案1】:

如果您尝试为您的任务应用程序传递一些配置,您可以将您的配置放在您的 spring 云配置中,并将云配置 url 作为环境变量传递给任务应用程序,或者也可以直接将配置作为环境变量传递.

how to pass environment variables are documented in this SCDF documentation

【讨论】:

以上是关于为从 SCDF 启动的批处理作业创建的 PODS 的 ConfigMap的主要内容,如果未能解决你的问题,请参考以下文章

获取无法序列化SCDF中任务的访问异常

保持 SCDF 中的计划作业执行,直到上一个作业执行完成

backoffLimit/maxCrashLoopBackOffRestarts 的使用

从 SCDF 执行任务时,数据库凭证作为部分作业参数公开

SCDF 未获取最新的应用程序 docker 映像

Spring Cloud DataFlow 组合任务未启动