我正在尝试在 kubernetes 集群中运行Spring批处理应用程序。我能够通过在部署 yaml 中放置以下代码段来强制对主应用程序 Pod 进行资源限制:
resources:
limits:
cpu: 500m
ephemeral-storage: 500Mi
memory: 250Mi
这些设置正在应用,可以在pod yaml(kubectl编辑pod批处理)中看到。
但是,这些限制不会传播到工作pod。我尝试在批处理的configmap中添加以下属性来设置cpu和内存限制:
SPRING.CLOUD.DEPLOYER.KUBERNETES.CPU: 500m
SPRING.CLOUD.DEPLOYER.KUBERNETES.MEMORY: 250Mi
然而,工人舱没有达到这些限制。我也尝试提供以下环境变量,但这些限制仍不适用于工作吊舱:
SPRING_CLOUD_DEPLOYER_KUBERNETES_CPU: 500m
SPRING_CLOUD_DEPLOYER_KUBERNETES_MEMORY: 250Mi
涉及的版本有:
我如何设置这些限制?
编辑:添加部署分区处理程序的代码:
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);
}
由于< code > DeployerPartitionHandler 是使用< code>partitionHandler方法中的< code>new运算符创建的,因此它不知道属性文件中的值。< code > DeployerPartitionHandler 为< code > deployment properties 提供了一个setter。您应该使用此参数来指定工作任务的部署属性。
编辑:基于格伦·伦弗罗的评论
部署属性应该是spring.cloud.deployer.kubernetes.limits.cpu
而不是spring.cloud.deployer.kubernetes.cpu
。