I am dealing with Kubernetes on a daily basis. Although I am using the very capable headlamp as GUI tool, sometimes there are moments when it comes to using kubectl after all. Since I am not using it every day, I keep forgetting commands. so therefore I have written down the most important ones below for reference.
Cluster and Context Management
| Command | Comment | 
| kubectl cluster-info | displays cluster endpoints and basic information | 
| kubectl cluster-info dump | displays cluster endpoints and very detailed information | 
| kubectl config get-contexts | lists all defined contexts in the kubeconfig file | 
| kubectl config current-context | shows the currently active context | 
| kubectl config use-context <context-name> | switches the active context to the specified one | 
| kubectl config view | displays the full configuration from the kubeconfig file | 
| kubectl version | prints the version information for both the kubectl client and the Kubernetes server | 
Resource Management
| command | comment | 
| kubectl apply -f <file.yaml> | creates or updates resources from a configuration file | 
| kubectl delete -f <file.yaml> | deletes resources defined in a configuration file | 
| kubectl get all | lists all resources in the current namespace | 
| kubectl get pods | list the pods in the current namespace | 
| kubectl get pods -A | list all pods in all namespaces | 
| kubectl get pods -A -o wide | list all pods in all namespaces with detailed output including host | 
| kubectl get services | list the services in the current namespace | 
| kubectl get services -A | list the services in all namespaces | 
| kubectl get deployments | list the deployments in the current namespace | 
| kubectl get deployments -A | list the deployments in all namespaces | 
| kubectl get ds | list the daemon sets in the current namespace | 
| kubectl get ds -A | list the daemon sets in all namespaces | 
| kubectl get statefulsets | list the stateful sets in the current namespace | 
| kubectl get statefulsets -A | list the stateful sets in all namespaces | 
| kubectl get secrets | list the secrets in the current namespace | 
| kubectl get secrets -A | list the secrets in all namespaces | 
| kubectl get nodes | list all nodes | 
| kubectl get configmaps | list the config maps in the current namespace | 
| kubectl get configmaps -A | list the config maps in all namespaces | 
| kubectl get <resource> -l <label> | filters resources by a specific label | 
| kubectl get <resource> –all-namespaceskubectl get <resource> -A | lists resources in all namespaces | 
| kubectl get <resource> -n <namespace> | lists resources in a specific namespace | 
| kubectl get <resource> –sort-by=<field> | sorts the output by a specified field, such as `status.containerStatuses.restartCount` | 
Seen my other posts about Kubernetes?
– create-a-configuration-backup-with-kubectl
– kubernetes-quickie-extract-the-ca-bundle
Pod Management
| command | comment | 
| kubectl get pods | lists all pods in the current namespace | 
| kubectl get pods -n <namespace> | lists pods in the specified namespace | 
| ubectl describe pod <pod-name> -n <namespace> | describes specified pod in the specified namespace including status, events, and container details | 
| kubectl logs <pod-name> | streams logs from a pod’s container | 
| kubectl logs -f <pod-name> | follows the logs in real-time | 
| kubectl logs -p <pod-name> | retrieves logs from a previous container instance | 
| kubectl logs -l <label> | gets logs for pods matching a label selector | 
| kubectl exec -it <pod-name> — /bin/sh | starts an interactive shell session inside a pod | 
| kubectl exec <pod-name> -c <container-name> — <command> | executes a command in a specific container within a pod | 
| kubectl run <pod-name> –image=<image> | creates and runs a pod with the specified image | 
| kubectl delete pod <pod-name> | deletes a specific pod | 
| kubectl delete pod <pod-name> –force –grace-period=0 | deletes a specific pod forcefully and without grace from the API server | 
Deployment Management
| command | comment | 
| kubectl create deployment <name> –image=<image> | creates a new deployment using the specified image | 
| kubectl get deployments | lists all deployments in the current namespace | 
| kubectl get deployments -n <namespace> | lists all deployments in the specified namespace | 
| kubectl describe deployment <name> | provides detailed information about a deployment | 
| kubectl scale deployment <name> –replicas=<number> | adjusts the number of replicas for a deployment | 
| kubectl set image deployment/<name> <container>=<image> | updates the container image in a deployment | 
| kubectl rollout restart deployment/<name>` | rolling restarts a deployment | 
| kubectl rollout status deployment/<name> | monitors the rollout status of a deployment | 
| kubectl rollout pause deployment/<name> | pauses a deployment rollout | 
| kubectl rollout resume deployment/<name> | resumes a paused rollout | 
| kubectl rollout undo deployment/<name> | reverts the deployment to the previous revision | 
| kubectl rollout undo deployment/<name> –to-revision=<revision> | rolls back to a specific revision | 
| kubectl delete deployment <name> | deletes a deployment and its managed pods | 
Service Management
| command | comment | 
| kubectl get services | lists all services in the current namespace | 
| kubectl get services -A | lists all services in all namespaces | 
| kubectl get services -n <namespace> | lists all services in specified namespace | 
| kubectl expose deployment <name> –port=<port> | creates a service that exposes a deployment | 
| kubectl create service <type> –tcp=<port> | creates a new service of a specified type (e.g., ClusterIP, NodePort) | 
| kubectl describe service <name> | provides detailed information about a service | 
| kubectl delete service <name> | removes a service from the cluster | 
| kubectl get endpoints <name> | lists the endpoints (pod IPs) backing a service | 
Node Management
| command | comment | 
| kubectl get nodes | lists all nodes in the cluster | 
| kubectl describe node <node-name> | provides detailed node-level information, including resource pressure and taints | 
| kubectl cordon <node-name> | marks a node as unschedulable | 
| kubectl uncordon <node-name>` | marks a node as schedulable again | 
| kubectl drain <node-name> | prepares a node for maintenance by evicting all pods | 
| kubectl label node <node-name> <key>=<value> | adds or updates a label on a node | 
| kubectl label node <node-name> <key>- | removes a label from a node | 
| kubectl taint node <node-name> <key>=<value>:<effect> | applies a taint to a node | 
| kubectl top node <node-name> | displays resource usage metrics (CPU and memory) for a node | 
Debugging and Monitoring
| command | comment | 
| kubectl get events | lists cluster events, useful for troubleshooting | 
| kubectl get componentstatuses | checks the status of cluster components | 
| kubectl port-forward <pod-name> 8080:80 | forwards a local port to a pod’s port for local access | 
| kubectl debug <pod-name> -it –image=<image> | enables debugging by launching a shell in a new container | 
Best Practices
– Use namespaces to isolate environments, teams, or applications
– Apply labels and annotations to resources for easier management and filtering
– Use declarative configurations (YAML files) with `kubectl apply` to define desired states
– Set resource requests and limits on containers to prevent overprovisioning or starvation
In case I am losing this blog post, I have it written down in my wiki too for good measure.