我的 GKE Autopilot 集群中的一些 pod 无法获取应用程序默认凭据来调用其他 GCP 服务。
我将应用一个新部署,3 个 pod 中的 1 个或 2 个将无法使用 googleapis (google-auth-library) npm 包进行身份验证(尝试使用版本 v73.0.0 和最新的 v84.0.0)。
我得到:
Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information. at GoogleAuth.getApplicationDefaultAsync (/node_modules/google-auth-library/build/src/auth/googleauth.js:173:19)
我正在使用此代码并重试失败:
const {google} = require('googleapis');
const setGoogleAuth = async () => {
try {
const auth = new google.auth.GoogleAuth({
// Scopes can be specified either as an array or as a single, space-delimited string.
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
});
// Acquire an auth client, and bind it to all future calls
const authClient = await auth.getClient();
google.options({auth: authClient});
} catch (e) {
console.error(e)
//retry
//sleep for 3 seconds
await sleep(3000)
await setGoogleAuth()
}
}
通过手动调用元数据服务器curl http://metadata/computeMetadata/v1/instance/service-accounts/default/identity?audience=<my-gcp-endpoint>
从 pod 中返回一个有效令牌,该令牌无法通过 googleapis 包进行身份验证
有时会杀死 pod 并让它们重新创建工作(使用 Horizontal Pod Autoscaler)。其他时候,我的部署没有问题。有时,杀死豆荚以便它们重新创建根本没有帮助。这种行为似乎非常不确定。
任何帮助将不胜感激,谢谢!