kubectl Basics
| Command | Description |
|---|---|
kubectl get pods | List Pods |
kubectl get pods -A | List Pods in all Namespaces |
kubectl get services | List Services |
kubectl get deployments | List Deployments |
kubectl get nodes | List Nodes |
kubectl get all | List all resources |
Pod Operations
| Command | Description |
|---|---|
kubectl describe pod <name> | Show Pod details |
kubectl logs <pod> | Show logs |
kubectl logs -f <pod> | Follow logs |
kubectl exec -it <pod> -- sh | Execute shell in container |
kubectl delete pod <name> | Delete a Pod |
kubectl port-forward <pod> 8080:80 | Port forward |
Resource Creation & Application
| Command | Description |
|---|---|
kubectl apply -f <file.yaml> | Apply a manifest |
kubectl create -f <file.yaml> | Create a resource |
kubectl delete -f <file.yaml> | Delete a resource |
kubectl edit <resource> <name> | Edit a resource |
Deployment
| Command | Description |
|---|---|
kubectl scale deployment <name> --replicas=3 | Scale |
kubectl rollout status deployment/<name> | Rollout status |
kubectl rollout history deployment/<name> | Rollout history |
kubectl rollout undo deployment/<name> | Rollback |
Namespace
| Command | Description |
|---|---|
kubectl get namespaces | List Namespaces |
kubectl create namespace <name> | Create Namespace |
kubectl config set-context --current --namespace=<ns> | Change default NS |
Debugging
| Command | Description |
|---|---|
kubectl describe <resource> <name> | Show details |
kubectl get events | List events |
kubectl top pods | Show Pod resource usage |
kubectl top nodes | Show Node resource usage |