Shell function for managing multiple AWS EKS Kubernetes contexts in separate terminal windows. Each terminal gets its own KUBECONFIG file, so switching contexts in one window never interferes with another.
- AWS CLI with profiles configured (see AWS Profiles below)
- yq - YAML processor
- fzf - fuzzy finder for interactive context selection
kubectl
-
Create the config directory:
mkdir -p ~/.config/kubert -
Copy the shell function and example config:
cp src/kubert.bash ~/.config/kubert/ cp config/example.kubert.yaml ~/.config/kubert/kubert.yaml
-
Edit
~/.config/kubert/kubert.yamlwith your clusters and AWS profiles. -
Source
kubert.bashin your shell profile (~/.zshrcor~/.bashrc):source ~/.config/kubert/kubert.bash
-
Restart your shell or
sourceyour profile.
Edit ~/.config/kubert/kubert.yaml:
defaults:
region: us-east-1
contexts:
dev:
cluster: my-dev-cluster
aws_profile: dev-admin
prod:
cluster: my-prod-cluster
region: us-east-2
aws_profile: prod-adminEach context requires:
cluster- the EKS cluster nameaws_profile- an AWS CLI profile name from~/.aws/config
Optional:
region- overrides the default region for this context
The config file path defaults to ~/.config/kubert/kubert.yaml. Override it by setting KUBERT_CONFIG_FILE before sourcing kubert.bash.
Kubert depends on having AWS CLI profiles already configured in ~/.aws/config. Each aws_profile value in your kubert config must correspond to a working profile. Kubert does not handle AWS authentication itself — it passes the profile to aws eks update-kubeconfig.
Example using AWS SSO:
[sso-session my-org]
sso_start_url = https://my-org.awsapps.com/start
sso_region = us-east-1
[profile dev-admin]
sso_session = my-org
sso_account_id = 123456789012
sso_role_name = AdministratorAccess
region = us-east-1
[profile prod-admin]
sso_session = my-org
sso_account_id = 987654321098
sso_role_name = AdministratorAccess
region = us-east-1Example using IAM role assumption:
[profile identity]
region = us-east-1
[profile dev-admin]
source_profile = identity
role_arn = arn:aws:iam::123456789012:role/dev-admin
region = us-east-1Switch to a context:
kubert devThis sets KUBECONFIG to ~/.kube/dev.config.yaml, then runs aws eks update-kubeconfig with the cluster, region, and profile from your config.
Run without arguments for interactive selection via fzf:
kubert# Terminal 1
kubert dev
kubectl get pods # dev cluster
# Terminal 2
kubert prod
kubectl get pods # prod clusterEach terminal maintains its own isolated context.
See LICENSE.