Kubectl Commands Cheat Sheet

Here you'll find a list of kubectl commands you can use to manage Metric Insights if deployed in Kubernetes. 

  1. 1.) Deploying
  2. 2.) Getting Information
  3. 3.) Getting into Pods with containers
  4. 4.) Getting Logs
  5. 5.) Deleting

1.) Deploying

  • Deploy Metric Insights in the namespace using a configuration file:

kubectl --namespace <MI-namespace> apply -f <configuration-file>.yml 

2.) Getting Information

  •  Get list of all services in the namespace:

kubectl get services -n <MI-namespace>


  • Get list of pods in the namespace:

kubectl get pods -n <MI-namespace>

kubectl get pods -n <MI-namespace> -o wide

kubectl get pods --all-namespaces

kubectl get pods --sort-by='.status.containerStatuses[0].restartCount'

  • Get detailed information about each pod:

kubectl describe pods -n <MI-namespace> -o wide 

  • Get list of events sorted by timestamp: 

kubectl get events --sort-by=.metadata.creationTimestamp


3.) Opening a Bash Shell inside a Pod

  • Open a bash shell for a specific pod:

 kubectl exec -it <pod-ID> -n <MI-namespace> bash  

4.) Getting Logs

  •  See logs for a specific pod: 

kubectl logs <pod-ID> 

kubectl logs -f <pod-ID>


5.) Deleting

  • Deleting pods and services (to generate a new pod):

kubectl -n <MI-namespace> delete pod <pod-ID>

kubectl -n <MI-namespace> delete svc <service-ID>

kubectl -n <MI-namespace> delete pod/svc --all


  • Deleting all resources in the namespace

kubectl -n <MI-namespace> delete -f <configuration-file>.yml