I love using kubectl ... -o jsonpath
but I cannot figure out how to print an annotation that contains a special character like -
or /
or .
.
This does not work:
kubectl get pods tmp -o 'jsonpath={.metadata.annotations.kubernetes.io/created-by}{"\n"}'
nor this:
kubectl get pods tmp -o 'jsonpath={.metadata.annotations.kubernetes\.io\/created\-by}{"\n"}'
nor this:
kubectl get pods tmp -o 'jsonpath={.metadata.annotations}{["kubernetes.io/created-by"]}{"\n"}'
nor this:
kubectl get pods tmp-1986694738-dhpx0 -o jsonpath="{\$['metadata']['annotations']['kubernetes.io/created-by']}"
(the last one should work according to what I can find about jsonPath, but doesn't, and anyhow is hard to get shell escaping right for.
Need a way to quote a
A use case for this is extracting "created-by" or "init-container" annotations. I've wanted to do both in the last month and fought jsonpath.
FYI, this is possible with go-template. We should still fix the jsonpath though.
kubectl get pods tmp -o go-template=$'{{index .metadata.annotations "kubernetes.io/created-by"}}\n'
Similar issue: https://github.com/kubernetes/kubernetes/issues/23386
Most helpful comment
FYI, this is possible with go-template. We should still fix the jsonpath though.
Similar issue: https://github.com/kubernetes/kubernetes/issues/23386