Cluster
kubectl cluster-infoShow the master and DNS endpointkubectl version --clientPrint the kubectl client versionkubectl config get-contextsList all known kubeconfig contextskubectl config use-context <name>Switch the active contextkubectl config current-contextPrint the active contextkubectl api-resourcesList every resource type the cluster supports
Pods
kubectl get podsList Pods in the current namespacekubectl get pods -AList Pods across every namespacekubectl get pod <name> -o yamlPrint the full Pod manifestkubectl describe pod <name>Show events and detail for a Podkubectl delete pod <name>Delete a Pod (controller will recreate)kubectl get pods --field-selector status.phase=PendingShow only Pending Pods
Deployments
kubectl get deployList Deploymentskubectl create deploy nginx --image=nginx:1.27Create a Deployment from an imagekubectl rollout status deploy/<name>Watch a rollout to completionkubectl rollout undo deploy/<name>Roll back to the previous revisionkubectl scale deploy/<name> --replicas=5Set the replica countkubectl set image deploy/<name> <container>=<image>Update a container image
Services & networking
kubectl get svcList Serviceskubectl expose deploy/<name> --port=80Create a ClusterIP Service for a Deploymentkubectl port-forward svc/<name> 8080:80Forward a local port to a Servicekubectl get ingressList Ingress resourceskubectl get endpointsShow which Pods back each Service
Config & secrets
kubectl get configmapList ConfigMapskubectl create configmap app --from-file=./config.yamlCreate a ConfigMap from a filekubectl get secretList Secretskubectl create secret generic db --from-literal=password=…Create a Secret from a literalkubectl get secret db -o jsonpath='{.data.password}' | base64 -dDecode a Secret value
Logs & exec
kubectl logs <pod>Print logs for the first container in a Podkubectl logs <pod> -c <container>Logs for a specific containerkubectl logs -f <pod>Follow logs (tail -f)kubectl logs --previous <pod>Logs from the previous container instancekubectl exec -it <pod> -- shOpen a shell inside a Podkubectl cp <pod>:/path ./localCopy a file from a Pod
Debug & inspect
When something is wrong, these are the commands you reach for first.
kubectl get events --sort-by=.lastTimestampRecent cluster eventskubectl top podCPU/memory per Pod (requires metrics-server)kubectl top nodeCPU/memory per Nodekubectl debug node/<node> -it --image=ubuntuOpen a debug Pod on a Nodekubectl debug pod/<pod> -it --image=busybox --share-processesAttach an ephemeral container to a Podkubectl auth can-i create deployCheck whether the current user can perform an action
Apply, diff, kustomize
kubectl apply -f ./manifests/Apply every YAML in a directorykubectl apply -k ./overlays/prodApply a Kustomize overlaykubectl diff -f deploy.yamlShow what would change before applyingkubectl delete -f ./manifests/Delete every resource defined in a directorykubectl wait --for=condition=Ready pod/<name>Wait for a condition to be true