<p>I have 1 master kubernetes server and 9 nodes. In that, I want to run backend on 2 nodes and frontend on 2 nodes and DB on 3 nodes.</p>

<p>For all backend, frontend, DB I have ready DockerImage.</p>

<p>How to run an image using kubernetes on only desired(2 or 3).</p>

<p>Please share some ideas to achieve the same. </p>

gokul kandasamy
<p>The Kubernetes scheduler most of the time will do a good job distributing the pods across the cluster. You may want to delegate that responsibility to the scheduler unless you have very specific requirements.</p>

<p>If you want to control this, you can use:</p>

<ul>
<li><a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector" rel="nofollow noreferrer">Node selectors</a></li>
<li><a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity" rel="nofollow noreferrer">Node Affinity or Anti-Affinity</a></li>
<li>Directly specify the <a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodename" rel="nofollow noreferrer">node name</a> in the deployment spec</li>
</ul>

<p>From these three, the recommended approach is to use node affinity or anti-affinity due to its flexibility.</p>
