spring批处理和spring云部署kubernetes中的Worker pod资源限制



我正在尝试在kubernetes集群中运行Spring批处理应用程序。通过在部署yaml中放置以下代码片段,我能够对主应用程序pod强制执行资源限制:

resources:
limits:
cpu: 500m
ephemeral-storage: 500Mi
memory: 250Mi

这些设置正在被应用,并且可以在pod yaml (kubectl edit pod batch)中看到。

然而,这些限制不会传播到工作pod。我尝试在批处理的configmap中添加以下属性来设置cpu和内存限制:

SPRING.CLOUD.DEPLOYER.KUBERNETES.CPU: 500m
SPRING.CLOUD.DEPLOYER.KUBERNETES.MEMORY: 250Mi

然而,工作舱没有得到这些限制。我也尝试提供以下环境变量,但仍然没有将限制应用于工作pod:

SPRING_CLOUD_DEPLOYER_KUBERNETES_CPU: 500m
SPRING_CLOUD_DEPLOYER_KUBERNETES_MEMORY: 250Mi

涉及的版本有:

  • Spring Boot: 2.1.9.RELEASE
  • 春云:2020.0.1
  • Spring Cloud Deployer: 2.5.0
  • Spring Cloud Task: 2.1.1.RELEASE
  • Kubernetes: 1.21

如何设置这些限制?

编辑:添加DeployerPartitionerHandler代码:

public PartitionHandler partitionHandler(TaskLauncher taskLauncher, JobExplorer jobExplorer) {
Resource resource = this.resourceLoader.getResource(resourceSpec);
DeployerPartitionHandler partitionHandler = new DeployerPartitionHandler(taskLauncher, jobExplorer, resource,
"worker");
commandLineArgs.add("--spring.profiles.active=worker");
commandLineArgs.add("--spring.cloud.task.initialize.enable=false");
commandLineArgs.add("--spring.batch.initializer.enabled=false");
commandLineArgs.add("--spring.cloud.task.closecontext_enabled=true");
commandLineArgs.add("--logging.level.root=DEBUG");
partitionHandler.setCommandLineArgsProvider(new PassThroughCommandLineArgsProvider(commandLineArgs));
partitionHandler.setEnvironmentVariablesProvider(environmentVariablesProvider());
partitionHandler.setApplicationName(appName + "worker");
partitionHandler.setMaxWorkers(maxWorkers);
return partitionHandler;
}
@Bean
public EnvironmentVariablesProvider environmentVariablesProvider() {
return new SimpleEnvironmentVariablesProvider(this.environment);
}

由于DeployerPartitionHandler是使用partitionHandler方法中的new操作符创建的,因此它不知道属性文件中的值。DeployerPartitionHandlerdeploymentProperties提供setter。您应该使用此参数为辅助任务指定部署属性。

编辑:基于Glenn Renfro的评论

部署属性应该是spring.cloud.deployer.kubernetes.limits.cpu而不是spring.cloud.deployer.kubernetes.cpu

相关内容

最新更新