K8s CLI & Context - Kubernetes Context Management & Commands Guide

Comprehensive guide to Kubernetes context management with kubectl commands and kubectx tool installation for Windows, macOS, and Ubuntu.

Kubernetes Context Management

Learn how to efficiently manage Kubernetes contexts to switch between different clusters and namespaces.

K8s Context

  • A context is a group of access parameters to a K8s cluster
  • Contains a Kubernetes cluster, a user, and a namespace
  • The current context is the cluster that is currently the default for kubectl
    • All kubectl commands run against that cluster

K8s API

The API Server exposes a REST API
{REST:API}
kube-controller-manager
cloud-controller-manager
kube-apiserver
kube-scheduler
etcd
Desired state YAML

kubectl - Context Cheat Sheet

kubectl config current-context

Get the current context

kubectl config get-contexts

List all context

kubectl config use-context [contextName]

Set the current context

kubectl config delete-context [contextName]

Delete a context from the config file

Kubectx – Quickly switch context

Instead of typing:

kubectl config use-context minikube

Simply type:

kubectx [contextName]

Windows

choco install kubectx-ps

macOS

brew install kubectx

Ubuntu

sudo apt install kubectx