我一直按照 https://cloud.google.com/profiler/docs/profiling-nodejs#gke 上的说明进行操作 对我的 Nodejs 应用程序使用 gcloud profiler:
我将 RUN npm install @google-cloud/profiler
添加到我的 dockerfile 中。
我添加了
require('@google-cloud/profiler').start({
serviceContext: {
service: 'your-service',
version: '1.0.1',
},
});
到我的 app.js 文件。
然后,我在 GKE 集群上运行容器并收到以下错误:
@google-cloud/profiler Failed to create profile, waiting 8.6s to try again: Error: generic::permission_denied
根据我对文档的理解,在 gcloud 托管实例中运行代码时,我不需要显式身份验证或权限来创建配置文件。
该错误本身并不是很有帮助,而且我在这里有点超出了我的深度。
我已经尝试过使用 --(autoprovisioning-)scopes "https://www.googleapis.com/auth/cloud-platform"
创建集群是否可以解决问题,但也没有运气。
您知道这里可能存在什么问题吗?
最佳答案
文档表明您不需要凭据,这是正确的但我认为您需要凭据(并且文档不完整)。
当应用程序(例如 Profiler)使用 Google 的应用程序默认凭据并在例如Compute Engine(App Engine、Cloud Run 等)它能够获取credentials automatically来自环境(在 GCP 上使用元数据服务;由开发人员在本地使用,将 GOOGLE_APPLICATION_CREDENTIALS
导出到 key )。
在 GKE 上,我认为这不是真实的(除非 Google 在某处施展魔法),并且应用程序将无法自动访问凭据除非您在 GKE 中代表他们。我认为(!?)您需要创建一个服务帐户并且:
NOTE Workload Identity is a neat feature but it's only useful if you only ever plan to use GKE (and not some other Kubernetes implementation).
在继续之前,让我们看看其他人是否回复告诉我我错了。
我wrote关于使用当时称为 Stackdriver Profiler 的 GKE 部署的应用程序。该文章已过时,但它应该提供您需要执行的操作的概述。
关于google-kubernetes-engine - 为什么 @google-cloud/profiler 在 GKE 实例内运行时会抛出 'permission_denied' 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69852863/