客观的
我想从正在运行的 pod 内连接并调用 Kubernetes REST API,所讨论的 Kubernetes 是使用 IAM 身份验证的 AWS EKS 集群。所有这些都使用 Kubernetes Python 库。
我试过的
从我的内部python file
:
from kubernetes import client, config
config.load_incluster_config()
v1 = client.CoreV1Api()
ret = v1.list_pod_for_all_namespaces(watch=False)
上面的命令会抛出一个403
错误,我相信这是由于 AWS EKS 使用了不同的身份验证机制。
我已经知道的工作
ApiToken = 'eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.xxx.yyy'
configuration = client.Configuration()
configuration.host = 'https://abc.sk1.us-east-1.eks.amazonaws.com'
configuration.verify_ssl = False
configuration.debug = True
configuration.api_key = {"authorization": "Bearer " + ApiToken}
client.Configuration.set_default(configuration)
虽然上述方法有效,但我必须对我通过 kubectl 在本地生成的令牌进行硬编码,并将其签入存在安全风险的代码中。
有没有更合适的方法来使用 AWS EKS 对 Kubernetes python 库进行身份验证?