<p>Let us assume that we have some predefined set of docker images on the private repository. Each of them takes a set of volumes, where input data are passed. Each image is a kind of a job - they represent an application that takes an input, computes the result, and then returns it as a file or something.</p>
<p>Currently, when the user wants to run a job, I can underneath invoke <code>docker run -v ... [image]</code> etc. Underneath, because everything is under some REST server API.
But, what if I want to schedule these images on the cluster? For simplicity let us assume that one image can be executed on a single machine, but in the future, I would like to have an option to schedule it to multiple machines.</p>
<p>So for example, now we have a cluster with machines A, B and C, user 1 invokes image x, and it is scheduled to machine A, then the same user schedules image y and it is scheduled to machine B (or A or C depending on their load), another user invokes image x with different input data (and thus volumes) and it is executed on machine A (or B or C - depending on their load; no dependencies between image and machine, or between images).</p>
<p>What can I use to achieve this? Can Kubernetes manage it? So far, looking at pods I think it cannot. Maybe just a load balancer is enough? Would like to take the most simple but also scalable and efficient solution.</p>

Witold Kupś
<p>A Kubernetes Job contains a pod template spec, so you just need to add to the PodSpec an anti-affinity rule with requiredDuringSchedulingRequiredDuringExecution where the exclusion selector will be the labels you set on the PodSpec.</p>
<p>Example:</p>
<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: stackoverflow
spec:
  template:
    metadata:
      labels:
        foo: bar
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingRequiredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: foo
                operator: In
                values:
                - bar
            topologyKey: &quot;kubernetes.io/hostname&quot;
</code></pre>
<p>More details in the <a href="https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#inter-pod-affinity-and-anti-affinity" rel="nofollow noreferrer">docs</a></p>
