【发布时间】: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