How to view the context of each pod

5/23/2018

I created a pod with context:

kubectl config set-context DevDan-context \
--cluster=kubernetes \
--namespace=development \
--user=DevDan  

I see the pod if I run kubectl --context=DevDan-context get pods.

But if I run just kubectl get pods I don't see the pod.

Is there a way to show all the pods with the column of context?
I know there is kubectl get pods --all-namespaces but it just show the pods and doesn't write what context each pod has:

ubuntu@HOST:~$ kubectl get pods --all-namespaces
NAMESPACE     NAME                                       READY     STATUS    RESTARTS   AGE
development   nginx-8586cf59-plq29                       1/1       Running   0          19h
kube-system   etcd-HOST                                  1/1       Running   1          9d
kube-system   kube-apiserver-HOST                        1/1       Running   1          9d
kube-system   kube-controller-manager-HOST               1/1       Running   1          9d
kube-system   kube-dns-6f4fd4bdf-25ddh                   3/3       Running   3          9d
kube-system   kube-flannel-ds-5vgd9                      1/1       Running   1          9d
kube-system   kube-flannel-ds-vvstn                      1/1       Running   0          9d
kube-system   kube-proxy-62xrx                           1/1       Running   1          9d
kube-system   kube-proxy-g7w7l                           1/1       Running   0          9d
kube-system   kube-scheduler-HOST                        1/1       Running   1          9d

The workaround is to run kubectl config get-contexts and then take each context and run kubectl --context=<my_context> get pods but if I have lots of context it can be problematic.

I also tried to run

-- E235
kubernetes

2 Answers

1/8/2019

To fetch all pods along with configuration:

kubectl describe pods --all-namespaces
-- Muthukrishnan.N
Source: StackOverflow

5/23/2018

set-context sets attributes of a given context

use-context switches to it as the default, so that get pods with no --context arg uses it by default

-- Jordan Liggitt
Source: StackOverflow