<p>In the <em><a href="https://rads.stackoverflow.com/amzn/click/com/B072TS9ZQZ" rel="nofollow noreferrer" rel="nofollow noreferrer">Kubernetes Book</a></em>, it says that it's poor form to run pods on the master node.</p>

<p>Following this advice, I'd like to create a policy that runs a pod on all nodes, except the master if there are more than one nodes. However, to simplify testing and work in single-node environments, I'd also like to run my pod on the master node if there is just a single node in the entire system.</p>

<p>I've been looking around, and can't figure out how to express this policy. I see that <a href="https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/" rel="nofollow noreferrer">DaemonSets</a> have affinities and anti-affinities. I considered labeling the master node and adding an anti-affinity for that label. However, I didn't see how to require that at least a single pod would always come up (to ensure that things worked for single-node environment). Please let me know if I'm misunderstanding something. Thanks!</p>

<p>How about something like this:</p>

<ol>
<li>During node provisioning, assign a particular label to each node that should run the job. In a single node cluster, this would be the master. In a multi-node environment, it would be every node except the master(s).</li>
<li>Create a deamonset that has tolerations for any nodes</li>
</ol>

<pre><code>tolerations:
    - key: node-role.kubernetes.io/master
      effect: NoSchedule
</code></pre>

<ol start="3">
<li>As described in that doc you linked, use <code>.spec.template.spec.nodeSelector</code> to select only nodes with your special label. (<a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/" rel="nofollow noreferrer">node selector docs</a>).</li>
</ol>

<p>How you assign the special label to nodes is probably a fairly manual process heavily dependent on how you are actually deploying your clusters, but that is the general plan I would follow.</p>

<p><strong>EDIT:</strong> Or I believe it may be simplest to just remove the master node taint from your single-node cluster. I believe most simple distributions like minikube will come this way by default.</p>
