ConfigMap with management configuration

1. ConfigMap introduce configuration management

ConfigMap Introduction

  Secret code may be provided, the Token, private keys and other sensitive data Pod; for some non-sensitive data, such as configuration information of the application, can be used ConfigMap

  ConfigMap created and used in a manner very similar to Secret, the main difference is that data is stored in clear text.

Like the Secret, ConfigMap also supports four created:

1> by-literal --from :

kubectl create configmap myconfigmap --from-literal=config1=xxx --from-literal=config2=yyy

  Each --from-literal corresponding to one information entry.

2> by-File --from :

echo -n xxx > ./config1
echo -n yyy > ./config2
kubectl create configmap myconfigmap --from-file=./config1 --from-file=./config2

Each file corresponds to the content of a message entry.

3> by the env-File---from :

cat << EOF > env.txt
config1=xxx
config2=yyy
EOF
kubectl create configmap myconfigmap --from-env-file=env.txt

File env.txt Key = Value of each row corresponds to one information entry.

4> by YAML configuration file:

 

Data files directly input in plain text.

As with the Secret, Pod may be used by way of Volume Secret or environment variables. 

(1) Volume ways:

 

(2) environmental variables ways:

 

configmap practice

In most cases, configuration information is provided as a file, so when you create ConfigMap usually --from-file or YAML way, usually Volume mode when reading ConfigMap.

Pod for example, how to record the configuration information transmitted log:

 

(1) may be employed in the form --from-file, it is saved in a file logging.conf, and then execute the command: kubectl create configmap myconfigmap1 --from-file = / logging.conf.

(2) If a YAML configuration file, its contents was:

 

Note Do not forget to write back Key logging.conf | symbol.

Create and view ConfigMap:

 

In this ConfigMap Pod, the configuration file:

 

① configuration information stored in the specified volume relative file path myapp / logging.conf.

② 将 volume mount 到容器的 /etc 目录。

创建 Pod 并读取配置信息:

 

  配置信息已经保存到 /etc/myapp/logging.conf 文件中。与 Secret 一样,Volume 形式的 ConfigMap 也支持动态更新,留给大家自己实践。

小结

  如何向 Pod 传递配置信息,如果信息需要加密,可使用 Secret;如果是一般的配置信息,则可使用 ConfigMap。

  Secret 和 ConfigMap 支持四种定义方法。Pod 在使用它们时,可以选择 Volume 方式或环境变量方式,不过只有 Volume 方式支持动态更新。

Guess you like

Origin www.cnblogs.com/ajunyu/p/11284713.html