Ideas to configure the application.server param dynamically for Kafka Streams remote interactive queries on a spring boot app running on Kubernetes

8/23/2018

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

The point is I want to run an interactive query that could be remote so I have set it up according to the documentation

The web layer is provided by a spring boot application running on port 8080.

My question is how to configure dynamically the application.server param with a unique endpoint per pod.

UPDATE:

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

gt;kubectl
get ep NAME ENDPOINTS AGE myapp 10.8.2.85:8080,10.8.2.88:8080 10d
  • Pod1 -> application.server\= 10.8.2.85:8080
  • Pod2 -> application.server\= 10.8.2.88:8080

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

MYAPP_SERVICE_PORT=8080
MYAPP_SERVICE_HOST=10.11.248.5
...

So how can I get the kubernetes endpoint of the pod?

-- codependent
apache-kafka
apache-kafka-streams
kubernetes

1 Answer

8/23/2018

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

kubernetes deployment:

spec:
  ...
  template:
    spec:
      containers:
        - env:
          - name: POD_IP
            valueFrom:
              fieldRef:
                fieldPath: status.podIP
          ...

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

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"));
-- codependent
Source: StackOverflow