strimzi / strimzi-kafka-operator

Apache Kafka® running on Kubernetes
https://strimzi.io/
Apache License 2.0
4.79k stars 1.28k forks source link

Why the pod of kafka will restart when expanding the cluster(use the external nodeport)? #2345

Closed EresZX closed 4 years ago

EresZX commented 4 years ago

If I config the external listener and use the nodeport, the pod of kafka will restart when expanding the cluster. However, if the external listener isn't used, this will not happen.

listeners: 
      plain: {}
      tls: {}
      external:
        type: nodeport
        tls: false
        overrides:
          bootstrap:
            nodePort: 32100

I look the log of operator and find that if I config the external listener, the operator could detect the change of the replicas number and the advertised listeners. The log includes the following information: 2019-11-29 22:27:11 DEBUG StatefulSetDiff:97 - StatefulSet kafka/my-cluster-kafka differs: {"op":"replace","path":"/spec/replicas","value":3} 2019-11-29 22:27:11 DEBUG StatefulSetDiff:98 - Current StatefulSet path /spec/replicas has value 1 2019-11-29 22:27:11 DEBUG StatefulSetDiff:99 - Desired StatefulSet path /spec/replicas has value 3 2019-11-29 22:27:11 DEBUG StatefulSetDiff:97 - StatefulSet kafka/my-cluster-kafka differs: {"op":"replace","path":"/spec/template/spec/containers/0/env/7/value","value":"1://:31977 0://:31198 2://:30897"} 2019-11-29 22:27:11 DEBUG StatefulSetDiff:98 - Current StatefulSet path /spec/template/spec/containers/0/env/7/value has value "0://:31198" 2019-11-29 22:27:11 DEBUG StatefulSetDiff:99 - Desired StatefulSet path /spec/template/spec/containers/0/env/7/value has value "1://:31977 0://:31198 2://:30897" 2019-11-29 22:27:11 DEBUG StatefulSetDiff:97 - StatefulSet kafka/my-cluster-kafka differs: {"op":"replace","path":"/spec/template/spec/initContainers/0/env/2/value","value":"1://:31977 0://:31198 2://:30897"} 2019-11-29 22:27:11 DEBUG StatefulSetDiff:98 - Current StatefulSet path /spec/template/spec/initContainers/0/env/2/value has value "0://:31198" 2019-11-29 22:27:11 DEBUG StatefulSetDiff:99 - Desired StatefulSet path /spec/template/spec/initContainers/0/env/2/value has value "1://:31977 0://:31198 2://:30897"

These differences make the operator decide to update the generation and restart the pod of kafka. I want to know the design ideas of this point and how to prevent the restart of pod when expanding the kafka cluster(Now I modify the source code and ignore these differences).

scholzj commented 4 years ago

This is currently expected. The node port numbers need to be set in the individual brokers as advertised ports. And they are passed to the pods through environment variables. So when the environment variable changes a rollback of the pod happens. And when you scale up, the variable changes because new port numbers are added.

In #2342 I took the first step to change this behavior. It will still trigger rolling update, but it will pass the port numbers through configMap, so that in the future we can deal with this in better way.