Kubectl How to List All Contexts

How do I view all the contexts I have set up with kubectl?

It doesn't appear there's a resource known to kubectl as 'contexts'

$ kubectl get contexts
error: the server doesn't have a resource type "contexts"
1

3 Answers

You can view all contexts via the config command

$ kubectl config get-contexts
1

For the kubectl command, use this command to list all the contexts:

kubectl config get-contexts

You can view the default config file that locates at ~/.kube/config, it contains more info like clusters, users, ...

In addition to you answer, you can use kubectx tool to easily switch between clusters and namespaces.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest