How to run a command against a specific context with kubectl?

5/1/2019

I have multiple contexts and I want to be able to run commands against a context that I have access to but am not pointed to, while in another context.

How do I run a command, say $ kubectl get pods against context B while I'm currently pointed to context A?

-- arshbot
kubectl
kubernetes

2 Answers

5/2/2019

try this command

kubectl config set-context $(kubectl config current-context) --namespace=<namespace>

then run

kubectl get po
-- P Ekambaram
Source: StackOverflow

5/1/2019

--context is a global option for all kubectl commands. Simply run:

$ kubectl get pods --context <context_B>

For a list of all global kubectl options, run $ kubectl options

-- arshbot
Source: StackOverflow