EKS
Kubernetes
AWS
Cluster Management
DevOps

Two clusters on EKS, how to switch between them

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Switching between two Amazon EKS clusters is usually a kubectl context problem, not a Kubernetes problem. The normal workflow is to write both clusters into your kubeconfig with aws eks update-kubeconfig, inspect the available contexts, and then use kubectl config use-context to switch the active one.

Put Both Clusters into Your Kubeconfig

kubectl does not talk to EKS directly. It reads context, cluster, and user information from your kubeconfig file, typically at ~/.kube/config.

For EKS, the usual command to add a cluster entry is:

bash
aws eks update-kubeconfig --region us-east-1 --name cluster-a
aws eks update-kubeconfig --region us-east-1 --name cluster-b

After running both commands, your kubeconfig contains entries for both clusters. If you want cleaner names, use aliases:

bash
aws eks update-kubeconfig --region us-east-1 --name cluster-a --alias dev-a
aws eks update-kubeconfig --region us-east-1 --name cluster-b --alias prod-b

Aliases are useful because raw EKS context names can be long and easy to confuse.

Inspect and Switch Contexts

Once both contexts exist, list them:

bash
kubectl config get-contexts

Switch to the cluster you want:

bash
kubectl config use-context dev-a

Then verify:

bash
kubectl config current-context
kubectl get nodes

That is the core answer. You are not "logging out" of one cluster and "logging into" another. You are selecting which context kubectl should use for the next commands.

Handle Multiple AWS Accounts or Profiles Carefully

If the two EKS clusters live in different AWS accounts, use explicit AWS CLI profiles when you populate the kubeconfig:

bash
1aws eks update-kubeconfig \
2  --region us-east-1 \
3  --name cluster-a \
4  --alias team-a \
5  --profile account-a
6
7aws eks update-kubeconfig \
8  --region us-east-1 \
9  --name cluster-b \
10  --alias team-b \
11  --profile account-b

This matters because the generated kubeconfig entry includes how kubectl will obtain authentication tokens later. If you accidentally build both contexts from the same wrong profile, switching contexts may appear to work while authentication fails at runtime.

When working across accounts, it is a good habit to verify both the current context and the current AWS identity before making changes:

bash
kubectl config current-context
aws sts get-caller-identity --profile account-a

That extra check is cheap insurance against deploying to the wrong cluster.

Use Separate Kubeconfig Files If Needed

For some teams, one combined ~/.kube/config file is convenient. For others, keeping cluster configs separate reduces risk.

Example:

bash
1aws eks update-kubeconfig \
2  --region us-east-1 \
3  --name cluster-a \
4  --kubeconfig ~/.kube/cluster-a.yaml
5
6aws eks update-kubeconfig \
7  --region us-east-1 \
8  --name cluster-b \
9  --kubeconfig ~/.kube/cluster-b.yaml

Then choose one when running commands:

bash
KUBECONFIG=~/.kube/cluster-a.yaml kubectl get pods
KUBECONFIG=~/.kube/cluster-b.yaml kubectl get pods

This is especially useful in automation or when production access should be kept more isolated from day-to-day development contexts.

Common Pitfalls

The biggest mistake is assuming that AWS profile switching alone changes the active Kubernetes cluster. It does not. kubectl uses its current context, which is stored in kubeconfig.

Another issue is letting the default context remain ambiguous. If both clusters have long autogenerated names, it becomes much easier to run commands against the wrong environment. Use aliases.

Developers also sometimes update kubeconfig repeatedly and assume the file is being replaced cleanly. In reality, contexts accumulate, so it is worth checking kubectl config get-contexts regularly.

Finally, always verify the active context before destructive commands such as apply, delete, or rollout restart. The wrong context is one of the most common causes of human error in multi-cluster work.

Summary

  • Add each EKS cluster to kubeconfig with aws eks update-kubeconfig.
  • Switch between them with kubectl config use-context.
  • Use aliases to make context names short and recognizable.
  • If clusters are in different AWS accounts, generate the kubeconfig entries with the correct AWS profiles.
  • Before important commands, confirm both the current context and the target environment.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.