Answers: <p>You can use <code>topologySpreadConstaints</code> for spreading Deployment pods evenly across nodes, regardless of the number of pods. Kubernetes documentation contains <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/" rel="nofollow noreferrer">multiple examples</a>, as well as following article - <a href="https://medium.com/geekculture/kubernetes-distributing-pods-evenly-across-cluster-c6bdc9b49699#:%7E:text=In%20order%20to%20distribute%20pods,in%20its%20own%20topology%20domain." rel="nofollow noreferrer">Kubernetes: Evenly Distribution of Pods Across Cluster Nodes</a>.</p>
  <p>The <code>.spec.teplate.spec</code> would look something like:</p>
  <pre><code>    spec:
        topologySpreadConstraints:
          - maxSkew: 1
            topologyKey: kubernetes.io/hostname
            whenUnsatisfiable: ScheduleAnyway
            labelSelector:
              matchLabels:
                type: dummy    
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2022-03-29T12:09:15.263Z
Answers: 2022-03-29T12:09:15.263Z
Answers: David Lukac
Body: <p>I need to set my deployment to have at least one pod on each node so that the system will continue uninterrupted in case the node goes down. I can set this to run one pod per node with daemonset or podAntiAffinity. But what I really want is that there is at least one pod in each node and all pods can be scheduled if there are more replicas than the number of nodes.</p>
  <p>How can I do that?
  Thank you for your answers</p>
  
Tags: <kubernetes><deployment><high-availability>
Title: How can I set up Deployment to run at least one pod on each node?
UserDisplayName: Enes Uysal
ThreadText: # How can I set up Deployment to run at least one pod on each node?
  
  (Asked by: username_0 on 2022-03-29)
  
  I need to set my deployment to have at least one pod on each node so that the system will continue uninterrupted in case the node goes down. I can set this to run one pod per node with daemonset or podAntiAffinity. But what I really want is that there is at least one pod in each node and all pods can be scheduled if there are more replicas than the number of nodes.
  
  How can I do that?
  Thank you for your answers
  
  **Tags:** kubernetes, deployment, high-availability
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-03-29. Score: 2 | Accepted answer
  
  You can use `topologySpreadConstaints` for spreading Deployment pods evenly across nodes, regardless of the number of pods. Kubernetes documentation contains [multiple examples](https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/), as well as following article - [Kubernetes: Evenly Distribution of Pods Across Cluster Nodes](https://medium.com/geekculture/kubernetes-distributing-pods-evenly-across-cluster-c6bdc9b49699#:%7E:text=In%20order%20to%20distribute%20pods,in%20its%20own%20topology%20domain.).
  
  The `.spec.teplate.spec` would look something like:
  
  ```
      spec:
        topologySpreadConstraints:
          - maxSkew: 1
            topologyKey: kubernetes.io/hostname
            whenUnsatisfiable: ScheduleAnyway
            labelSelector:
              matchLabels:
                type: dummy    
  
  ```
  
  
  ---
  
  