Join our Discord Server
Collabnix Team The Collabnix Team is a diverse collective of Docker, Kubernetes, and IoT experts united by a passion for cloud-native technologies. With backgrounds spanning across DevOps, platform engineering, cloud architecture, and container orchestration, our contributors bring together decades of combined experience from various industries and technical domains.

Kubectl Quick Reference 2025

3 min read

Kubectl is the command-line interface for interacting with Kubernetes clusters. It allows you to deploy applications, inspect and manage cluster resources, and view logs. This cheatsheet provides a comprehensive reference of commonly used kubectl commands, organized by operation type.

Whether you’re new to Kubernetes or an experienced administrator, this guide will help you quickly find the right command for your task. Commands are presented with their descriptions and practical examples to make your Kubernetes workflow more efficient.

Cluster Management Commands

CommandDescriptionExample
kubectl cluster-infoDisplay cluster infokubectl cluster-info
kubectl versionShow kubectl and cluster versionkubectl version
kubectl config viewShow kubeconfig settingskubectl config view
kubectl config current-contextDisplay current contextkubectl config current-context
kubectl config use-context <context>Switch to another contextkubectl config use-context minikube
kubectl config set-contextSet a context parameterkubectl config set-context --current --namespace=myapp
kubectl api-resourcesList supported API resourceskubectl api-resources

Namespace Operations

CommandDescriptionExample
kubectl get namespacesList all namespaceskubectl get ns
kubectl create namespaceCreate a namespacekubectl create ns app-dev
kubectl delete namespaceDelete a namespacekubectl delete ns app-dev
kubectl config set-context --current --namespace=<ns>Set default namespacekubectl config set-context --current --namespace=app-dev

Pod Operations

CommandDescriptionExample
kubectl get podsList all pods in current namespacekubectl get pods
kubectl get pods --all-namespacesList pods in all namespaceskubectl get pods -A
kubectl get pods -o wideList pods with more detailskubectl get pods -o wide
kubectl describe pod <pod-name>Show detailed pod informationkubectl describe pod nginx-pod
kubectl run <name> --image=<image>Create and run a podkubectl run nginx --image=nginx
kubectl delete pod <pod-name>Delete a podkubectl delete pod nginx-pod
kubectl logs <pod-name>Get pod logskubectl logs nginx-pod
kubectl logs -f <pod-name>Stream pod logskubectl logs -f nginx-pod
kubectl logs <pod-name> -c <container>Get container logs from multi-container podkubectl logs webapp -c auth-service
kubectl exec -it <pod-name> -- <command>Execute command in podkubectl exec -it nginx-pod -- /bin/bash
kubectl port-forward <pod-name> <local-port>:<pod-port>Forward pod port to localkubectl port-forward nginx-pod 8080:80

Deployment Operations

CommandDescriptionExample
kubectl get deploymentsList all deploymentskubectl get deploy
kubectl describe deployment <name>Show deployment detailskubectl describe deploy nginx-deploy
kubectl create deployment <name> --image=<image>Create a deploymentkubectl create deploy nginx --image=nginx
kubectl scale deployment <name> --replicas=<count>Scale a deploymentkubectl scale deploy nginx --replicas=5
kubectl rollout status deployment <name>Check rollout statuskubectl rollout status deploy nginx
kubectl rollout history deployment <name>View rollout historykubectl rollout history deploy nginx
kubectl rollout undo deployment <name>Rollback deploymentkubectl rollout undo deploy nginx
kubectl rollout restart deployment <name>Restart deployment (for image refresh)kubectl rollout restart deploy nginx
kubectl set image deployment/<name> <container>=<image>Update container imagekubectl set image deployment/nginx nginx=nginx:latest
kubectl delete deployment <name>Delete a deploymentkubectl delete deploy nginx

Service Operations

CommandDescriptionExample
kubectl get servicesList all serviceskubectl get svc
kubectl describe service <name>Show service detailskubectl describe svc nginx-service
kubectl expose deployment <name> --port=<port> --type=<type>Create a service for deploymentkubectl expose deploy nginx --port=80 --type=LoadBalancer
kubectl delete service <name>Delete a servicekubectl delete svc nginx-service

ConfigMap and Secret Operations

CommandDescriptionExample
kubectl get configmapsList all configmapskubectl get cm
kubectl get secretsList all secretskubectl get secrets
kubectl create configmap <name> --from-file=<path>Create configmap from filekubectl create cm app-config --from-file=config.properties
kubectl create configmap <name> --from-literal=<key>=<value>Create configmap from literalkubectl create cm app-config --from-literal=api.url=https://api.example.com
kubectl create secret generic <name> --from-literal=<key>=<value>Create secret from literalkubectl create secret generic db-creds --from-literal=password=s3cr3t
kubectl describe configmap <name>Show configmap detailskubectl describe cm app-config
kubectl describe secret <name>Show secret detailskubectl describe secret db-creds

