【问题标题】:Accessing firestore data within GKE from another region从另一个区域访问 GKE 中的 Firestore 数据
【发布时间】:2020-08-09 16:40:06
【问题描述】:

我希望有人可以回答或分享一些灯,

我目前正在尝试从 GKE 访问 firestore 数据,但是由于 firestore 只有几个区域,所以它目前与我们的集群位于不同的区域。

  • GKE: asia-east1
  • Firestore:aisa-east2

这是我正在使用的示例代码:

import (
    "cloud.google.com/go/firestore"
    "context"
    "golang.org/x/oauth2/google"
    "google.golang.org/api/option"
)

func main() {
    ctx := context.Background()
    cred, err := google.FindDefaultCredentials(ctx, "https://www.googleapis.com/auth/datastore")
    if err != nil {
        log.Error(err, "failed to get cred")
    }

    client, err = firestore.NewClient(ctx, PROJECT_ID, option.WithCredentials(cred))
    if err != nil {
        log.Error(err, "Failed to connect firestore: %s")
        return nil, err
    }
    // I can retrieve data for docs with local environment, but in GKE it's always empty
    docs := client.Collection(COLLECT_NAME).Doc(id).Get(ctx)
    ...
}    

我可以使用本地环境检索docs 的数据,但在 GKE 中它始终为空。我怀疑这是由于该地区,因为如果有任何权限问题,我可以看到错误消息。 有没有办法强制为客户设置区域?我无论如何都找不到设置区域,或者有什么解决方法吗?

注意 kubernetes 权限已经为 Cloud Datastore 以及节点池启用。 我还尝试设置GOOGLE_APPLICATION_CREDENTIALS 并将其安装到容器中,但仍然没有运气。

非常感谢任何提示/帮助。

谢谢!!

【问题讨论】:

    标签: google-cloud-platform google-cloud-firestore google-cloud-datastore google-kubernetes-engine


    【解决方案1】:

    已解决...我们的应用程序存在多个错误和数据问题,现在可以正常工作了。

    对于任何可能怀疑firestore的区域问题的人(因为一旦设置就无法更改,并且它只有一个区域等),仍然可以从其他区域访问firestore数据。

    我调试的步骤:

    1. 使用 VPC 原生创建一个新的 GKE 集群,因为有人提到了 VPC,但没有运气。
    2. 在GKE同区创建一个vm,发现脚本可以获取数据!正确
    3. 更新我使用的库 [但这可能无关紧要]
    4. 检查了我们使用的数据,发现一个数据点意外包含 null 导致我们的脚本返回 null。
    5. 修复了数据,程序开始工作(耶!)

    所以这里学到的教训是仔细检查数据,因为 firestore 可以有空值,所以不要指望它总是返回值。

    【讨论】:

      猜你喜欢
      • 2018-11-20
      • 1970-01-01
      • 1970-01-01
      • 2020-04-22
      • 2013-07-04
      • 1970-01-01
      • 1970-01-01
      • 2019-07-31
      • 1970-01-01
      相关资源
      最近更新 更多