I have been using kubernetes over 3 years and would like to write a blog to provide useful commands
How to get currently running pods?
kubectl get pods (default namespace)
kubectl get pods –all-namespaces
kubectl get pods -o wide , kubectl get pods -all-namespaces -o wide (This will display more details of the pods)
How to view the pod details ?
kubectl describe pod pod_name (Default namespace)
kubectl describe pod pod_name -n xyz (xyz namespace)
Note: pod_name is the name of the pod
How many nodes do you see in the cluster?
kubectl get nodes
kubectl get nodes –all-namespaces
How to get deployments?
default namespace:
kubectl get deployments
on xyz namspace:
kubectl get deploymenets -n xyz
or
kubectl get deployments –namespace xyz
How to empty the node of all pods/applications and mark it unschedulable?
kubectl drain node01
If you want the node to be unschedulable and do not want to remove any apps currently running on node then you need to use cordon
kubectl cordon node01
How to configure the node to be scheduled again ?
kubectl uncordon node01
how to see certificate?
kubectl get crt
how to check access?
kubectl auth can-i create deployments
kubectl auth can-i delete nodes
kubectl auth can-i create deployments –as username
kubectl auth can-i delete nodes –as username
How to find roles details?
kubectl get roles (default namespace)
kubectl get nodes -n xyz ( Particular xyz namespace)
kubectl get roles –all-namespaces (All namespaces)
How to find details of access granted to the role named “developer”?
kubectl describe role developer (default namespace)
kubectl describe role developer -n xyz ( xyz namespace)
How to see which account the role developer assigned to on xyz namespace?
kubectl describe rolebinding weave-net -n xyz
How to find cluster roles?
kubectl get clusterroles
How to find clusterrole bindings?
kubectl get clusterrolebindings
How to check networkpolicies defined in the cluster?
kubectl get networkpolicy
How to check the details of networkpolicy attached to cluster?
kubectl describe networkpolicy
How to see the status of persistence volume claim?
kubectl get persistentvolumeclaim
How to get the status of the persistent volume?
kubectl get pvc
How to verify recliam policy set on persistent volume?
kubectl get pv
How to delete persistent volume claim?
kubectl delete pvc clam_name
Note: claim_name is the name of the persistent volume claim
I will continue to add more in this blog.
Hope you enjoyed the post.
Cheers
Ramasankar Molleti