Kubernetes Useful Commands

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

LinkedIn

 

Published by Ramasankar

As a Principal Cloud Architect with over 18 years of experience, I am dedicated to revolutionizing IT landscapes through cutting-edge cloud solutions. My expertise spans Cloud Architecture, Security Architecture, Solution Design, Cloud Migration, Database Transformation, Development, and Big Data Analytics.Currently, I spearhead cloud initiatives with a focus on Infrastructure, Containerization, Security, Big Data, Machine Learning, and Artificial Intelligence. I collaborate closely with development teams to architect, build, and manage robust cloud ecosystems that drive business growth and technological advancement.Core Competencies: • Cloud Platforms: AWS, Google Cloud Platform, Microsoft Azure • Technologies: Kubernetes, Serverless Computing, Microservices • Databases: MS SQL Server, PostgreSQL, Oracle, MongoDB, Amazon Redshift, DynamoDB, Aurora • Industries: Finance, Retail, Manufacturing. Throughout my career, I’ve had the privilege of working with industry leaders such as OCC, Gate Gourmet, Walgreens, and Johnson Controls, gaining invaluable insights across diverse sectors.As a lifelong learner and knowledge sharer, I take pride in being the first in my organization to complete all major AWS certifications. I am passionate about mentoring and guiding fellow professionals in their cloud journey, fostering a culture of continuous learning and innovation.Let’s connect and explore how we can leverage cloud technologies to transform your business: • LinkedIn: https://www.linkedin.com/in/ramasankar-molleti-23b13218/ • Book a mentorship session: [1:1] Together, let’s architect the future of cloud computing and drive technological excellence. Disclaimer The views expressed on this website/blog are mine alone and do not reflect the views of my company. All postings on this blog are provided “AS IS” with no warranties, and confers no rights. The owner of https://ramasankarmolleti.com will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.

Leave a comment