# Java RestClient multi host configuration to access ES on Kubernetes

**URL:** https://discuss.elastic.co/t/java-restclient-multi-host-configuration-to-access-es-on-kubernetes/324870
**Category:** Elastic Cloud on Kubernetes (ECK)
**Created:** [February 7, 2023, 8:39am UTC](https://discuss.elastic.co/t/java-restclient-multi-host-configuration-to-access-es-on-kubernetes/324870 "2023-02-07T08:39:21Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![franck.valentin](https://avatars.discourse-cdn.com/v4/letter/f/d2c977/32.png) [@franck.valentin](https://discuss.elastic.co/u/franck.valentin)
#### Post date: [February 7, 2023, 8:39am UTC](https://discuss.elastic.co/t/java-restclient-multi-host-configuration-to-access-es-on-kubernetes/324870/1 "2023-02-07T08:39:21Z")

</div>

Hi,

I try to figure out how to configure a Java RESTClient to access ES 7.17 deployed on Kubernetes, more precisely how to [set several hosts]([Initialization | Elasticsearch Java API Client [7.17] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/7.17/java-rest-low-usage-initialization.html#java-rest-low-usage-initialization) and take advantage of the [retry mechanism implemented in the RestClient]([RestClient - elasticsearch-rest-client 7.17.9 javadoc](https://javadoc.io/doc/org.elasticsearch.client/elasticsearch-rest-client/7.17.9/org/elasticsearch/client/RestClient.html#performRequest(org.elasticsearch.client.Request)).

But how to set the hosts when ES is deployed on Kubernetes and queried via services?  
E.g.  
Services:

```auto
eck-es-data ClusterIP None <none> 9200/TCP 
eck-es-discovery-1 ClusterIP None <none> 9300/TCP
eck-es-http ClusterIP 10.100.26.250 <none> 9200/TCP
eck-es-master ClusterIP None <none> 9200/TCP
eck-es-transport ClusterIP None <none> 9300/TCP

```

Statefulsets:

```auto
eck-es-data 
eck-es-master

```

Pods:

```auto
eck-es-data-0
eck-es-data-1
eck-es-data-2
eck-es-master-0
eck-es-master-1
eck-es-master-2

```

Using the service eck-es-http:9200 should be incorrect as the client would see it as a single host.  
Could adding each of the pods eck-es-data-0/1/2 lead to unexpected behavior if the ES is scaled or if they are restarted?  
Could the headless service eck-es-data be used to get all the data node addresses?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [March 7, 2023, 8:40am UTC](https://discuss.elastic.co/t/java-restclient-multi-host-configuration-to-access-es-on-kubernetes/324870/2 "2023-03-07T08:40:06Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
