nats-io / nats-streaming-operator

NATS Streaming Operator
Apache License 2.0
174 stars 44 forks source link

Spread pods across nodes #15

Closed Qwerios closed 5 years ago

Qwerios commented 5 years ago

I noticed after running the operator that sometimes the streaming pods would end up on the same node. I prefer spreading pods across multiple nodes in case of a rare node failure.

This is the yaml I usually add to either my deployment or pod yamls:

affinity:
  podAntiAffinity:
    preferredDuringSchedulingIgnoredDuringExecution:
    - weight: 100
      podAffinityTerm:
        labelSelector:
          matchExpressions:
          - key: app
            operator: In
            values:
            - nats-streaming
        topologyKey: kubernetes.io/hostname

Is this something that could be of use for the operator?

wallyqs commented 5 years ago

yes, also think that would be better to recover in case of complete node failure.

wallyqs commented 5 years ago

Added a template parameter to the pod spec, so now possible to set anti affinity policy for example:

---
apiVersion: "streaming.nats.io/v1alpha1"
kind: "NatsStreamingCluster"
metadata:
  name: "example-stan-anti"
spec:
  size: 3
  natsSvc: "example-nats"

  # Define Custom Pod Spec
  template:
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: stan_cluster
                    operator: In
                    values:
                    - example-stan-anti
              topologyKey: kubernetes.io/hostname
Qwerios commented 5 years ago

Assuming this will become available with a new release. Checked the current master deployment.yaml and it is pointing to the current version I have. Will monitor this repo and its docs for when it becomes available.