Kubectl Commands Masterclass

Essential CLI commands to inspect, debug, manage, and execute commands across your Kubernetes cluster.

1. Core Kubectl Commands Cheat Sheet

CommandDescriptionUsage Example
kubectl getLists resources (pods, svc, deploy, ns)kubectl get pods -o wide
kubectl describeShows detailed resource state & event logskubectl describe pod my-pod
kubectl apply -fApplies declarative configuration file(s)kubectl apply -f deployment.yaml
kubectl deleteDeletes resource(s) from clusterkubectl delete pod my-pod
kubectl logsFetches pod console stdout logskubectl logs -f my-pod -c container-1
kubectl execExecutes interactive shell in containerkubectl exec -it my-pod -- bash
kubectl port-forwardForwards local port to cluster pod/servicekubectl port-forward svc/my-svc 8080:80

2. Live Debugging Workflows

A. Forwarding Cluster Service to Local Machine:
kubectl port-forward service/postgres-service 5432:5432
B. Opening Interactive Shell Inside Pod:
kubectl exec -it my-app-pod -n production -- /bin/sh

Next Up

Explore Pods: Pod lifecycle, container specs, and multi-container patterns (Sidecar pattern).

Next Lesson: Pods Basics & Patterns →