Forum Topic

Thanks for your participation and contribution.

Back to Kubernetes

kubectl Cheat Sheet

Post a reply

List of Namespaces

$ kubectl get namespaces

Delete Namespace

kubectl delete namespace cpu-example-ns

Get Deployment details

$ kubectl get deployment -n di-dev --output=json kubectl get deployment -n di-dev

Node Info

$ kubectl get nodes
$ kubectl describe nodes

Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  CPU Requests  CPU Limits  Memory Requests  Memory Limits
  ------------  ----------  ---------------  -------------
  1650m (10%)   1550m (9%)  3525Mi (10%)     3325Mi (10%)
Events:         <none>

Read Container Logs

$ kubectl logs container-abc -n namespace123

Drain Nodes

$ kubectl get nodes $ kubectl drain aks-agentpool-node-name --ignore-daemonsets --delete-local-data

Sort option

kubectl top pod --all-namespaces | sort --reverse --key 4 --numeric

Last updated


Install latest kubectl Version

curl -LO "$(curl -s"
chmod +x ./kubectl 
sudo mv ./kubectl /usr/local/bin/kubectl
kubectl -v --client

Last updated


Rename Contexts

* Get context information (you need the CLUSTER name and AUTHINFO for the next step): 
kubectl config get-contexts <old-context-name> 
* Create new context:
kubectl config set-context <new-context-name> --cluster <cluster-from-old-context> --user <auth-info-from-old-context>
*Delete old context:
kubectl delete-context <old-context-name>

Last updated

1-3 of 3

Reply to this discussion

You cannot edit posts or make replies: You should be logged in before you can post.