kubectlcluster-info # clusterendpointinfokubectlgetevents # recentclustereventskubectlgetcs # controlplanecomponentstatuskubectlconfigget-contexts # listallcontextskubectlconfigcurrent-context # showactivecontextkubectlconfiguse-context<context> # switchcontextkubectlconfigset-context--current--namespace=<ns> # set default namespace for current context
Basics
kubectlget<resource> # listresourceskubectldescribe<resource><name> # detailed info about a resourcekubectl logs <pod> # print logs from a podkubectl logs <pod> -c <container> # logs from specific container in podkubectl logs <pod> --previous # logs from previous (crashed) containerkubectl exec -it <pod> -- bash # exec into container (bash)kubectl exec -it <pod> -- sh # exec into container (sh — use for alpine/busybox)kubectl exec -it <pod> -c <container> -- bash # exec into specific containerkubectl delete <resource><name> # delete a resourcekubectl apply -f <file.yaml> # apply manifestkubectl delete -f <file.yaml> # delete resources defined in manifest
kubectlgetpods # listpodsindefaultnamespacekubectlgetpods-owide # withIPandnodeinfokubectlgetpods-n<namespace> # podsinspecificnamespacekubectlgetpods-A # podsinallnamespaceskubectlgetpods-lapp=<label> # filter pods by labelkubectl get pods -w # watch pods (live updates)kubectl describe pod <pod> # full pod details — useful for troubleshootingkubectl delete pod <pod> # delete podkubectl delete pod <pod> --force --grace-period=0 # force delete stuck podkubectl label pods <pod><key>=<value> # add/update label on podkubectl run <name> --image=nginx --port=80 # run a simple podkubectl run <name> --image=nginx --dry-run=client -o yaml # generate pod YAML without applyingkubectl top pods # pod CPU/memory usage (requires metrics-server)kubectl top pods -n <namespace>
kubectlgetdeployments # listdeploymentskubectlgetrs # listreplicasetskubectldescribedeployment<name>kubectlapply-fdeployment.yaml # create/updatedeploymentfrommanifestkubectleditdeployment<name> # editdeploymentliveineditorkubectldeletedeployment<name>kubectlscaledeployment<name>--replicas=4 # scaledeploymentkubectlsetimagedeployment/<name><container>=<image>:<tag> # rolling update imagekubectl rollout status deployment/<name> # check rollout progresskubectl rollout history deployment/<name> # view rollout historykubectl rollout undo deployment/<name> # roll back to previous versionkubectl rollout undo deployment/<name> --to-revision=2 # roll back to specific revisionkubectl rollout restart deployment/<name> # restart all pods (picks up new config/secrets)