tokeks
A zero-dependency Python library for getting the Kubernetes token of a AWS EKS cluster.
No AWS CLI, third-party client or library (boto3, botocore, etc.) required.
Installation
pip install tokeks
Usage prerequisites
Assign your credentials to environment variables:
export AWS_ACCESS_KEY_ID="..."
export AWS_SECRET_ACCESS_KEY="..."
Library usage
from tokeks import Tokeks
tokeks = Tokeks(
access_key_id=os.environ['AWS_ACCESS_KEY_ID'],
secret_access_key=os.environ['AWS_SECRET_ACCESS_KEY'],
region_id='YOUR_REGION_ID',
cluster_id='YOUR_CLUSTER_ID')
token = tokeks.get_token()
CLI usage
-
Go to project directory
-
Run script:
TOKEN=$(./getekstoken us-west-1 cluster-1)
- Verify Kubernetes API access:
APISERVER=...
curl -X GET $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
If the response is something like:
{
"kind": "APIVersions",
"versions": [
"v1"
],
"serverAddressByClientCIDRs": [
{
"clientCIDR": "0.0.0.0/0",
"serverAddress": "..."
}
]
}
(and does not contain "Unauthorized"), you're good to go!