【问题标题】:Google Cloud Bucket connection from Kubernetes deployment using Storage API使用 Storage API 的 Kubernetes 部署的 Google Cloud Bucket 连接
【发布时间】:2018-08-03 09:52:15
【问题描述】:

我们在 Kubernetes 集群部署中运行了一个 java 应用程序。我们使用 Google Cloud Bucket 作为存储。我们使用 Java Files.move 方法将文件从 Persistent Volume Claim (PVC) 移动到存储桶:

import java.nio.file.Files;

Files.move(source, target, StandardCopyOption.REPLACE_EXISTING)

但是我们的写入性能很差。所以我们尝试探索 Google Cloud Storage API 将文件从我们的 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 部署。

【问题讨论】:

    标签: kubernetes google-cloud-storage google-kubernetes-engine


    【解决方案1】:

    对我来说,更新 Google Storage API 的版本解决了这个问题。在我的 Gradle 构建文件中,我使用的是 1.36,切换到 1.42 后,它工作正常。

    【讨论】:

      【解决方案2】:

      问题是由于 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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-10-28
        • 2020-06-13
        • 1970-01-01
        • 1970-01-01
        • 2019-12-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多