kubectl version --clientCheck the installed kubectl client version.
Comprehensive kubectl commands for contexts, resources, apply flows, creation, deletion, logs, and cluster introspection.
Install validation, context switching, and cluster metadata.
kubectl version --clientCheck the installed kubectl client version.
Print the kubectl client and Kubernetes API server versions.
kubectl versionPrint the kubectl client and Kubernetes API server versions.
kubectl cluster-infoShow control plane and core service endpoints.
kubectl config viewInspect the merged kubeconfig content.
kubectl config current-contextPrint the active kubeconfig context.
kubectl config get-contextsList configured contexts and their clusters/users.
kubectl config use-context prod-clusterChange the active context in kubeconfig.
Persist a default namespace for the current context.
kubectl config set-context --current --namespace=paymentsPersist a default namespace for the current context.
kubectl api-resourcesShow resource types supported by the API server.
kubectl api-versionsShow supported API group versions.
Get comfortable listing and scoping objects.
kubectl get namespacesShow all namespaces.
kubectl create namespace stagingCreate a namespace imperatively.
kubectl delete namespace stagingDelete a namespace and the resources in it.
kubectl get all -n paymentsList common workload and service objects.
kubectl get pods -o wide -n paymentsShow node, IP, and extra details.
kubectl get pod web-abc123 -n paymentsInspect a single pod quickly.
kubectl describe pod web-abc123 -n paymentsView events, status, probes, mounts, and conditions.
kubectl explain podShow resource documentation from the API schema.
kubectl explain pod.spec.containersInspect nested resource fields.
Core workflows for changing objects from YAML.
kubectl apply -f deployment.yamlCreate or update a resource from a file.
kubectl apply -f k8s/Recursively apply manifests from a directory.
kubectl apply -R -f manifests/Apply manifests recursively from nested directories.
kubectl apply -f https://example.com/manifest.yamlApply a manifest hosted remotely.
kubectl diff -f deployment.yamlSee server-side differences before applying.
kubectl edit deployment web -n paymentsOpen a live editor against the API server.
kubectl replace -f deployment.yamlReplace an object using the manifest definition.
kubectl replace --force -f deployment.yamlDelete and recreate the object.
kubectl patch deployment web -p '{"spec":{"replicas":5}}'Apply a strategic/merge patch to an object.
kubectl patch deployment web --type='json' -p='[{"op":"replace","path":"/spec/replicas","value":5}]'Apply an RFC 6902 JSON patch.
kubectl annotate deployment web owner=platform-team --overwriteSet or replace an annotation.
kubectl label deployment web tier=frontend --overwriteSet or replace a label.
Fast object creation for experiments and demos.
kubectl create deployment web --image=nginx:1.27Create a deployment from an image.
kubectl scale deployment web --replicas=5Change replicas on a scalable workload.
kubectl expose deployment web --port=80 --target-port=8080 --type=ClusterIPCreate a Service for a workload.
kubectl run toolbox --image=busybox:1.36 -it --rm -- shCreate a one-off interactive pod.
kubectl create configmap app-config --from-literal=APP_ENV=prodCreate a ConfigMap imperatively.
kubectl create configmap nginx-conf --from-file=nginx.confBuild a ConfigMap from file content.
kubectl create secret generic app-secret --from-literal=API_KEY=supersecretCreate an opaque Secret.
kubectl create secret tls ingress-cert --cert=tls.crt --key=tls.keyCreate a TLS Secret from cert and key files.
kubectl create job db-migrate --image=alpine:3.20 -- echo migrationCreate a one-time Job.
kubectl create cronjob db-backup --image=alpine:3.20 --schedule='0 2 * * *' -- sh -c 'echo backup'Create a CronJob from the CLI.
Safe cleanup and shell access workflows.
kubectl delete -f deployment.yamlDelete objects defined in a manifest file.
kubectl delete pod web-abc123 -n paymentsDelete a pod so the controller can recreate it.
kubectl delete pod stuck-pod --grace-period=0 --forceForce-delete a stuck pod.
kubectl exec -it web-abc123 -n payments -- /bin/shStart an interactive shell inside a container.
kubectl exec web-abc123 -n payments -- envRun a non-interactive command in a container.
kubectl cp ./app.conf payments/web-abc123:/etc/app/app.confCopy a local file into a pod.
kubectl cp payments/web-abc123:/var/log/app.log ./app.logCopy a file from a pod to the local machine.
kubectl port-forward pod/web-abc123 8080:80 -n paymentsForward a local port to a pod port.
kubectl port-forward svc/web 8080:80 -n paymentsForward a local port to a service.
kubectl attach -it pod/debugger -n paymentsAttach STDIN/STDOUT to a running container.
Observe runtime behavior quickly.
kubectl logs web-abc123 -n paymentsPrint the current container logs.
kubectl logs -f web-abc123 -n paymentsStream logs in real time.
Read logs from a specific container in a multi-container pod.
kubectl logs web-abc123 -c web -n paymentsRead logs from a specific container in a multi-container pod.
Read logs from the previous crashed container instance.
kubectl logs web-abc123 --previous -n paymentsRead logs from the previous crashed container instance.
kubectl logs -l app=web --tail=100 -n paymentsAggregate logs across matching pods.
kubectl get events -n payments --sort-by=.lastTimestampShow events sorted by timestamp.
kubectl events -n payments --watchStream Kubernetes events.
kubectl get pods -n payments -wWatch resource changes live.
kubectl top pods -n paymentsRequires Metrics Server; shows CPU and memory usage.
Requires Metrics Server; shows node CPU and memory usage.
kubectl top nodesRequires Metrics Server; shows node CPU and memory usage.