max.request.size Kafka in Kubernetes

10/5/2018

I'm trying to give max.request.size to Kafka in kubernetes, it seems doesn't work. How to do that?

I tried also with KAFKA_MAX_REQUEST_SIZE again no positive result:

  spec:
  containers:
  - name: kafka
    image: wurstmeister/kafka
    ...

    env:
    - name: KAFKA_ZOOKEEPER_CONNECT
      value: "zookeeper:2181"
    - name: KAFKA_ADVERTISED_PORT
      value: "9092"
    - name: KAFKA_DELETE_TOPIC_ENABLE
      value: "true"
    - name: KAFKA_CREATE_TOPICS
      value: "tpinput:1:1,tpoutput:1:1,operinput:1:1,operoutput:1:1,authoutput:1:1"  
    - name: KAFKA_JMX_PORT
      value: "7071"             
    - name: KAFKA_ZOOKEEPER_TIMEOUT_MS
      value: "16000"
    - name: KAFKA_MESSAGE_MAX_BYTES
      value: "209715200"
    - name: KAFKA_FETCH_MESSAGE_MAX_BYTES
      value: "209715200"  
    - name: KAFKA_REPLICA_FETCH_MAX_BYTES
      value: "209715200" 
    - name: KAFKA_PRODUCER_MAX_REQUEST_SIZE
      value: "9651322321"
    - name: KAFKA_ADVERTISED_HOST_NAME
      valueFrom:
        fieldRef:
          fieldPath: status.podIP        
    - name: KUBE_POD_NAME
      valueFrom:
        fieldRef:
          fieldPath: metadata.name
    imagePullPolicy: Always
    restartPolicy: Always
    envFrom:
    - configMapRef:
        name: env-config-for-pods
-- user37033
apache-kafka
kubernetes

1 Answer

10/5/2018

Based on the Docker entrypoint script here and this part in that file:

EXCLUSIONS="|KAFKA_VERSION|KAFKA_HOME|KAFKA_DEBUG|KAFKA_GC_LOG_OPTS|KAFKA_HEAP_OPTS|KAFKA_JMX_OPTS|KAFKA_JVM_PERFORMANCE_OPTS|KAFKA_LOG|KAFKA_OPTS|"

# Read in env as a new-line separated array. This handles the case of env variables have spaces and/or carriage returns. See #313
IFS=$'\n'
for VAR in $(env)
do
    env_var=$(echo "$VAR" | cut -d= -f1)
    if [[ "$EXCLUSIONS" = *"|$env_var|"* ]]; then
        echo "Excluding $env_var from broker config"
        continue
    fi

    if [[ $env_var =~ ^KAFKA_ ]]; then
        kafka_name=$(echo "$env_var" | cut -d_ -f2- | tr '[:upper:]' '[:lower:]' | tr _ .)
        updateConfig "$kafka_name" "${!env_var}" "$KAFKA_HOME/config/server.properties"
    fi

    if [[ $env_var =~ ^LOG4J_ ]]; then
        log4j_name=$(echo "$env_var" | tr '[:upper:]' '[:lower:]' | tr _ .)
        updateConfig "$log4j_name" "${!env_var}" "$KAFKA_HOME/config/log4j.properties"
    fi
done

KAFKA_MAX_REQUEST_SIZE should be included in the $KAFKA_HOME/config/server.properties file as max.request.size. I wouldn't be surprised if there's a bug in the docker image.

You can always shell into your Kafka pod and check the $KAFKA_HOME/config/server.properties config file.

kubectl exec -it <kafka-pod> -c <kafka-container> sh
-- Rico
Source: StackOverflow