Is there a way to enforce running init code on TM?...
# troubleshooting
a
Is there a way to enforce running init code on TM? We are bit behind with Flink 1.15 (planning to upgrade in some future). Wanted to add rack-awareness for
KafkaSource
operators. Created small supplier that checks ec2 metadata and pulls AZ id. But based on logs it only runs on JobManager. We don't have a way to enforce single az deployment (yet).
t
Hey Aviv, would not it be easier to fetch such information during deployment and inject the value as ENV to TM?
a
Hey @Tamir Sagi it's not about how to get this value, it's about executing this call. Whether fetching via env var or via ec2 metadata the actual init happens only on JM (so far) and when the instance of
KafkaSource
starts on TM it already has resolved values.
t
TM is created by JM when deploying in Native k8s, hence the only way to impact TM pod (i.e adding init container to its lifecycle, modify topology constrains etc) is to use pod template. otherwise you can create a dedicated deployment for TM.
a
Wait, I do use pod template (to add annotations, labels, startup probe, nodeSelectors and etc). But how would it trigger the initialization of kafkaSource operator on TM ?
t
AFAIK, You cannot control how Kafka source is initialized on TM. it is defined in JM and then during TM initialization Kafka consumer is created(wrapped by reader) using the given properties. Kafka connector 1.15 does not seem to support rack awareness out of the box, you can try adding its property
ConsumerConfig.CLIENT_RACK_CONFIG
to Kafka Source properties but I'm not sure it will even work properly(it will not know which zone the TM is running on). (The support has has been added in Kafka-connector 3.1.0) [1] I mentioned pod template as an option to play with TM topology constrains and node affinity. If you intend to restrict to single AZ You can try to restrict TMs to be deployed on specific AZ (Not good for failover and HA) using Node Affinity + condition[2] Assuming you know the AZ ID:
Copy code
affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: topology.kubernetes.io/zone
            operator: In
            values:
            - zone id
[1] https://cwiki.apache.org/confluence/display/FLINK/FLIP-268%3A+Kafka+Rack+Awareness [2] https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity
a
yep, it work properly as the value is ignored by split enumerator.
the only way it will work properly is to deploy to a single az
which can make sense, as we have some significant amount of rebalancing