如何使用kubectl和jsonpath将configmap的内容保存到文件中? [英] How to save content of a configmap to a file with kubectl and jsonpath?

查看:183
本文介绍了如何使用kubectl和jsonpath将configmap的内容保存到文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将configmap的内容保存到本地硬盘驱动器上的文件中. Kubectl支持使用JSONPath进行选择,但是我找不到只需要选择文件内容的表达式.

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.

configmap是使用命令创建的

The configmap was created using the command

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

我跑步时

kubectl describe configmap my-configmap

我看到以下输出:

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}"

哪个输出

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

我想要的输出是

{
  "key": "value"
}

JSONPath难题的最后一部分是什么?

What is the last piece of the JSONPath puzzle?

推荐答案

有一个公开的问题中列出了需要解决的有关kubectl(和JSONpath)的列表,其中之一是问题

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.

如何?

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!

这篇关于如何使用kubectl和jsonpath将configmap的内容保存到文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