<p>I have a Spring boot application running a Kafka consumer that consumes messages from a single Topic having two partitions(partition-0 and 1). The application is deployed as a single Kubernetes pod. I have scaled the application and now it's running in two pods.  But the client Id prefix of the consumer running in both pod has the same clientIdPrefix 'client-consumer-0'.</p>
<p>How to generated clientIdPrefix unique to the pod?</p>

<p>Set kafka consumer client.id properties for change consumer client name
<a href="https://docs.confluent.io/platform/current/installation/configuration/consumer-configs.html#consumerconfigs_client.id" rel="nofollow noreferrer">https://docs.confluent.io/platform/current/installation/configuration/consumer-configs.html#consumerconfigs_client.id</a>.</p>
<p>You can give property in yml file like below.</p>
<pre><code>spring:
  kafka:
    consumer:
      properties:
        client.id: ${KAFKA_CLIENT_ID:unique-kafka-client-name}
</code></pre>
<p>for create unique value for client id you can use pod info
<a href="https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#use-pod-fields-as-values-for-environment-variables" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#use-pod-fields-as-values-for-environment-variables</a></p>
<p>i.e <strong>metadata.uid</strong></p>
<pre><code>  env:
    - name: KAFKA_CLIENT_ID
      valueFrom:
        fieldRef:
          fieldPath: metadata.uid
</code></pre>
