<p>I am running Spring Batch application in Kubernetes environment. The k8s cluster have one master and three worker nodes. I am testing spring batch under high load, which is spawning around 100 worker pods. However, all the 100 pods are coming up only on two out of three worker nodes. No node selector or additional labeling has been done on the nodes.</p>
<p>I have used Spring cloud deployer Kubernetes to create worker pods in Kubernetes.</p>
<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 ensure that worker pods get scheduled on all available worker nodes evenly?</p>
<p>Following is the partition handler implementation responsible for launching the tasks.</p>
<pre><code>@Bean
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>

<p>Posting this out of comments as a community wiki for better visibility, feel free to edit and expand.</p>
<hr />
<p>There are scheduling mechanics which can prevent scheduling pods on some nodes:</p>
<ul>
<li><p><a href="https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/" rel="nofollow noreferrer">Taints and tolerations</a></p>
</li>
<li><p><a href="https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/" rel="nofollow noreferrer">Node selector</a></p>
</li>
</ul>
<p>If nothing is set, it's worth trying to rejoin the node. For instance it might not be registered correctly (this solved the issue above).</p>
