<p>I am deploying a Kafka Streams application on Kubernetes replicated as several pods. This pods are exposed as a Kubernetes service so I have a common entry point that load balances the traffic: myapp:8080</p>

<p>The point is I want to run an interactive query that could be remote so I have set it up according to the <a href="https://kafka.apache.org/10/documentation/streams/developer-guide/interactive-queries.html#querying-remote-state-stores-for-the-entire-app" rel="nofollow noreferrer">documentation</a></p>

<p>The web layer is provided by a spring boot application running on port 8080.</p>

<p>My question is how to configure dynamically the <code>application.server</code> param with a unique endpoint per pod.</p>

<p><strong>UPDATE:</strong></p>

<p>I guess what I need is to configure the <code>application.server</code> with the value of the kubernetes endpoint assigned to each pod:</p>

<pre><code>$&gt;kubectl get ep
NAME                    ENDPOINTS                       AGE
myapp   10.8.2.85:8080,10.8.2.88:8080   10d
</code></pre>

<ul>
<li>Pod1 -> <code>application.server</code>= 10.8.2.85:8080</li>
<li>Pod2 -> <code>application.server</code>= 10.8.2.88:8080</li>
</ul>

<p>However printing the <code>System.getEnv()</code> of the applications I only have the ip and port of the kubernetes service, not the assigned pod endpoint:</p>

<pre><code>MYAPP_SERVICE_PORT=8080
MYAPP_SERVICE_HOST=10.11.248.5
...
</code></pre>

<p>So how can I get the kubernetes endpoint of the pod?</p>

codependent
<p>I've been able to get the endpoint ip of each pod by adding it as an environment variable this way:</p>

<p><strong>kubernetes deployment:</strong></p>

<pre><code>spec:
  ...
  template:
    spec:
      containers:
        - env:
          - name: POD_IP
            valueFrom:
              fieldRef:
                fieldPath: status.podIP
          ...
</code></pre>

<p>Now I can access the pod ip/port and assign it to the <code>application.server</code> parameter in each instance of the application:</p>

<pre><code>private final Environment environment;

@Autowired
public SomeController(Environment environment) {
    this.environment = environment;
}

...
props.put(StreamsConfig.APPLICATION_SERVER_CONFIG, System.getEnv("POD_IP") + ":" + environment.getProperty("local.server.port"));
</code></pre>
