【发布时间】:2019-02-02 21:24:34
【问题描述】:
我希望能够从用 python 编写的 Google Cloud 函数访问和管理 GKE (kubernetes) 集群。 我设法从创建的集群中访问和检索数据(至少是端点、用户名和密码),但是我不知道如何将它们与 kubernetes 包 api 一起使用。
这是我的导入:
import google.cloud.container_v1 as container
from google.auth import compute_engine
from google.cloud.container_v1 import ClusterManagerClient
from kubernetes import client, config
这是集群数据的代码:
project_id = 'my-gcp-project'
zone = 'my-zone'
cluster_id = 'my-existing-cluster'
credentials = compute_engine.Credentials()
gclient: ClusterManagerClient = container.ClusterManagerClient(credentials=credentials)
cluster = gclient.get_cluster(project_id,zone,cluster_id)
cluster_endpoint = cluster.endpoint
print("*** CLUSTER ENDPOINT ***")
print(cluster_endpoint)
cluster_master_auth = cluster.master_auth
print("*** CLUSTER MASTER USERNAME PWD ***")
cluster_username = cluster_master_auth.username
cluster_password = cluster_master_auth.password
print("USERNAME : %s - PASSWORD : %s" % (cluster_username, cluster_password))
在那之后我想做这样的事情:
config.load_kube_config()
v1 = client.CoreV1Api()
print("Listing pods with their IPs:")
ret = v1.list_pod_for_all_namespaces(watch=False)
for i in ret.items:
print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))
但是,我不知道如何设置我的端点和身份验证信息。 谁能帮帮我?
【问题讨论】:
标签: python-3.x kubernetes google-cloud-platform google-cloud-functions google-kubernetes-engine