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
application.server
\= 10.8.2.85:8080application.server
\= 10.8.2.88:8080However 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?
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"));