Courseiva

How to View the Active Kubeconfig Context

Which kubeconfig context is currently active?

Quick Answer

The answer is `kubectl config current-context`. This command directly queries your kubeconfig file and prints the name of the currently active context, which is the default cluster, user, and namespace combination that kubectl will use for all subsequent commands. On the Certified Kubernetes Administrator CKA exam, this is a foundational concept because misidentifying the active context is a common source of errors when managing multiple clusters—you might accidentally run destructive commands against the wrong environment. The exam often tests your ability to verify context before performing administrative tasks, and a frequent trap is confusing `kubectl config view` (which shows all contexts) with the specific command to show only the active one. Remember the memory tip: "current-context" is the only command that gives you the single, active answer—think of it as asking kubectl "who's in charge right now?"

⚠ Common exam trap

A common mix-up: candidates confuse `kubectl config get-contexts` (which shows all contexts with an asterisk on the active one) with a command that directly outputs only the active context, leading them to choose option C instead of the more precise D.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

kubectl config current-context

`kubectl config current-context` is the dedicated kubectl command that displays the name of the currently active context from the kubeconfig file. The active context determines which cluster, user, and namespace are used by default for kubectl commands, making this the precise way to identify the active context.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    kubectl config view

    Why it's wrong here

    kubectl config view prints the merged kubeconfig contents, including contexts, clusters and users, but does not mark which one is active. It is tempting because it shows all context definitions, and it would be the correct choice when you need to inspect or verify the full configuration rather than identify the current context.

  • ✗

    kubectl cluster-info

    Why it's wrong here

    kubectl cluster-info reports the addresses of the control plane and add-on services, not the active context. It is tempting because it confirms connectivity to a cluster, and it would be the correct choice when verifying that the API server is reachable and which endpoint the client is talking to.

  • ✗

    kubectl config get-contexts

    Why it's wrong here

    kubectl config get-contexts lists all contexts and marks the current one with an asterisk, but does not report it as a single value. kubectl config current-context returns the active context name directly, which is what the question asks for.

  • ✓

    kubectl config current-context

    Why this is correct

    This subcommand reads the kubeconfig's current-context field and prints the name of the context kubectl will use by default, directly answering which context is active. It queries configuration state rather than cluster resources, so no API server call is needed.

About these practice questions

This CKA question is part of Courseiva's 726-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

2 more ways this is tested on CKA

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. An admin wants to view the current context in their kubeconfig. Which command should they use?

medium
  • A.kubectl config get-contexts
  • B.kubectl cluster-info
  • ✓ C.kubectl config current-context
  • D.kubectl config view

Why C: `kubectl config current-context` is the exact command to display the currently active context from the kubeconfig file. The context includes the cluster, namespace, and user that `kubectl` will use by default. This is a direct query of the `current-context` field in the kubeconfig YAML/JSON structure.

Variation 2. A cluster has multiple kubeconfig files. You want to set the current context to 'admin@production' for all future kubectl commands. Which command should you run?

medium
  • A.kubectl config set-context admin@production
  • ✓ B.kubectl config use-context admin@production
  • C.kubectl config set-cluster admin@production
  • D.kubectl config get-contexts admin@production

Why B: The `kubectl config use-context` command is used to set the current context in a kubeconfig file, which determines the cluster, user, and namespace that kubectl will use by default for all subsequent commands. Option B correctly specifies `admin@production` as the context to switch to, making it the active context for future kubectl operations.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This CKA practice question is part of Courseiva's free CNCF certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the CKA exam.