My *_*URU 2 authentication google-cloud-platform gcloud google-kubernetes-engine kubectl
我运行以下命令
gcloud auth login --no-launch-browser ## I use corporate email id to authenticate
gcloud container clusters get-credentials <>gke_cluster_name> --region <region> --project <gcp_project>
export https_proxy=<kube_api_proxy>:8118 ## Proxy to connect to k8s controlplane
kubectl get no
Run Code Online (Sandbox Code Playgroud)
每隔 1 小时,我必须重复上述步骤来重新进行身份验证,因为我会失败并出现以下错误,否则当我尝试连接到 k8S 时
Unable to connect to the server: error executing access token command "/usr/lib64/google-cloud-sdk/bin/gcloud
config config-helper --format=json": err=exit status 1 output= stderr=ERROR: gcloud crashed (TransportError):
HTTPSConnectionPool(host='oauth2.googleapis.com', port=443): Max retries exceeded with url: /token
(Caused by ProxyError('Cannot connect to proxy.',
OSError('Tunnel connection failed: 403 Request blocked by Privoxy')))
Run Code Online (Sandbox Code Playgroud)
有没有办法可以增加这个超时时间,比如说 4 小时左右,因为我有一个运行时间超过 1 小时的作业,并且由于超时而在中间失败。
CLI gcloud创建有效期为 3,600 秒的 OAuth 访问令牌。这是非组织项目支持的最大生命周期。这也是您正在使用的用户身份的最长生命周期。
要延长组织的令牌生命周期,您必须从服务帐户创建凭据并设置组织策略约束constraints/iam.allowServiceAccountCredentialLifetimeExtension,该扩展支持生命周期为 12 小时的令牌。关联
但是,我不知道在 CLI 中使用该约束而不修改 CLI 源代码的方法,它是用 Python 编写的。我从未进行过此更改,因为编写自己的代码要容易得多。
相反,编写您自己的令牌生成器。互联网上有很多源代码示例。我写了一篇文章,其中包含源代码链接。将我的代码中的这一行更改为所需的时间:
# Set how long this token will be valid in seconds
expires_in = 3600 # Expires in 1 hour
Run Code Online (Sandbox Code Playgroud)
总之:
| 归档时间: |
|
| 查看次数: |
2203 次 |
| 最近记录: |