How can I set up Deployment to run at least one pod on each node?



  • 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



  • You can use topologySpreadConstaints for spreading Deployment pods evenly across nodes, regardless of the number of pods. Kubernetes documentation contains https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/ , as well as following article - 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    
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2