How to save content of a configmap to a file with kubectl and jsonpath?

自作多情 提交于 2020-06-11 20:11:24

问题


I'm trying to save the contents of a configmap to a file on my local hard drive. Kubectl supports selecting with JSONPath but I can't find the expression I need to select just the file contents.

The configmap was created using the command

kubectl create configmap my-configmap --from-file=my.configmap.json=my.file.json

When I run

kubectl describe configmap my-configmap

I see the following output:

Name:         my-configmap 
Namespace:    default 
Labels:       <none> 
Annotations:  <none>

Data
==== 
my.file.json:
---- 
{
    "key": "value" 
} 
Events:  <none>

The furthest I've gotten so selecting only the file contents is this:

 kubectl get configmap my-configmap -o jsonpath="{.data}"

Which outputs

map[my.file.json:{
    "key": "value"
}]

The output that I want is

{
  "key": "value"
}

What is the last piece of the JSONPath puzzle?


回答1:


There’s an open issue at the Kubernetes GitHub repo with a list of things that needs to be fixed in regards to kubectl (and JSONpath), one of them are issue 16707 jsonpath template output should be json.

Edit:

How about this:

kubectl get cm my-configmap -o jsonpath='{.data.my\.file\.json}'

I just realized i had answered another question related (kind of) to this one. The above command should output what you had in mind!



来源:https://stackoverflow.com/questions/51768988/how-to-save-content-of-a-configmap-to-a-file-with-kubectl-and-jsonpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!