How to access kubernetes keys with hyphen and slashes (labels/annotations)?

9/24/2019

I want to check whether the all labels/annotations in a set of secrets have been changed. Unfortunately the key to check has a hyphen in it and I have no idea how to access it.

I tried:

kubectl get secret -o custom-columns=NAME:metadata.name,ANNOTATIONS:metadata.annotations['k8s.key/with-hyphen']
kubectl get secret -o go-template --template='{{ range .items }}{{ .metadata.annotations['k8s.key/with-hyhen'] }}{{ end }}'
kubectl get secret -o custom-columns=NAME:metadata.name,ANNOTATIONS:metadata.annotations."k8s.key/with-hyphen"
kubectl get secret -o custom-columns=NAME:metadata.name,ANNOTATIONS:metadata.annotations.k8s.key/with-hyphen
-- Moritz Schmitz v. Hülst
go-templates
jmespath
jsonpath
kubectl
kubernetes

0 Answers