Objective
I want to connect to and call Kubernetes REST APIs from inside a running pod, the Kubernetes in question is an AWS EKS cluster using IAM authentication. All of this using Kubernetes Python lib.
What I have tried
From inside my python file:
from kubernetes import client, config
config.load_incluster_config()
v1 = client.CoreV1Api()
ret = v1.list_pod_for_all_namespaces(watch=False)
The above command throws a 403 error, This I believe is due to the different auth mechanism that AWS EKS uses.
What I already know works
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)
While the above works, I have to hardcode a token that I generate locally via kubectl and check it into the code which is a security risk.
Is there a more proper way to authenticate the Kubernetes python lib with AWS EKS?