Kubernetes Cheatsheet

A quick reference for common Kubernetes (kubectl) commands.

Cluster Management

Command Description
kubectl config view Display the current context.
kubectl config use-context [context-name] Switch to a different context.
kubectl cluster-info Display information about the cluster.
kubectl get nodes List all nodes in the cluster.

Debugging

Command Description
kubectl exec -it [pod-name] -- /bin/sh Execute a shell inside a running pod.
kubectl port-forward [pod-name] [local-port]:[pod-port] Forward a local port to a port on a pod.
kubectl top pod Display CPU and memory usage for pods.
kubectl get events --sort-by='.lastTimestamp' List recent events in the cluster.

Deleting Resources

Command Description
kubectl delete -f [file.yaml] Delete resources defined in a YAML file.
kubectl delete pod [pod-name] Delete a pod.
kubectl delete deployment [deployment-name] Delete a deployment.
kubectl delete service [service-name] Delete a service.

Deploying Applications

Command Description
kubectl apply -f [file.yaml] Create or update resources from a YAML file.
kubectl create deployment [name] --image=[image] Create a new deployment.
kubectl expose deployment [name] --port=[port] --type=LoadBalancer Expose a deployment as a new service.
kubectl scale deployment [name] --replicas=[count] Scale the number of pods in a deployment.

Viewing Resources

Command Description
kubectl get pods List all pods in the current namespace.
kubectl get pods -n [namespace] List all pods in a specific namespace.
kubectl get all List all resources in the current namespace.
kubectl describe pod [pod-name] Show detailed information about a pod.
kubectl logs [pod-name] Print the logs for a pod.
kubectl logs -f [pod-name] Stream the logs for a pod.

© 2025 devcortex.ai ・ AI-powered developer tools.