【发布时间】:2020-04-17 17:14:20
【问题描述】:
我可以像这样使用谷歌云的 kubernetes API:
import os
import time
import json
from pprint import pprint
from google.oauth2 import service_account
import googleapiclient.discovery
from six.moves import input
# https://developers.google.com/identity/protocols/oauth2/scopes
scopes = [
'https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/compute'
]
credentials = service_account.Credentials.from_service_account_file(
'service_account.json',
scopes = scopes
)
container = googleapiclient.discovery.build('container', 'v1', credentials = credentials)
loc = container.projects().locations()
client = loc.getServerConfig(name="projects/MY_PROJECT/locations/europe-west1-b")
client.execute()
但是,我想实现相当于
gcloud container clusters get-credentials MY_CLUSTER --zone=europe-west1-b --project MY_PROJECT
即获取完整的 kubernetes config+autorization 文件(然后我可以将其与 kubernetes python 模块一起使用)
查看 API 时
https://cloud.google.com/kubernetes-engine/docs/reference/rest
似乎缺少 get-credentials 调用?还是我使用了错误的 API?
【问题讨论】:
标签: kubernetes google-kubernetes-engine