What are the Essential kubectl Commands?
Learn the core kubectl commands — get, describe, apply, logs, exec — and how each works under the hood, with examples.
Expected Interview Answer
kubectl is the command-line tool that talks to the Kubernetes API server to create, inspect, modify, and delete cluster resources, and a small core set of commands — get, describe, apply, logs, and exec — covers the vast majority of day-to-day operational work.
kubectl get lists resources of a given type with a compact summary, kubectl describe shows a detailed, human-readable view of one resource including recent events, which is usually the first place to look when debugging a failing Pod. kubectl apply -f declaratively creates or updates resources from a YAML manifest, comparing the desired state in the file against the cluster’s current state and reconciling the difference, which is why it is preferred over the imperative kubectl create for anything managed long-term. kubectl logs streams a container’s stdout/stderr, and kubectl exec opens an interactive shell or runs a one-off command inside a running container for live debugging. Under the hood, every kubectl command is simply an authenticated HTTP call to the Kubernetes API server using the credentials and cluster context configured in the local kubeconfig file, so kubectl itself holds no cluster state of its own.
- A small set of commands covers most daily cluster operations
- kubectl apply enables declarative, reproducible resource management
- kubectl describe and logs are the first stops for debugging
- Everything routes through the same authenticated Kubernetes API
AI Mentor Explanation
kubectl is like the walkie-talkie a team analyst uses to communicate with the stadium’s central match-control system. "Get" is like asking control for a quick scoreboard summary, "describe" is like asking for a detailed player report including recent incidents, and “apply” is like submitting an updated team-sheet document that control reconciles against what is currently on the field. "Logs" is like requesting the ball-by-ball commentary feed, and “exec” is like radioing a specific player directly for a live check-in. The walkie-talkie itself holds no data — every request goes through to the same central match-control system.
Step-by-Step Explanation
Step 1
Inspect with get and describe
kubectl get lists resources; kubectl describe shows detailed status and recent events for one.
Step 2
Apply desired state
kubectl apply -f manifest.yaml declaratively reconciles the cluster to match the file.
Step 3
Check logs
kubectl logs <pod> -f streams a container’s output for debugging.
Step 4
Exec into a container
kubectl exec -it <pod> -- sh opens an interactive shell for live inspection.
What Interviewer Expects
- Fluency with get, describe, apply, logs, and exec as the daily toolkit
- Understanding that kubectl apply is declarative and kubectl create is not
- Knowledge that kubectl is a thin client over the Kubernetes API server
- Ability to describe a realistic debugging flow using these commands
Common Mistakes
- Using kubectl create repeatedly instead of idempotent kubectl apply
- Not checking kubectl describe events before jumping to logs
- Forgetting -f flag or wrong context/namespace, applying to the wrong cluster
- Confusing kubectl exec (into a running container) with kubectl run (starts a new Pod)
Best Answer (HR Friendly)
“kubectl is the command-line tool we use every day to talk to a Kubernetes cluster — checking what is running with get, digging into problems with describe, deploying changes with apply, and reading logs or jumping into a container directly when something is broken. It is really just a handful of commands that cover almost everything we need day to day once you get comfortable with them.”
Code Example
# List Pods in the current namespace
kubectl get pods
# Get detailed status and recent events for one Pod
kubectl describe pod myapp-7d4f9c-abcde
# Declaratively apply a manifest
kubectl apply -f deployment.yaml
# Stream logs from a container
kubectl logs -f myapp-7d4f9c-abcde
# Open an interactive shell inside a running container
kubectl exec -it myapp-7d4f9c-abcde -- shFollow-up Questions
- What is the difference between kubectl apply and kubectl create?
- How would you debug a Pod stuck in CrashLoopBackOff?
- What information does kubectl describe show that kubectl get does not?
- How does kubectl authenticate to the cluster?
MCQ Practice
1. Which command declaratively reconciles the cluster to match a YAML file?
kubectl apply -f compares the file’s desired state with the cluster’s current state and reconciles the difference, and is idempotent to re-run.
2. Which command is the best first step when debugging a failing Pod?
kubectl describe pod shows status, conditions, and recent events, which usually reveals why a Pod is failing before checking logs.
3. What does kubectl fundamentally do when you run any command?
Every kubectl command translates to an authenticated request to the Kubernetes API server using the local kubeconfig context.
Flash Cards
What does kubectl get do? — Lists resources of a given type with a compact summary.
What does kubectl describe do? — Shows detailed status, conditions, and recent events for one resource.
kubectl apply vs kubectl create? — apply is declarative and idempotent; create is imperative and errors on re-run.
How does kubectl talk to the cluster? — Via authenticated HTTP calls to the Kubernetes API server using the local kubeconfig.