1

我的 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 并让它们重新创建工作(使用 Horizo​​ntal Pod Autoscaler)。其他时候,我的部署没有问题。有时,杀死豆荚以便它们重新创建根本没有帮助。这种行为似乎非常不确定。

任何帮助将不胜感激,谢谢!

4

1 回答 1

0

在环境中设置 DETECT_GCP_RETRIES=3 或 K_SERVICE=true 有效。

在此处查看完整的 GitHub 问题讨论:https ://github.com/googleapis/google-auth-library-nodejs/issues/1236

于 2021-09-12T02:22:42.303 回答