0

I set label "mytime" in timestemp format for my pod. Now i want select all pods with expired time? some think like this:

kubectl get pods -o jsonpath='{range .items[*]}{.metadata.labels.mytime<$now()}{.metadata.name}{ "\n"}{end}'

but i see error

error: error executing jsonpath "{range .items[*]}{.metadata.labels.mytime<$now()}{.metadata.name}{ \"\\n\"}{end}": Error executing template: unrecognized identifier now(). Printing more information for debugging the template:
        template was:
                {range .items[*]}{.metadata.creationTimestamp>$now()}{.metadata.name}{ "\n"}{end}
        object given to jsonpath engine was: ...

how use time in condition?

Tim
  • 155
  • 1
  • 3
  • 13

2 Answers2

0
kubectl -n test get deployment -o jsonpath='{.items[?(@.metadata.labels.mytime<"2020-10-08_14-15-07")].metadata.name}'
4b0
  • 21,981
  • 30
  • 95
  • 142
Tim
  • 155
  • 1
  • 3
  • 13
0

This did the trick for me:

I couldn't get the result with now, may be due to the difference in format.

kubectl get pods -o=jsonpath="{range .items[?(@.metadata.labels.mytime<=\"2022-12-19\")]}[{.metadata.labels.mytime},{.metadata.namespace},{.metadata.name}] {end}"