What is kubectl and what commands should every user know?
Quick Answer
kubectl is the command-line tool for interacting with the Kubernetes API server. It translates human-readable commands into API requests. The essential commands are get, describe, apply, logs, exec, and delete — together they cover 90% of daily operations.
Detailed Answer
Think of kubectl like a remote control for your Kubernetes cluster. Just as a TV remote sends infrared signals to the TV to change channels, kubectl sends HTTP requests to the Kubernetes API server to create, read, update, and delete resources. You could technically do everything kubectl does by sending raw REST API calls with curl, but kubectl makes it convenient by handling authentication, serialization, and output formatting.
When you run a command like kubectl get pods, here's what happens internally: kubectl reads your kubeconfig file (usually at ~/.kube/config) to find the API server address and your authentication credentials (certificates, tokens, or cloud provider auth). It then sends an HTTPS GET request to the API server at a path like /api/v1/namespaces/default/pods. The API server authenticates your request, checks your RBAC permissions, and returns the data. Kubectl then formats the response into the table you see in your terminal.
The most critical commands form a daily workflow: kubectl get lists resources (pods, services, deployments) — add -o wide for more detail or -o yaml for the full spec. kubectl describe gives a detailed view of a single resource including its events, which is your first stop when debugging. kubectl apply -f creates or updates resources from a YAML file — this is the declarative approach used in production. kubectl logs streams container logs for debugging. kubectl exec -it pod -- /bin/sh gives you a shell inside a running container, like SSH into a server. kubectl delete removes resources.
Beyond the basics, several advanced commands are invaluable: kubectl port-forward tunnels a local port to a Pod for local debugging. kubectl top pods shows real-time CPU/memory usage (requires metrics-server). kubectl rollout status monitors deployment progress. And kubectl diff -f file.yaml shows what would change before you apply — essential in production.
A productivity gotcha: kubectl is verbose by default. In your daily workflow, set up aliases (alias k=kubectl), enable shell completion (source <(kubectl completion zsh)), and use kubectl config set-context to set a default namespace so you don't have to type -n namespace on every command. For the CKA/CKAD exams, these shortcuts save critical minutes.