Cluster & context ⤢ kubectl cluster-infoShow where the control plane and core services run. kubectl cluster-info ⤢ kubectl config get-contextsList the clusters and namespaces you can switch between. kubectl config get-contexts ⤢ kubectl config use-contextSwitch to a different cluster or namespace context. kubectl config use-context my-prod ⤢ kubectl config set-context --current --namespaceSet the default namespace of the current context. kubectl config set-context --current --namespace=staging ⤢ kubectl config rename-contextRename a saved context in your kubeconfig. kubectl config rename-context old-name prod ⤢ kubectl api-resourcesList every resource type the cluster knows. kubectl api-resources ⤢ kubectl versionPrint the client and server Kubernetes versions. kubectl version ⤢ kubectl explainShow the fields a resource supports, read from the API schema. kubectl explain pod.spec.containers ⤢ kubectl auth can-iCheck whether the current user may run a given action. kubectl auth can-i delete pods Inspecting workloads ⤢ kubectl get podsList pods and their status; add -o wide for node and IP. kubectl get pods -A ⤢ kubectl get allList the common resources of a namespace in one call. kubectl get all ⤢ kubectl get -o wideAdd node and IP columns to any get command. kubectl get pods -o wide ⤢ kubectl get -o yamlPrint a resource as the full YAML manifest behind it. kubectl get deploy/web -o yaml ⤢ kubectl get deploymentsList deployments and how many replicas are ready. kubectl get deployments ⤢ kubectl get statefulsetsList stateful sets and their ready replicas. kubectl get statefulsets ⤢ kubectl get jobs, cronjobsList batch jobs and scheduled cron jobs. kubectl get jobs,cronjobs ⤢ kubectl describe podShow events, labels, and status for one pod. kubectl describe pod web-abc ⤢ kubectl describe nodeShow a node's capacity, conditions, and running pods. kubectl describe node node-1 ⤢ kubectl logsPrint a pod's stdout; -f to follow, --previous for the last crash. kubectl logs -f web-abc ⤢ kubectl execRun a command inside a running pod. kubectl exec -it web-abc -- sh ⤢ kubectl topLive CPU and memory for pods or nodes (needs metrics-server). kubectl top pods ⤢ kubectl get eventsList recent events such as failed pulls and backoffs. kubectl get events -A --sort-by=.lastTimestamp ⤢ kubectl get ingressList ingress rules and their load balancer addresses. kubectl get ingress ⤢ kubectl cpCopy files between your machine and a running pod. kubectl cp web-abc:/var/log/app.log ./app.log ⤢ kubectl waitBlock until a resource meets a condition. kubectl wait --for=condition=ready pod -l app=web ⤢ kubectl runStart a throwaway pod from an image, no manifest needed. kubectl run debug --rm -it --image=busybox -- sh Apply, scale, roll out ⤢ kubectl diffShow what apply would change, without changing it. kubectl diff -f deploy.yaml ⤢ kubectl apply -fCreate or update resources from a manifest file. kubectl apply -f deploy.yaml ⤢ kubectl apply --pruneApply manifests and delete objects that left them. kubectl apply -f dir/ --prune -l app=web ⤢ kubectl editOpen a live resource in your editor and apply on save. kubectl edit deploy/web ⤢ kubectl patchChange a few fields on a live resource. kubectl patch deploy/web --patch-file fix.json ⤢ kubectl set imagePoint a deployment's containers at a new image. kubectl set image deploy/web web=nginx:1.27 ⤢ kubectl replace --forceReplace an object, deleting and recreating it when needed. kubectl replace --force -f deploy.yaml ⤢ kubectl delete -fRemove the resources declared in a manifest file. kubectl delete -f deploy.yaml ⤢ kubectl scaleChange the replica count of a deployment. kubectl scale deploy/web --replicas=4 ⤢ kubectl rollout statusWatch a rollout finish or fail. kubectl rollout status deploy/web ⤢ kubectl rollout historyList the revisions a rollout has been through. kubectl rollout history deploy/web ⤢ kubectl rollout restartRestart every pod of a deployment, one at a time. kubectl rollout restart deploy/web ⤢ kubectl rollout undoRoll a deployment back to its previous revision. kubectl rollout undo deploy/web Services & networking ⤢ kubectl get svcList services and their type and cluster IP. kubectl get svc ⤢ kubectl get endpointsShow which pod IPs currently back each service. kubectl get endpoints web ⤢ kubectl exposeCreate a service that fronts a set of pods; --type=NodePort or LoadBalancer reaches outside the cluster. kubectl expose deploy/web --port=80 ⤢ kubectl ingress statusShow the load balancer address behind each ingress (alpha). kubectl ingress status -A ⤢ kubectl get networkpoliciesList the policies that restrict pod traffic. kubectl get networkpolicies ⤢ kubectl port-forwardTunnel a local port to a pod or service. kubectl port-forward svc/web 8080:80 Nodes & maintenance ⤢ kubectl get nodesList cluster nodes and their status. kubectl get nodes -o wide ⤢ kubectl cordonMark a node unschedulable (no new pods). kubectl cordon node-1 ⤢ kubectl uncordonMark a node schedulable again. kubectl uncordon node-1 ⤢ kubectl drainEvict pods from a node and mark it unschedulable. kubectl drain node-1 --ignore-daemonsets ⤢ kubectl taintAdd or remove a taint that repels pods from a node. kubectl taint node node-1 key=value:NoSchedule ⤢ kubectl delete pod --grace-period=0 --forceDelete a stuck pod at once, skipping graceful shutdown. kubectl delete pod web-abc --grace-period=0 --force Objects & config ⤢ kubectl create namespaceMake a new namespace to scope resources to. kubectl create namespace staging ⤢ kubectl get namespacesList namespaces and their status. kubectl get namespaces ⤢ kubectl create configmapStore config keys or files as a cluster object. kubectl create configmap app --from-file=config.yaml ⤢ kubectl get configmapsList config maps in the namespace. kubectl get configmaps ⤢ kubectl create secretStore a password or certificate as a secret. kubectl create secret generic db --from-literal=password=s3cret ⤢ kubectl get secretsList secrets in the namespace. kubectl get secrets ⤢ kubectl labelAttach or remove a label on a resource. kubectl label pod web-abc tier=backend ⤢ kubectl annotateAttach metadata that selectors cannot match. kubectl annotate deploy/web release=july