我希望在shell脚本中获得秘密的特定字段的值。
从kubectl get secret文档来看,获得秘密的标准方法是以指定的格式以base64编码的值返回整个事件。
因此,要获取bar秘密的foo字段,输出为未编码的字符串,我将执行以下操作:
kubectl get secret foo -o json | jq -r ".data.bar" | base64 --decode那是
foo秘密作为JSON获取jq以从JSON读取bar字段base64解码值只有使用kubectl**?** 才能这样做吗?
或者在POSIX兼容的shell中使用一种优雅的方法,它不依赖于任何依赖项,比如jq。
发布于 2019-08-06 16:48:38
尝尝这个
kubectl get secret foo --template={{.data.bar}} | base64 --decode不需要jq。
发布于 2019-10-12 15:07:37
自Kubernetes 1.11 (参见PR 60755)以来,这应该是可行的:
kubectl get secret foo -o go-template='{{ .data.bar | base64decode }}'
发布于 2020-12-03 08:55:00
kubectl get secret foo -o jsonpath={.data.bar} | base64 --decodehttps://stackoverflow.com/questions/57379081
复制相似问题