kubernetes问题上的Spring Boot access ElasticSearch问题
如果ElasticSearch安装在本地,那么Spring Boot应用程序可以通过spring.data.elasticsearch.cluster-nodes=localhost:9300访问它
但是当它们都安装在K8s上时,SpringBoot就无法再访问它了
spring boot的部署yaml如下所示
apiVersion: apps/v1
kind: Deployment
metadata:
name: springbootelastic
spec:
selector:
matchLabels:
run: springbootelastic
replicas: 1
template:
metadata:
labels:
run: springbootelastic
spec:
containers:
- name: springbootelastic
image: wangyan100/springbootelastic:latest
imagePullPolicy: Always
env:
- name: CLUSTER_NODES
value: elasticsearch:9300
- name: CLUSTER_HOST
value: elasticsearch
#imagePullSecrets:
# - name: regcred
所有yaml文件和代码都可以在https://github.com/wangyan100/springbootexamples/tree/master/spring-boot-elasticsearch/src上找到。
我在spring boot的pod日志中得到的异常如下所示
:添加传输节点: 10.108.175.123:9300不是群集群集elasticsearch的一部分,忽略...
:无法加载elasticsearch节点: org.elasticsearch.client.transport.NoNodeAvailableException:配置的节点均不可用:{#transport#-1}{RwIDGzHOQFqU1Lrl0yULkQ}{elasticsearch}{10.108.175.123:9300}
elasticsearch在pod上运行,我可以通过http://192.168.99.113:31183浏览它(31183是节点端口)
{
"name" : "c97xU38",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "3FQq0XXeQjuzDRqXO2wY6w",
"version" : {
"number" : "6.4.3",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "fe40335",
"build_date" : "2018-10-30T23:17:19.084789Z",
"build_snapshot" : false,
"lucene_version" : "7.4.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
https://stackoverflow.com/questions/56569276
复制相似问题