Swapnil Patel
Swapnil Patel

Reputation: 907

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?

Upvotes: 46

Views: 54136

Answers (2)

Emruz Hossain
Emruz Hossain

Reputation: 5558

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 state.

Upvotes: 95

Faramarz Qoshchi
Faramarz Qoshchi

Reputation: 1652

Adding a -w or --watch to all your kubectl get [resource]s command makes the result notified of each creation, modification, or deletion of that resource.
i.e kubectl get pod [pod_name] -w or kubectl get nodes --watch

Upvotes: 10

Related Questions