What is the recommended way to deploy kafka to make it deploy in all the available nodes?

4/22/2019

I have 3 slaves nodes in k8s and i'm running kafka (3 cluster). While deploying zk/broker/rest-proxy, its not getting deployed in all the available nodes. How can i make sure that all pods are deployed in different nodes. Do i need to use nodeaffinity or podaffinity ?

-- Pooja
apache-kafka
kubernetes

2 Answers

4/22/2019

If you want all pods to run on different nodes - you must use PodAntiAffinity. If this is hard requirement - you must use requiredDuringSchedulingIgnoredDuringExecution rule. If it's not - use preferredDuringSchedulingIgnoredDuringExecution.

topologyKey should be kubernetes.io/hostname.

In labelSelector put your pod's labels.

-- Vasily Angapov
Source: StackOverflow

4/22/2019

I recommend using soft anti-affinity which will look like:

affinity:
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - podAffinityTerm:
          labelSelector:
            matchExpressions:
            - key: app
              operator: In
              values:
              - <your app label>
          topologyKey: kubernetes.io/hostname
        weight: 100

Here I explained the difference between anti-affinity types with examples applied to a live cluster: https://blog.verygoodsecurity.com/posts/kubernetes-multi-az-deployments-using-pod-anti-affinity/

-- Max Lobur
Source: StackOverflow