Persistent Volume Operations

CommandDescriptionExample
kubectl get persistentvolumesList persistent volumeskubectl get pv
kubectl get persistentvolumeclaimsList persistent volume claimskubectl get pvc
kubectl describe persistentvolumeclaim <name>Show PVC detailskubectl describe pvc mysql-pvc
kubectl delete persistentvolumeclaim <name>Delete a PVCkubectl delete pvc mysql-pvc

Node Operations

CommandDescriptionExample
kubectl get nodesList all nodeskubectl get nodes
kubectl describe node <node-name>Show node detailskubectl describe node worker-1
kubectl cordon <node-name>Mark node as unschedulablekubectl cordon worker-1
kubectl uncordon <node-name>Mark node as schedulablekubectl uncordon worker-1
kubectl drain <node-name>Drain node in preparation for maintenancekubectl drain worker-1 --ignore-daemonsets
kubectl taint nodes <node-name> <key>=<value>:<effect>Add a taint to nodekubectl taint nodes worker-1 gpu=true:NoSchedule

Resource Management

CommandDescriptionExample
kubectl top nodesShow CPU/Memory usage for nodeskubectl top nodes
kubectl top podsShow CPU/Memory usage for podskubectl top pods
kubectl get eventsShow events in the clusterkubectl get events
kubectl get allShow all resourceskubectl get all

YAML Generation

CommandDescriptionExample
kubectl create deployment <name> --image=<image> --dry-run=client -o yamlGenerate deployment YAMLkubectl create deploy nginx --image=nginx --dry-run=client -o yaml > deploy.yaml
kubectl run <name> --image=<image> --dry-run=client -o yamlGenerate pod YAMLkubectl run nginx --image=nginx --dry-run=client -o yaml > pod.yaml
kubectl expose deployment <name> --port=<port> --dry-run=client -o yamlGenerate service YAMLkubectl expose deploy nginx --port=80 --dry-run=client -o yaml > svc.yaml

Apply and Diff

CommandDescriptionExample
kubectl apply -f <file.yaml>Create/update resource from filekubectl apply -f deploy.yaml
kubectl apply -f <directory>Create/update from all files in directorykubectl apply -f ./configs
kubectl diff -f <file.yaml>Show difference with live configurationkubectl diff -f deploy.yaml
kubectl delete -f <file.yaml>Delete resources from filekubectl delete -f deploy.yaml

Context Switching

CommandDescriptionExample
kubectl config get-contextsList all contextskubectl config get-contexts
kubectl config current-contextShow current contextkubectl config current-context
kubectl config use-context <context>Switch to contextkubectl config use-context prod-cluster
kubectl config rename-context <old> <new>Rename contextkubectl config rename-context gke_proj_zone_name prod

Common Flags

FlagDescriptionExample
-n, --namespaceSpecify namespacekubectl get pods -n kube-system
-A, --all-namespacesAll namespaceskubectl get pods -A
-o, --outputOutput format (yaml/json/wide/custom)kubectl get pod nginx -o yaml
--watch, -wWatch for changeskubectl get pods -w
--selector, -lFilter by labelkubectl get pods -l app=nginx
--field-selectorFilter by fieldkubectl get pods --field-selector status.phase=Running
--sort-bySort outputkubectl get pods --sort-by=.metadata.creationTimestamp

Advanced Operations

CommandDescriptionExample
kubectl auth can-i <verb> <resource>Check permissionskubectl auth can-i create deployments
kubectl explain <resource>Get documentationkubectl explain pods.spec.containers
kubectl get componentstatusesCheck component healthkubectl get cs
kubectl wait --for=condition=<condition> <resource>Wait for conditionkubectl wait --for=condition=Ready pod/nginx
kubectl patch <resource> <name> -p '<patch>'Patch resourcekubectl patch deploy nginx -p '{"spec":{"replicas":3}}'
kubectl kustomize <dir>Print kustomizationkubectl kustomize ./overlay/dev

Have Queries? Join https://launchpass.com/collabnix

Collabnix Team The Collabnix Team is a diverse collective of Docker, Kubernetes, and IoT experts united by a passion for cloud-native technologies. With backgrounds spanning across DevOps, platform engineering, cloud architecture, and container orchestration, our contributors bring together decades of combined experience from various industries and technical domains.
Join our Discord Server
Index