【发布时间】:2019-03-24 05:58:41
【问题描述】:
我正在使用 Kubernetes Python 客户端来管理我的本地 Kubernetes 集群:
from kubernetes import client, config
config = client.Configuration()
config.host = "http://local_master_node:8080"
client.Configuration.set_default(config)
print(client.CoreV1Api().v1.list_node())
一切正常,直到我需要使用拥有 Google 项目的客户提供的密钥文件连接到 Google Cloud Kubernetes Engine 上的项目,例如:
{
"type": "...",
"project_id": "...",
"private_key_id": "...",
"private_key": "...",
"client_email": "...",
"client_id": "...",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/..."
}
我正在尝试加载它(可能以错误的方式进行):
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = os.path.abspath('credentials.json')
config.load_incluster_config()
但是这段代码引发了异常kubernetes.config.config_exception.ConfigException: Service host/port is not set.
问题是:
- 如何正确地为 Kubernetes Python 客户端提供 Google 凭据?
- 如果我在正确的轨道上,那么我在哪里可以找到与 Google Cloud 一起使用的主机/端口?
一些 sn-ps 将不胜感激。
【问题讨论】:
标签: python authentication kubernetes google-cloud-platform google-kubernetes-engine