CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / Kubernetes / kubectl config

kubectl config

Manage clusters, users and contexts in kubeconfig

Beginnerkuberneteskubeconfigaccess

kubectl config reads and edits your kubeconfig: the file that tells kubectl which clusters exist, how to authenticate to each, and which one (and which namespace) your commands go to right now. Switching context is how you move between dev and prod, so it's also how prod accidents happen.

Syntaxkubectl config (get-contexts | current-context | use-context NAME | set-context [--current] --namespace=NS | view [--minify] | rename-context | delete-context)

Watch it run

Before a change, confirm which cluster and namespace kubectl will hit, then switch to the dev cluster.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
kubectl config get-contexts

Each context is cluster + user (AUTHINFO) + default namespace. The * marks the one every kubectl command uses right now: prod. An empty NAMESPACE means 'default'.

Anatomy of a command

$
commandkubectl

The Kubernetes CLI.

How it works

A kubeconfig is a YAML file with three lists, clusters (API server URL and CA certificate), users (credentials: a client certificate, a token, or an exec plugin), and contexts that pair a cluster with a user and optional namespace, plus current-context. kubectl loads it from --kubeconfig, else from the KUBECONFIG variable (a colon-separated list of files merged in order; the first to set a value wins), else ~/.kube/config. kubectl config subcommands just read and rewrite those files; they never contact a cluster. On EKS, aws eks update-kubeconfig adds a cluster entry and a user that uses the exec plugin: each kubectl call runs aws eks get-token, which creates a presigned STS GetCallerIdentity request; the EKS API server verifies it and maps your IAM identity to Kubernetes users and groups through access entries (or the older aws-auth ConfigMap). Tokens last about 15 minutes and are refreshed automatically.

Options you'll actually use

get-contextsList contexts; * marks the current one
current-contextPrint the active context's name
use-context NAMESwitch the active context
set-context --current --namespace=NSChange the default namespace
view [--minify] [--raw]Show the merged config; --minify = current context only
rename-context OLD NEWGive a context a friendlier name
delete-context NAMERemove a context (the cluster and user entries stay)
get-clusters / get-usersList cluster and user entries
--kubeconfig FILEUse a specific file for this one command

Common mistakes

Running kubectl delete or apply without checking the current context

use-context in one terminal changes ~/.kube/config for every terminal; the command may hit prod.

kubectl config current-context first, or put the context in your prompt; use --context explicitly in scripts
Committing ~/.kube/config or pasting kubectl config view --raw into a ticket

It can contain client certificates and tokens that grant cluster access.

Share the cluster name and region; others run aws eks update-kubeconfig themselves
Using a long-lived ServiceAccount token in CI kubeconfigs

It never expires and is hard to rotate; a leak means permanent access.

Use OIDC/IAM-based short-lived credentials (EKS access entries, IRSA for CI runners)

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Write the commands to switch to the context named prod and make monitoring its default namespace.

  2. 2

    Write a one-off command that lists pods in the context dev without switching your current context.

  3. 3

    Switch to the dev context, list its pods (its default namespace is payments), then switch back to prod and check which context is active.

  4. 4

    In AWS Lab > EKS > your cluster > Run kubectl (lab), open your cluster's Overview and find the command that connects kubectl (update-kubeconfig) and the API server endpoint it would write.

Related commands

kubectl getList Kubernetes resources and their statusaws eksConnect kubectl to EKS and manage cluster accessaws configureSet up AWS CLI credentials, region and profileskubectl deleteDelete Kubernetes resources safely
Previouskubectl topNexthelm
Linux / Kubernetes / kubectl config

kubectl config

Manage clusters, users and contexts in kubeconfig

Beginnerkuberneteskubeconfigaccess

kubectl config reads and edits your kubeconfig: the file that tells kubectl which clusters exist, how to authenticate to each, and which one (and which namespace) your commands go to right now. Switching context is how you move between dev and prod, so it's also how prod accidents happen.

Syntaxkubectl config (get-contexts | current-context | use-context NAME | set-context [--current] --namespace=NS | view [--minify] | rename-context | delete-context)

Watch it run

Before a change, confirm which cluster and namespace kubectl will hit, then switch to the dev cluster.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
kubectl config get-contexts

Each context is cluster + user (AUTHINFO) + default namespace. The * marks the one every kubectl command uses right now: prod. An empty NAMESPACE means 'default'.

Anatomy of a command

$
commandkubectl

The Kubernetes CLI.

How it works

A kubeconfig is a YAML file with three lists, clusters (API server URL and CA certificate), users (credentials: a client certificate, a token, or an exec plugin), and contexts that pair a cluster with a user and optional namespace, plus current-context. kubectl loads it from --kubeconfig, else from the KUBECONFIG variable (a colon-separated list of files merged in order; the first to set a value wins), else ~/.kube/config. kubectl config subcommands just read and rewrite those files; they never contact a cluster. On EKS, aws eks update-kubeconfig adds a cluster entry and a user that uses the exec plugin: each kubectl call runs aws eks get-token, which creates a presigned STS GetCallerIdentity request; the EKS API server verifies it and maps your IAM identity to Kubernetes users and groups through access entries (or the older aws-auth ConfigMap). Tokens last about 15 minutes and are refreshed automatically.

Options you'll actually use

get-contextsList contexts; * marks the current one
current-contextPrint the active context's name
use-context NAMESwitch the active context
set-context --current --namespace=NSChange the default namespace
view [--minify] [--raw]Show the merged config; --minify = current context only
rename-context OLD NEWGive a context a friendlier name
delete-context NAMERemove a context (the cluster and user entries stay)
get-clusters / get-usersList cluster and user entries
--kubeconfig FILEUse a specific file for this one command

Common mistakes

Running kubectl delete or apply without checking the current context

use-context in one terminal changes ~/.kube/config for every terminal; the command may hit prod.

kubectl config current-context first, or put the context in your prompt; use --context explicitly in scripts
Committing ~/.kube/config or pasting kubectl config view --raw into a ticket

It can contain client certificates and tokens that grant cluster access.

Share the cluster name and region; others run aws eks update-kubeconfig themselves
Using a long-lived ServiceAccount token in CI kubeconfigs

It never expires and is hard to rotate; a leak means permanent access.

Use OIDC/IAM-based short-lived credentials (EKS access entries, IRSA for CI runners)

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Write the commands to switch to the context named prod and make monitoring its default namespace.

  2. 2

    Write a one-off command that lists pods in the context dev without switching your current context.

  3. 3

    Switch to the dev context, list its pods (its default namespace is payments), then switch back to prod and check which context is active.

  4. 4

    In AWS Lab > EKS > your cluster > Run kubectl (lab), open your cluster's Overview and find the command that connects kubectl (update-kubeconfig) and the API server endpoint it would write.

Related commands

kubectl getList Kubernetes resources and their statusaws eksConnect kubectl to EKS and manage cluster accessaws configureSet up AWS CLI credentials, region and profileskubectl deleteDelete Kubernetes resources safely
Previouskubectl topNexthelm