Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script to continuously follow kubectl get pods

I'm trying to build a script that can follow(-f) kubectl get pods see a realtime update when I make any changes/delete pods on Ubuntu server.

What could be the easiest/efficient way to do so?

like image 879
Swapnil Patel Avatar asked Nov 26 '18 16:11

Swapnil Patel


People also ask

How do you find the continuous log in kubectl?

Thankfully, the kubectl command lets you look at deployments as well. The command takes a flag (-l / –selector) that lets you filter by label. Since we tag our deployment pods with the example label, we can see all of them. The -f / –follow flag then continuously prints out the message from those pods.

What is the command to get all the pods running in the cluster?

To check the version, enter kubectl version . In this exercise you will use kubectl to fetch all of the Pods running in a cluster, and format the output to pull out the list of Containers for each.


1 Answers

You can just use

kubectl get pod <your pod name> -w

whenever any update/change/delete happen to the pod, you will see the update.

You can also use

watch -n 1 kubectl get  pod <your pod name>

This will continuously run kubectl get pod ... with 1 seconds interval. So, you will see latest sate.

like image 72
Emruz Hossain Avatar answered Sep 20 '22 12:09

Emruz Hossain