Core Commands — Managing the Restaurant
The manager has learned the vocabulary. Now it's time to give orders. kubectl is the manager's walkie-talkie — every command you type goes to the Kubernetes API server, which tells the cluster what to do.
0 · Setup — Connecting to the Restaurant
kubectl version --client
Client Version: v1.28.x
kubectl cluster-info
Kubernetes control plane is running at https://k8s-cluster:6443
kubectl talks to the API server. If kubectl cluster-info fails, check your kubeconfig (~/.kube/config).
1 · kubectl apply — Handing the Blueprint to the Manager
kubectl apply -f deployment.yaml
deployment.apps/campus-library created
kubectl apply -f k8s/
apply is declarative — you describe what you want, and Kubernetes figures out how to get there. This is the recommended way to manage resources.
2 · kubectl get — What's Cooking?
kubectl get pods
NAME READY STATUS RESTARTS AGE
campus-library-7d4b8c9f-x2k4m 1/1 Running 0 5m
campus-library-7d4b8c9f-a9n3p 1/1 Running 0 5m
campus-library-7d4b8c9f-q8w2r 1/1 Running 0 5m
kubectl get deployments
kubectl get services
kubectl get all -n campus-dev
kubectl get all --all-namespaces
kubectl get is your compass. Run it whenever you're lost — it always tells you what's running.
3 · kubectl describe — What's Wrong with This Chef?
When a Pod isn't healthy, describe gives you the details:
kubectl describe pod campus-library-7d4b8c9f-x2k4m
The output includes events at the bottom — this is where you'll find errors like image pull failures, crash loops, and resource issues.
kubectl describe deployment campus-library
get shows the summary. describe shows the details. If get shows a problem, describe tells you why.
4 · kubectl logs — What Did the Chef Say?
kubectl logs campus-library-7d4b8c9f-x2k4m
Library running on port 3000
kubectl logs -f campus-library-7d4b8c9f-x2k4m
kubectl logs --previous campus-library-7d4b8c9f-x2k4m
kubectl logs is your debugging tool. If a Pod is in CrashLoopBackOff, check the logs first.
5 · kubectl exec — Opening a Chef's Lunch Box
kubectl exec -it campus-library-7d4b8c9f-x2k4m -- bash
root@campus-library-7d4b8c9f-x2k4m:/#
kubectl exec campus-library-7d4b8c9f-x2k4m -- cat /app/server.js
kubectl exec is for debugging. If you find yourself using it often, something is wrong with the container's configuration.
6 · kubectl scale — Hiring More Chefs
kubectl scale deployment campus-library --replicas=5
deployment.apps/campus-library scaled
kubectl get pods
NAME READY STATUS RESTARTS AGE
campus-library-7d4b8c9f-x2k4m 1/1 Running 0 10m
campus-library-7d4b8c9f-a9n3p 1/1 Running 0 10m
campus-library-7d4b8c9f-q8w2r 1/1 Running 0 10m
campus-library-7d4b8c9f-m3j5n 1/1 Running 0 10s
campus-library-7d4b8c9f-k8p2w 1/1 Running 0 10s
Scaling is instant. Kubernetes starts new Pods immediately. Scale down to remove them.
7 · kubectl delete — Sending Chefs Home
kubectl delete -f deployment.yaml
kubectl delete pod campus-library-7d4b8c9f-x2k4m
Deleting a Pod managed by a Deployment causes the Deployment to recreate it. To truly remove Pods, delete the Deployment.
8 · kubectl rollout — Watching the Kitchen Update
kubectl rollout status deployment/campus-library
deployment "campus-library" successfully rolled out
kubectl rollout history deployment/campus-library
kubectl rollout undo deployment/campus-library
rollout undo is your emergency button. If a new image is broken, rollback is instant.
Cheat Sheet
| Command | Restaurant meaning |
|---|---|
kubectl apply -f | Hand the blueprint to the manager |
kubectl get | What's cooking? |
kubectl describe | What's wrong with this chef? |
kubectl logs | What did the chef say? |
kubectl exec | Open a chef's lunch box |
kubectl scale | Hire more chefs |
kubectl delete | Send chefs home |
kubectl rollout | Watch the kitchen update |
kubectl rollout undo | Emergency rollback |