Sign In

Curriculum 1: What is Kubectl?

Kubectl's Role

10 min · 15 XP

The Role of kubectl

Now that you understand what Kubernetes is, let us look at how kubectl fits in as your primary way to interact with it.

The CLI Interface to the Kubernetes API

Everything in Kubernetes is managed through its REST API. The API server is the front door to the cluster. kubectl is a command-line client that knows how to talk to that API.

When you run a command like this:

kubectl get pods

kubectl does the following behind the scenes:

  1. Reads your kubeconfig file to find the cluster address and credentials
  2. Builds an HTTP GET request to the API server endpoint /api/v1/pods
  3. Sends the request with proper authentication
  4. Receives the JSON response
  5. Formats it into a human-readable table in your terminal

How kubectl Communicates With the Cluster

kubectl uses a configuration file (usually at ~/.kube/config) to know which cluster to talk to. This file contains:

  • Cluster information -- the API server address and certificate
  • User credentials -- how to authenticate
  • Contexts -- named combinations of cluster + user + namespace
# See your current context
kubectl config current-context

# List all available contexts
kubectl config get-contexts

# Switch to a different context
kubectl config use-context my-other-cluster

Common Workflow Patterns

Most kubectl workflows follow a predictable pattern:

Inspect -- Look at what is running:

kubectl get deployments
kubectl describe pod my-app-pod

Act -- Make changes:

kubectl apply -f deployment.yaml
kubectl scale deployment my-app --replicas=5

Debug -- Investigate problems:

kubectl logs my-app-pod
kubectl exec -it my-app-pod -- /bin/sh

kubectl vs Other Tools

kubectl is not the only way to manage Kubernetes, but it is the most universal.

ToolBest ForLimitations
kubectlFull control, scripting, automationRequires terminal comfort
Kubernetes DashboardVisual overview, quick editsLimited advanced operations
Lens / K9sDeveloper-friendly UIExtra install, learning curve
HelmPackage managementHigher-level abstraction

The dashboard and GUI tools are built on top of the same API that kubectl uses. Learning kubectl gives you the deepest understanding of what is actually happening in your cluster.

Key Takeaways

  • kubectl is a CLI client for the Kubernetes REST API
  • It reads connection details from your kubeconfig file
  • Common workflows follow an inspect, act, debug pattern
  • kubectl gives you the most complete and scriptable access to your cluster