我有一个由后端(spring引导)和搜索引擎(elasticsearch)组成的应用程序。在我将它部署到OCP中之后,最初我使用命令"curl“从后端pod到elasticsearch服务(https://service-name.namespace.svc.cluster.local:9200)测试了两者之间的连接,并且它工作了。这张照片是:

但是,当我试图从部署的后端应用程序中访问elasticsearch时,会出现如下错误消息:

下面是我在Spring中的配置,用于连接我所做的Elasticsearch:
package com.siolbca.config;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
@Configuration
@EnableElasticsearchRepositories(basePackages = "com.siolbca.repository")
@ComponentScan(basePackages = "com.siolbca.services")
public class Config {
@Bean
public RestHighLevelClient client() {
ClientConfiguration clientConfiguration
= ClientConfiguration.builder()
.connectedTo("https://elasticsearch-siol-es-http.siolbca-dev.svc.cluster.local:9200")
.usingSsl()
.withBasicAuth("elastic","G0D1g6TurJ79pcxr1065pU0U")
.build();
return RestClients.create(clientConfiguration).rest();
}
@Bean
public ElasticsearchOperations elasticsearchTemplate() {
return new ElasticsearchRestTemplate(client());
}
}我所做的一些事情是:
中使用elasticsearch服务IP地址
configuration
有人知道为什么我的后端应用程序不能与elasticsearch服务通信,即使这两个吊舱可以连接?任何回答都会很有帮助。谢谢。
编辑
这是我的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.siolbca</groupId>
<artifactId>siolbca</artifactId>
<version>1.0</version>
<name>siolbca</name>
<description>Backend project for SIOLBCA</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>发布于 2021-05-08 18:09:12
我认为elasticsearch .connectedTo方法需要格式host:port,即没有协议。所以试着:
.connectedTo("elasticsearch-siol-es-http.siolbca-dev.svc.cluster.local:9200")https://stackoverflow.com/questions/67446024
复制相似问题