<p>I am running a deployment on a cluster of 1 master and 4 worker nodes (2-32GB and 2-4GB machine). I want to run a maximum of 10 pods on 4GB machines and 50 pods in 32GB machines.</p>
<p>Is there a way to assign different number of pods to different nodes in Kubernetes for same deployment?</p>

love
<blockquote>
<p>I want to run a maximum of 10 pods on 4GB machines and 50 pods in 32GB
machines.</p>
</blockquote>
<p>This is possible with <a href="https://kubernetes.io/docs/tasks/administer-cluster/kubelet-config-file/" rel="nofollow noreferrer">configuring</a> kubelet to limit the maximum pod count on the node:</p>
<pre class="lang-golang prettyprint-override"><code>// maxPods is the number of pods that can run on this Kubelet.
MaxPods int32 `json:&quot;maxPods,omitempty&quot;`
</code></pre>
<p>Github can be found <a href="https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/kubelet/config/v1beta1/types.go#L480-L488" rel="nofollow noreferrer">here</a>.</p>
<blockquote>
<p>Is there a way to assign different number of pods to different nodes
in Kubernetes for same deployment?</p>
</blockquote>
<p>Adding this to your request makes it not possible. There is no such native mechanism in Kubernetes at this point to suffice this. And this more or less goes in spirit of how Kubernetes works and its principles. Basically you schedule your application and let scheduler decides where it should go, unless there is very specific resource required like GPU. And this is possible with labels,affinity etc .</p>
<p>If you look at the <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#deployment-v1-apps" rel="nofollow noreferrer">Kubernetes-API</a> you notice the there is no such field that will make your request possible. However, API functionality can be extended with custom resources and this problem can be tackled with creating your own scheduler. But this is not the easy way of fixing this.</p>
<p>You may want to also set appropriate memory requests. Higher requests will tell scheduler to deploy more pods into node which has more memory resources. It's not ideal but it is something.</p>
