如何解决当 Horizental Pod Auto Scaler 开始工作时,GKE Metadata Server 不可用
使用 WorkloadIdentity 运行 Pod 会在自动缩放启动时出现 Google 凭据错误。
我的应用程序配置了 WorkloadIdentity 以使用 Google Pub/Sub 并设置 HorizontalPodAutoscaler 以将 pod 扩展到最多 5 个副本。
当自动缩放器创建 pod 的副本时会出现问题,GKE 的元数据服务器在几秒钟内无法工作,然后在 5 到 10 秒后没有产生错误。
这是自动缩放器创建一个pod后的错误日志。
WARNING:google.auth.compute_engine._metadata:Compute Engine Metadata server unavailable onattempt 1 of 3. Reason: timed out
WARNING:google.auth.compute_engine._metadata:Compute Engine Metadata server unavailable onattempt 2 of 3. Reason: timed out
WARNING:google.auth.compute_engine._metadata:Compute Engine Metadata server unavailable onattempt 3 of 3. Reason: timed out
WARNING:google.auth._default:Authentication failed using Compute Engine authentication due to unavailable metadata server
Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information,please see https://cloud.google.com/docs/authentication/getting-started
这里到底有什么问题?
当我从这里阅读文档时 workload identity docs
"The GKE metadata server takes a few seconds to start to run on a newly created Pod"
我认为问题与此问题有关,但这种情况有解决方案吗?
谢谢
解决方法
除了确保您的应用程序能够应对这种情况外,没有特定的解决方案。 Kubernetes 使用 DaemonSets 来启动每个节点的应用程序,比如元数据拦截服务器,但正如文档清楚地告诉你的那样,这需要几秒钟(注意新节点、调度 pod、拉取镜像、启动容器)。
您可以使用 initContainer 来阻止您的应用程序在某些脚本返回之前启动,这可以尝试访问 GCP API 直到它工作为止。但这可能比在发生这些错误时重试代码更重要。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。