DevOps & Cloud · Cheatsheet
Kubernetes Commands Cheatsheet
kubectl essentials: pods, deployments, services, secrets, scaling, debugging, and RBAC
72 commands 9 sections
No entry matches that filter.
-
kubectl cluster-infoDisplay cluster endpoint and services info -
kubectl config viewShow merged kubeconfig settings -
kubectl config current-contextShow the current context -
kubectl config use-context <ctx>Switch to a different context -
kubectl config get-contextsList all available contexts -
kubectl config set-context --current --namespace=<ns>Set default namespace for current context -
kubectl get nodesList all nodes in the cluster -
kubectl get nodes -o wideList nodes with extra details (IP, OS, etc.) -
kubectl api-resourcesList all supported resource types
-
kubectl get podsList pods in current namespace -
kubectl get pods -AList pods across all namespaces -
kubectl get pods -o wideList pods with node and IP info -
kubectl get pods -wWatch pods in real-time -
kubectl describe pod <name>Show detailed info about a pod -
kubectl run <name> --image=<img>Create and run a pod from an image -
kubectl delete pod <name>Delete a specific pod -
kubectl delete pod <name> --force --grace-period=0Force delete a stuck pod -
kubectl exec -it <pod> -- bashOpen shell in a running pod -
kubectl cp <pod>:<path> <local>Copy files from pod to local machine
-
kubectl get deploymentsList all deployments -
kubectl describe deployment <name>Show deployment details and events -
kubectl create deployment <name> --image=<img>Create a deployment -
kubectl set image deployment/<name> <ctr>=<img>:<tag>Update container image in deployment -
kubectl rollout status deployment/<name>Watch rollout progress -
kubectl rollout history deployment/<name>Show rollout revision history -
kubectl rollout undo deployment/<name>Rollback to previous revision -
kubectl rollout undo deployment/<name> --to-revision=<n>Rollback to specific revision -
kubectl rollout restart deployment/<name>Restart all pods in deployment -
kubectl delete deployment <name>Delete a deployment
-
kubectl get svcList all services -
kubectl get svc -AList services across all namespaces -
kubectl describe svc <name>Show service details and endpoints -
kubectl expose deployment <name> --port=80 --type=LoadBalancerExpose deployment as a service -
kubectl port-forward svc/<name> 8080:80Forward local port to service -
kubectl port-forward pod/<name> 8080:80Forward local port to pod -
kubectl get ingressList all ingress resources -
kubectl get endpoints <svc>Show pod IPs behind a service
-
kubectl get configmapsList all ConfigMaps -
kubectl create configmap <name> --from-file=<path>Create ConfigMap from file -
kubectl create configmap <name> --from-literal=key=valCreate ConfigMap from literal values -
kubectl get secretsList all secrets -
kubectl create secret generic <name> --from-literal=k=vCreate a generic secret -
kubectl create secret tls <name> --cert=tls.crt --key=tls.keyCreate a TLS secret -
kubectl get secret <name> -o jsonpath="{.data.key}" | base64 -dDecode and view a secret value -
kubectl describe configmap <name>Show ConfigMap contents and metadata
-
kubectl get namespacesList all namespaces -
kubectl create namespace <name>Create a new namespace -
kubectl delete namespace <name>Delete a namespace and all its resources -
kubectl get all -n <namespace>List all resources in a namespace -
kubectl get serviceaccountsList service accounts -
kubectl auth can-i <verb> <resource>Check if current user can perform action -
kubectl auth can-i --listList all permissions for current user
-
kubectl logs <pod>Show logs for a pod -
kubectl logs <pod> -fFollow (stream) pod logs -
kubectl logs <pod> -c <container>Show logs for specific container in pod -
kubectl logs <pod> --previousShow logs from previous crashed container -
kubectl logs -l app=<label>Show logs for all pods matching label -
kubectl describe pod <name>Show events and status (debug crashes) -
kubectl get events --sort-by=.metadata.creationTimestampList cluster events sorted by time -
kubectl top podsShow CPU/memory usage per pod -
kubectl top nodesShow CPU/memory usage per node -
kubectl debug <pod> -it --image=busyboxAttach debug container to a pod
-
kubectl scale deployment/<name> --replicas=3Scale deployment to 3 replicas -
kubectl autoscale deployment/<name> --min=2 --max=10 --cpu-percent=80Create HorizontalPodAutoscaler -
kubectl get hpaList Horizontal Pod Autoscalers -
kubectl apply -f <file.yaml>Apply config from YAML file -
kubectl apply -f <directory>/Apply all YAML files in directory -
kubectl diff -f <file.yaml>Preview changes before applying -
kubectl delete -f <file.yaml>Delete resources defined in YAML file -
kubectl get <resource> -o yamlExport resource definition as YAML -
kubectl explain <resource>Show documentation for a resource type
-
https://kubernetes.io/docs/reference/kubectl/Kubernetes kubectl reference: resource operations, configuration, and generated command help.