Kafka Running in Zookeeper mode...port is deprecated. Please use KAFKA_ADVERTISED_LISTENERS instead.

2025. 2. 26. 23:16k8s/Kafka

참조: https://blog.palark.com/recent-troubleshooting-cases-from-our-sres-part-2/

 

Recent troubleshooting cases from our SREs, part 2

Our stories include a poorly prepared Kafka in Docker, an unexpected network issue for ZooKeeper & ClickHouse, a faulty hardware in the data center, and the PgSQL database optimization.

blog.palark.com

 

It appears you're encountering issues deploying Kafka within a Kubernetes environment, specifically related to service naming conflicts and environment variable handling. The error message port is deprecated. Please use KAFKA_ADVERTISED_LISTENERS instead. suggests that the KAFKA_PORT environment variable is being set, which Kafka no longer supports.

Understanding the Issue:

Kubernetes automatically injects environment variables into pods based on service names. For instance, if you have a service named kafka, Kubernetes will add variables like KAFKA_PORT, KAFKA_PORT_9092_TCP, etc., into the pod's environment. These variables can inadvertently interfere with Kafka's internal configurations, leading to errors during startup.

Solution:

To prevent this conflict, it's advisable to avoid naming your Kubernetes service kafka. Instead, choose a different name that doesn't clash with Kafka's internal environment variables. For example, renaming the service to kafka-service will result in environment variables like KAFKA_SERVICE_PORT, which are less likely to cause conflicts

샘플

Service

apiVersion: v1
kind: Service
metadata:
  name: kafka-service
  namespace: kafka
spec:
  # service specifications

 

StatefulSet

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: kafka
  namespace: kafka
spec:
  serviceName: kafka-service
  replicas: 3
  selector:
    matchLabels:
      app: kafka
  template:
    metadata:
      labels:
        app: kafka
    spec:
      # pod specifications