In order to changes to the cluster, you have to talk with API server. To do that, you can use UI, API or CLI, which is kubectl.

  • It can be used for any cluster like cloud, minikube etc.
kubectl CommandAction
run NAME —image=nginxQuickly run a pod without manifest
port-forward NAME LOCALPORT:CTPORT
exec -it NAME — shInteractive shell to container
kubectl cp LOCALFILE REMOTE:RFILE
get RESOURCE
- kubectl get podsShows the pods
- kubectl get pods -n kube-systemShow pods in kube-system namespace
- kubectl get namespaceShow namespaces
apply | delete -f FILE [—all]Apply the YAML file, like creating a file.
describe RESOURCE RESOURCE_NAME
- kubectl describe pod my_podGive detailed info about an object
delete RESOURCE RESOURCE_NAME
create ns NAMESPACE_NAMECreate namespace
kubectl top {pods | nodes}Get usage metrics from objects
kubectl logs demo-podShow logs
kubectl get pods -L LABELShow the label as a separate column

Scale & Deployment

kubectl CommandAction
kubectl scale deploy demo-deploy —replicas 3
kubectl get deploy
kubectl create deployment demo-deploy —image=nginx

Rollout & History

kubectl rollout history deploy demo-deployment show history kubectl rollout undo deploy demo-deployment roll back to the previous version