我的GKE Autopilot集群中的一些pods无法获取应用程序默认凭据来调用其他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并让它们重建工作(使用水平Pod Autoscaler)。其他时候,我对部署没有任何问题。有时,杀死pod以使其重新创建根本没有任何帮助。这种行为看起来非常不确定。
如有任何帮助,将不胜感激,谢谢!
发布于 2021-09-12 02:22:42
在环境中设置DETECT_GCP_RETRIES=3或K_SERVICE=true起作用。
在这里查看完整的GitHub问题讨论:https://github.com/googleapis/google-auth-library-nodejs/issues/1236
https://stackoverflow.com/questions/68854640
复制相似问题