There are so many frameworks for managing Kubernetes Cluster easily. But still majority of the engineers interact with Kubernetes using the command line client – kubectl. I am listing a set of useful commands that we usually use in Kubernetes. This can be considered as a quick command reference.

If you are interested in learning more details about Kubernetes, you can refer to my previous article “Zero to Kubernetes in 30 minutes”.

Cluster

Command to get the list of nodes in the K8s cluster

kubectl get nodes

Command to get the memory and CPU utilization of the cluster nodes

kubectl top nodes

Command to check the Kubernetes client version and Server version

kubectl version

Command to get the details of a Kubernetes node

kubectl describe node [node-name]

Namespace

We can call namespace using the keywords ns or namespace

Command to list namespaces

kubectl get namespace

Command to describe a namespace

kubectl describe namespace [namespace-name]

Command to create a namespace

kubectl create namespace [namespace-name]

Command to delete a namespace and all objects in the namespace

kubectl delete namespace [namespace-name]

Kubernetes Pod

Command to list all the pods across all namespaces

kubectl get pods --all-namespaces

Command to list all the pods from a specific namespace

kubectl get pods -n [namespace]

Command to list the pods running in the default namespace

kubectl get pods

Command to check the CPU and Memory utilization of pods

kubectl top pods -n [namespace]

if you don’t specify the namespace, the command will list the memory and cpu utilization of the pods in the default namespace

Command to describe a Kubernetes Pod

kubectl describe pod [pod-name]

Command to print the logs from a pod

kubectl logs [pod-name] -n [namespace]

Command to stream the logs from a pod

kubectl logs -f [pod-name] -n [namespace]

Command to enter inside a pod or open the shell of a pod

kubectl exec -it [pod-name] -n [namespace] -- bash

Services

We can call services by using the keyword service or svc

Command to list services

kubectl get service -n [namespace]

Command to describe a service

kubectl describe service [service-name] -n [namespace]

Command to delete a service

kubectl delete service [service-name] -n [namespace]

Deployments

Command to list the deployments

kubectl get deployments -n [namespace]

Command to describe deployment

kubectl describe deployment [deployment] -n [namespace]

Command to delete a deployment

kubectl delete deployment [deployment] -n [namespace]

Volumes

Command to list all Persistent Volumes (PV)

kubectl get pv

Command to list Persistent Volume Claims (PVC)

kubectl get pvc

Command to delete a Persistent Volume (PV)

kubectl delete pv [volume-name]

Command to delete a Persistent Volume Claim (PVC)

kubectl delete pvc [persistent-volume-claim]

Command to describe a Persistent Volume (PV)

kubectl describe pv [persistent-volume-name]

Command to describe a Persistent Volume Claim (PVC)

kubectl describe pvc [persistent-volume-claim]