Cheat Sheet - Sandeep-K-Khandelwal/CKAD GitHub Wiki
Labels
- Add a label :
kubectl label pod dev3 app=nginx
- Delete the label:
kubectl label pod dev3 app-
- Show labels:
kubectl get pods --show-labels
- List pods with a specific label:
kubectl get pods --selector=app=nginx --show-labels
Annotations:
- Add an annotation :
kubectl annotate pod dev3 app=nginx
Deployment
- Update the image -
kubectl set image deployment webapp nginx=nginx:1.17.4
- Update to a specific version -
kubectl rollout undo deploy webapp --to-revision=3
- Get history of a specific version -
kubectl rollout history deploy webapp --revision=7
- Pause the rollout -
kubectl rollout pause deploy webapp
- Autoscale -
kubectl autoscale deployment webapp --min=2 --max=5 --cpu-percent=80
Job
kubectl create job hello-job --image=busybox --dry-run -o yaml -- echo "Hello I am from job"
Events
kubectl get events --sort-by=.metadata.creationTimestamp
Expose
kubectl expose po nginx --name=svc1 --port=80 --target-port=9376
kubectl expose deployment nginx --name=svc1 --type=LoadBalancer
Set namespace
- We can switch the namespace using the following command -
kubectl config set-context $(kubectl config current-context) --namespace=<namespace_name>