
# ccictl create configmap
#### 操作背景
基于文件、目录或指定的文字值创建 ConfigMap。
一个 ConfigMap 可以包含一个或多个键/值对。
当您基于文件创建 ConfigMap 时，键默认为文件的基本名称，值默认为文件内容。 如果基本名称是无效的键，您可以指定一个替代键。
当基于目录创建 ConfigMap 时，目录中每个基本名称是有效键的文件都会被打包到 ConfigMap 中。 除常规文件之外的所有目录条目都会被忽略（例如子目录、符号链接、设备、管道等）。
```
ccictl create configmap NAME [--from-file=[key=]source] [--from-literal=key1=value1]
```
#### 示例
```
# 基于 bar 文件夹新建一个名为 my-config 的 ConfigMap
ccictl create configmap my-config --from-file=path/to/bar
# 新建一个名为 my-config 的 ConfigMap，使用指定的键而不是磁盘上的文件基本名称
ccictl create configmap my-config --from-file=key1=/path/to/bar/file1.txt --from-file=key2=/path/to/bar/file2.txt
# 新建一个名为 my-config 的 ConfigMap，包含 key1=config1 和 key2=config2
ccictl create configmap my-config --from-literal=key1=config1 --from-literal=key2=config2
# 从文件中的 key=value 对新建一个名为 my-config 的 ConfigMap
ccictl create configmap my-config --from-file=path/to/bar
# 从 env 文件新建一个名为 my-config 的 ConfigMap
ccictl create configmap my-config --from-env-file=path/to/foo.env --from-env-file=path/to/bar.env
```
#### 选项
```
--allow-missing-template-keys     默认值：true
```
如果为 true，在模板中字段或映射键缺失时忽略模板中的错误。 仅适用于 golang 和 jsonpath 输出格式。
```
--append-hash
```
将 Configmap 的哈希值追加到它的名称上。
```
--from-env-file strings
```
指定文件路径以读取 key=val 对的行来创建一个 Configmap 。
```
--from-file strings
```
键文件可以使用其文件路径来指定，在这种情况下，文件的基本名称将用作 ConfigMap 的键。 另外，键文件也可以选择使用键和文件路径来指定，在这种情况下，将使用指定的键。 指定一个目录将遍历此目录中所有被命名的文件（其基本名称为有效的 ConfigMap 键）。
```
--from-literal strings
```
指定键和文字值以插入到 ConfigMap 中（例如 mykey=somevalue）。
```
-h, --help
```
configmap 操作的帮助命令。
```
-o, --output string
```
输出格式。可选值为： json、yaml、name、go-template、go-template-file、template、templatefile、jsonpath、jsonpath-as-json、jsonpath-file。
```
--save-config
```
如果为 true，当前对象的配置将被保存在其注解中。否则，注解将保持不变。 此标志在您希望后续对该对象执行 ccictl apply 时很有用。
```
--template string
```
当 -o=go-template、-o=go-template-file 时使用的模板字符串或模板文件路径。 模板格式为 golang 模板 \[http://golang.org/pkg/text/template/#pkg-overview\]。
**ccictl选项亦可在子命令中生效，列表如下：**
[父命令ccictl选项列表](https://support.huaweicloud.com/devg-cci2/ccictl_01.html#ccictl_01__section188081236162119)
