EHi Hello Everyone, I am trying to get the restart time for all the pods in the . . .

Azim Sain:
EHi
Hello Everyone,
I am trying to get the restart time for all the pods in the cluster but it only returns result for first pod in the file.

Step 1) using below I get the pod names to file podNames.txt

kubectl get pods | awk '{print ($1)}' > podNames.txt

step2) in below I am trying to check storage usage of either of folder with names zoo or data

cat podNames.txt | while read in; do echo "$in"; kubectl exec -it "$in" -- df -h | grep -e zoo -e data; done 

So it gives output for only first pod in the podNames.txt file. and give below message in output:

Unable to use a TTY - input is not a terminal or the right kind of file

So I removed (-t) in the command and ran below:

cat podNames.txt | while read in; do echo "$in"; kubectl exec -i "$in" -- df -h | grep -e zoo -e data; done 

This time also same output only for first pod, only the warning message was not displayed.

can anyone help here, as I suspects after running the command inside container the loop gets exit and unable to proceed.

Mouhamadou Moustapha Camara:
hi remove -i option and try again

Azim Sain:
Hi @Mouhamadou Moustapha Camara, appreciate your help.
it gives required output.
thanks a ton buddy.

Mouhamadou Moustapha Camara:
if you need to get the restart time, you can use the following command :

kubectl get pods -o custom-columns=NAME:.metadata.name,STARTED:.status.containerStatuses[*].state.running.startedAt

Azim Sain:
thanks once more, this is helpful !!

unnivkn:
Hi @Azim Sain hope you are using Step 1) with --no-headers else Step 2) won’t work.
kubectl get pods --no-headers | awk ‘{print ($1)}’ > podNames.txt

Azim Sain:
Hey @unnivkn,
was not aware of “–no-headers”, thanks for sharing as this . this helps me reducing one step of piping out to SED to delete first line of headers. I was using below to remove headers
SED ‘1d’ podNames.txt.