Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How if I interact with different kubernetes clusters in different terminals sessions with out having to switch contexts all the the time?

I am testing role differences right now so I have a context for each role setup.

Terminal session Admin, I want to be able to use context Admin in one session so I can update the rules as needed.

In terminal session User, I want to be able to test that role via its context.

(Note: I am on EKS so roles map to IAM roles)

like image 780
Josh Beauregard Avatar asked Jan 25 '23 16:01

Josh Beauregard


2 Answers

Well, I am an idiot.

Natively, there is no answer in the --help output for kubectl; however, there is output for this in the man page.

All one has to do is throw the --context flag into their command.

However, the below-mentioned kubectx tool is what I use day to day now.

like image 152
Josh Beauregard Avatar answered Apr 08 '23 02:04

Josh Beauregard


Here are some tips for managing multiple kubectl contexts:

  • Use asdf to manage multiple kubectl versions
  • Set the KUBECONFIG env var to change between multiple kubeconfig files
  • Use kube-ps1 to keep track of your current context/namespace
  • Use kubectx and kubens to change fast between clusters/namespaces
  • Use aliases to combine them all together

Take a look at this article, it explains how to accomplish this: Using different kubectl versions with multiple Kubernetes clusters (Disclaimer: I wrote the mentioned article)

I also recommend this reads: Mastering the KUBECONFIG file and Configure Access to Multiple Clusters

like image 37
Eduardo Baitello Avatar answered Apr 08 '23 04:04

Eduardo Baitello