使用存储API从Kubernetes部署的Google云存储桶连接
我们在Kubernetes集群部署中运行了一个java应用程序。我们使用谷歌云存储桶作为存储。我们使用Java Files.move方法将文件从持久卷声明(PVC)移动到存储桶:使用存储API从Kubernetes部署的Google云存储桶连接,kubernetes,google-cloud-storage,google-kubernetes-engine,Kubernetes,Google Cloud Storage,Google Kubernetes Engine,我们在Kubernetes集群部署中运行了一个java应用程序。我们使用谷歌云存储桶作为存储。我们使用Java Files.move方法将文件从持久卷声明(PVC)移动到存储桶: import java.nio.file.Files; Files.move(source, target, StandardCopyOption.REPLACE_EXISTING) 但是我们的写性能很差。所以我们尝试将文件从PVC移动到桶中 try { log.info("before getServic
import java.nio.file.Files;
Files.move(source, target, StandardCopyOption.REPLACE_EXISTING)
但是我们的写性能很差。所以我们尝试将文件从PVC移动到桶中
try {
log.info("before getService");
Storage storage = StorageOptions.newBuilder()
.setCredentials(GoogleCredentials.create(aToken)).build()
.getService();
// aToken is the access token of the service account
log.info("after getService");
} catch (Exception e) {
log.error("Error while creating storage object - ", e);
}
但只有“getService之前”才会被记录。之后什么也没发生。没有抛出异常。进程被困在getService()中
同一个应用程序适用于使用Google Storage Bucket的本地部署,但不适用于Kubernetes部署。对我来说,更新Google Storage API版本解决了这个问题。在我的Gradle构建文件中,我使用的是1.36,在切换到1.42后,它运行良好。问题是由于pom.xml中的api版本号(我们使用的是Maven)。在pom.xml中更改为1.23.0版解决了这个问题
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-jetty</artifactId>
<version>1.23.0</version>
</dependency>
com.google.api-client
谷歌api客户端
1.23.0
com.google.http-client
谷歌http客户端
1.23.0
com.google.oauth-client
谷歌oauth客户端jetty
1.23.0