Without kubectl, how do you display list of names of available Kubernetes contexts that you can use from the machine?

Experience Level: Junior
Tags: Kubernetes

Answer

Use the following command:

cat ~/.kube/config|yq eval -o json|jq ".contexts[].name"

How does it work?

  • The configuration data is stored the file ~/.kube/config
  • cat command displays the conent of the file
  • yq command converts the output from yaml to JSON format
  • jq command will iterate over all child elements of element (array) contexts, name property of each child element is displayed.
Kubernetes Certified Application Developer (CKAD) preparation
Kubernetes Certified Application Developer (CKAD) preparation

Are you learning Kubernetes ? Try our test we designed to help you progress faster.

Test yourself
Kubernetes
Kubernetes

Are you learning Kubernetes ? Try our test we designed to help you progress faster.

Test yourself
25 Kubernetes questions that will help you get certified and become more efficient with K8s
25 Kubernetes questions that will help you get certified and become more efficient with K8s

Are you learning Kubernetes ? Try our test we designed to help you progress faster.

Test yourself