As of now i do
JavaScript
x
2
1
kubectl --context <cluster context> get pod -A
2
to get pod in specific cluster
is there a python way to set kubernetes context for a virtual env , so we can use multiple context at the same time example :
JavaScript
1
6
1
Terminal 1:
2
(cluster context1) user@machine #
3
4
Terminal 2:
5
(cluster context2) user@machine #
6
This should be equivalent of
JavaScript
1
6
1
Terminal 1:
2
user@machine # kubectl --context <cluster context1> get pod -A
3
4
Terminal 2:
5
user@machine # kubectl --context <cluster context1> get pod -A
6
Advertisement
Answer
This isn’t probably a rational solution, but anyway… At some time I used different kubectl
versions for different clusters and I came up with a venv-like solution to switch between them. I wrote text files like this:
JavaScript
1
3
1
export KUBECONFIG="/path/to/kubeconfig"
2
export PATH="/path/including/the/right/kubectl"
3
And activated them in the same fashion as venv: source the_file
. If you can split your contexts to separate files, you can add export KUBECONFIG="/path/to/kubeconfig"
to your venv/bin/activate
and it will use the desired config when you activate the venv
.