10 kubectl Commands Every Kubernetes Developer Must Know
Whether you’re preparing for a Kubernetes certification or just want to be more productive, mastering kubectl is essential. Here are the 10 commands that will make you a Kubernetes power user.
1. kubectl get - View Resources
# Get all pods in current namespace
kubectl get pods
# Get pods in all namespaces
kubectl get pods -A
# Get pods with more details
kubectl get pods -o wide
# Watch pods in real-time
kubectl get pods -w2. kubectl describe - Detailed Information
# Describe a specific pod
kubectl describe pod my-pod
# Describe a node
kubectl describe node worker-13. kubectl run - Quick Pod Creation
# Create a pod quickly
kubectl run nginx --image=nginx
# Create with dry-run to generate YAML
kubectl run nginx --image=nginx --dry-run=client -o yaml > pod.yaml4. kubectl create - Create Resources
# Create a deployment
kubectl create deployment nginx --image=nginx --replicas=3
# Create a service
kubectl create service clusterip my-svc --tcp=80:805. kubectl apply - Declarative Management
# Apply a configuration file
kubectl apply -f deployment.yaml
# Apply all files in a directory
kubectl apply -f ./manifests/6. kubectl logs - View Container Logs
# View pod logs
kubectl logs my-pod
# Follow logs in real-time
kubectl logs -f my-pod
# View logs from a specific container
kubectl logs my-pod -c sidecar7. kubectl exec - Execute Commands
# Execute a command in a pod
kubectl exec my-pod -- ls /app
# Get an interactive shell
kubectl exec -it my-pod -- /bin/bash8. kubectl port-forward - Local Access
# Forward local port to pod
kubectl port-forward pod/my-pod 8080:80
# Forward to a service
kubectl port-forward svc/my-svc 8080:809. kubectl config - Context Management
# View current context
kubectl config current-context
# Switch context
kubectl config use-context my-cluster
# List all contexts
kubectl config get-contexts10. kubectl explain - Built-in Documentation
# Get documentation for a resource
kubectl explain pod
# Get specific field documentation
kubectl explain pod.spec.containers.resourcesBonus: Speed Up Your Workflow
Add these to your ~/.bashrc:
alias k=kubectl
alias kgp='kubectl get pods'
alias kgs='kubectl get svc'
alias kgd='kubectl get deploy'
source <(kubectl completion bash)
complete -F __start_kubectl kPractice These Commands
Reading about commands isn’t enough—you need hands-on practice. Sailor.sh provides real Kubernetes clusters where you can practice these commands in exam-like conditions. Start your free practice session today!