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.
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:
After running both commands, your kubeconfig contains entries for both clusters. If you want cleaner names, use aliases:
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:
Switch to the cluster you want:
Then verify:
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:
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:
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:
Then choose one when running commands:
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
- UDP send and receive in kubernetes
- Unable to access my minikube cluster from the browser ❗ Because you are using a Docker driver on windows, the terminal needs to be open to run it.
- Unable to access NGINX nodePort service in K8 cluster running on RPI
- Unable to configure UDP on ingress-nginx-controller
- Unable to add GSI to DynamoDB table using CloudFormation
- unable to call firefox from selenium in python on AWS machine
- Two conflicting long lived process managers
- Unable to increase file descriptors for rabbitmq

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack 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.