Skip to main content

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​

Check kubectl is installed
kubectl version --client
Client Version: v1.28.x
Check cluster connection
kubectl cluster-info
Kubernetes control plane is running at https://k8s-cluster:6443
Remember

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​

Apply a manifest file
kubectl apply -f deployment.yaml
deployment.apps/campus-library created
Apply everything in a folder
kubectl apply -f k8s/
Remember

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?​

See all Pods
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
See Deployments
kubectl get deployments
See Services
kubectl get services
See everything in a namespace
kubectl get all -n campus-dev
See all resources across all namespaces
kubectl get all --all-namespaces
Remember

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:

Describe a specific Pod
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.

Describe a Deployment
kubectl describe deployment campus-library
Remember

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?​

See logs of a Pod
kubectl logs campus-library-7d4b8c9f-x2k4m
Library running on port 3000
Follow logs in real time
kubectl logs -f campus-library-7d4b8c9f-x2k4m
Logs from a previous container (if it crashed)
kubectl logs --previous campus-library-7d4b8c9f-x2k4m
Remember

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​

Open a shell inside a running Pod
kubectl exec -it campus-library-7d4b8c9f-x2k4m -- bash
root@campus-library-7d4b8c9f-x2k4m:/#
Run a single command
kubectl exec campus-library-7d4b8c9f-x2k4m -- cat /app/server.js
Remember

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​

Scale a Deployment
kubectl scale deployment campus-library --replicas=5
deployment.apps/campus-library scaled
Verify
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
Remember

Scaling is instant. Kubernetes starts new Pods immediately. Scale down to remove them.

7 · kubectl delete — Sending Chefs Home​

Delete a resource
kubectl delete -f deployment.yaml
Delete by name
kubectl delete pod campus-library-7d4b8c9f-x2k4m
Common mistake

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​

Check rollout status
kubectl rollout status deployment/campus-library
deployment "campus-library" successfully rolled out
See rollout history
kubectl rollout history deployment/campus-library
Rollback if something goes wrong
kubectl rollout undo deployment/campus-library
Remember

rollout undo is your emergency button. If a new image is broken, rollback is instant.

Cheat Sheet​

CommandRestaurant meaning
kubectl apply -fHand the blueprint to the manager
kubectl getWhat's cooking?
kubectl describeWhat's wrong with this chef?
kubectl logsWhat did the chef say?
kubectl execOpen a chef's lunch box
kubectl scaleHire more chefs
kubectl deleteSend chefs home
kubectl rolloutWatch the kitchen update
kubectl rollout undoEmergency rollback