英文:
Create nested ConfigMap from kubectl
问题
我有一个配置需要从kubectl应用,但我不太明白它是什么:
apiVersion: v1
kind: ConfigMap
data:
localHosting.v1: |
host: "localhost:1234"
containerHost: "container-name:5555"
我无法弄清楚如何使用 kubectl create configmap
命令来创建这个 ConfigMap。我以为 ConfigMaps 只是键值对,而 --from-literal
标志的使用似乎期望的是键值对,但这个配置似乎有额外的嵌套层级。
我知道通常你可以创建一个YAML文件或使用heredoc将整个YAML文件传递给kubectl,但在我的情况下这不是一个很好的解决方案。是否有一种方法可以构建 kubectl create configmap
命令来执行这个操作?
英文:
I have a config I need to apply from kubectl, but I don't quite understand what it is:
apiVersion: v1
kind: ConfigMap
data:
localHosting.v1: |
host: "localhost:1234"
containerHost: "container-name:5555"
I can't figure out how to make this configmap using a kubectl create configmap
invocation though. I thought that ConfigMaps were just key-value pairs, and the usage of the --from-literal
flag seems to expect that, but this config seems to have an additional level of nesting.
I know you could typically create a YAML file or pipe in the whole YAML file using a heredoc, but that's not a very good solution in my situation. Is there a way to craft kubectl create configmap
command to do this?
答案1
得分: 2
They are just key-value pairs. In your example, localHosting.v1
is the key, and the string...
host: "localhost:1234"
containerHost: "container-name:5555"
...is the value. You can create this from the command line by running something like:
kubectl create cm myconfigmap '--from-literal=localHosting.v1=host: "localhost:1234" containerHost: "container-name:5555"'
Which results in:
$ kubectl get cm myconfigmap -o yaml
apiVersion: v1
data:
localHosting.v1: |
host: "localhost:1234"
containerHost: "container-name:5555"
kind: ConfigMap
metadata:
creationTimestamp: "2023-07-14T02:28:14Z"
name: myconfigmap
namespace: sandbox
resourceVersion: "57813424"
uid: a126c38f-6836-4875-9a1b-7291910b7490
As with any other shell command, we use single quotes ('
) to quote a multi-line string value.
英文:
> I thought that ConfigMaps were just key-value pairs...
They are just key-value pairs. In your example, localHosting.v1
is the key, and the string...
host: "localhost:1234"
containerHost: "container-name:5555"
...is the value. You can create this from the command line by running something like:
kubectl create cm myconfigmap '--from-literal=localHosting.v1=host: "localhost:1234"
containerHost: "container-name:5555
'
Which results in:
$ kubectl get cm myconfigmap -o yaml
apiVersion: v1
data:
localHosting.v1: |
host: "localhost:1234"
containerHost: "container-name:5555
kind: ConfigMap
metadata:
creationTimestamp: "2023-07-14T02:28:14Z"
name: myconfigmap
namespace: sandbox
resourceVersion: "57813424"
uid: a126c38f-6836-4875-9a1b-7291910b7490
As with any other shell command, we use single quotes ('
) to quote a multi-line string value.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论