<p>I am trying to run a Spring Batch application in kubernetes cluster. I am able to enforce resource limits to the main application pod by placing the following snippet in the deployment yaml:</p>
<pre><code>resources:
  limits:
    cpu: 500m
    ephemeral-storage: 500Mi
    memory: 250Mi
</code></pre>
<p>These settings are getting applied and can be seen in the pod yaml (kubectl edit pod batch).</p>
<p>However, these limits are not propagated to the worker pods. I tried adding the following properties in configmap of batch to set the cpu and memory limits:</p>
<pre><code>SPRING.CLOUD.DEPLOYER.KUBERNETES.CPU: 500m
SPRING.CLOUD.DEPLOYER.KUBERNETES.MEMORY: 250Mi
</code></pre>
<p>However, the worker pods are not getting these limits. I tried providing the following env variables too, but still the limits were not applied to the worker pod:</p>
<pre><code>SPRING_CLOUD_DEPLOYER_KUBERNETES_CPU: 500m
SPRING_CLOUD_DEPLOYER_KUBERNETES_MEMORY: 250Mi
</code></pre>
<p>The versions involved are:</p>
<ul>
<li>Spring Boot: 2.1.9.RELEASE</li>
<li>Spring Cloud: 2020.0.1</li>
<li>Spring Cloud Deployer: 2.5.0</li>
<li>Spring Cloud Task: 2.1.1.RELEASE</li>
<li>Kubernetes: 1.21</li>
</ul>
<p>How can I set these limits?</p>
<p>EDIT: Adding code for DeployerPartitionerHandler:</p>
<pre><code>public PartitionHandler partitionHandler(TaskLauncher taskLauncher, JobExplorer jobExplorer) {

    Resource resource = this.resourceLoader.getResource(resourceSpec);

    DeployerPartitionHandler partitionHandler = new DeployerPartitionHandler(taskLauncher, jobExplorer, resource,
            &quot;worker&quot;);

    commandLineArgs.add(&quot;--spring.profiles.active=worker&quot;);
    commandLineArgs.add(&quot;--spring.cloud.task.initialize.enable=false&quot;);
    commandLineArgs.add(&quot;--spring.batch.initializer.enabled=false&quot;);
    commandLineArgs.add(&quot;--spring.cloud.task.closecontext_enabled=true&quot;);
    commandLineArgs.add(&quot;--logging.level.root=DEBUG&quot;);

    partitionHandler.setCommandLineArgsProvider(new PassThroughCommandLineArgsProvider(commandLineArgs));
    partitionHandler.setEnvironmentVariablesProvider(environmentVariablesProvider());
    partitionHandler.setApplicationName(appName + &quot;worker&quot;);
    partitionHandler.setMaxWorkers(maxWorkers);

    return partitionHandler;
}

@Bean
public EnvironmentVariablesProvider environmentVariablesProvider() {
    return new SimpleEnvironmentVariablesProvider(this.environment);
}
</code></pre>

Abhinav Sharma
<p>Since the <code>DeployerPartitionHandler</code> is created using the <code>new</code> operator in the <code>partitionHandler</code> method, it is not aware of the values from the properties file. The <code>DeployerPartitionHandler</code> provides a setter for <code>deploymentProperties</code>. You should use this parameter to specify deployment properties for worker tasks.</p>
<p>EDIT: Based on comment by Glenn Renfro</p>
<p>The deployment property should be <code>spring.cloud.deployer.kubernetes.limits.cpu</code> and not <code>spring.cloud.deployer.kubernetes.cpu</code>.</p>
