Use Configmap Management configuration-5 minutes a day to play Docker container Technology (159)

Source: Internet
Author: User

Secret can provide the Pod with sensitive data such as passwords, Token, private keys, and configmap for some insensitive data, such as applied configuration information.

Configmap are created and used in much the same way as Secret, and the main difference is that the data is stored in plaintext.

Like Secret, Configmap also supports four ways to create:

1. Through--from-literal:

KUBECTL Create Configmap myconfigmap--from-literal=config1=xxx--from-literal=config2=yyy

Each--from-literal corresponds to an information entry.

2. Through--from-file:

echo-n xxx >/CONFIG1
Echo-n yyy >/config2
KUBECTL Create Configmap myconfigmap--from-file=./config1--from-file=./config2

Each file content corresponds to an information entry.

3. Through--from-env-file:

Cat << EOF > Env.txt
Config1=xxx
Config2=yyy
Eof
KUBECTL Create Configmap Myconfigmap--from-env-file=env.txt

Each line in the file Env.txt key=value corresponds to an information entry.

4. Through the YAML configuration file:

The data in the file is entered directly in clear text.

Like Secret, Pod can also use Secret in the form of Volume or environment variables.

Volume Way:

Environment variable mode:

In most cases, configuration information is provided as a file, so the--from-file or YAML method is usually used when creating Configmap, and the Volume is usually used when reading Configmap.

For example, to the Pod. How to log configuration information:

You can use the--from-file form, save it in a file logging.conf, and then execute the command:

KUBECTL Create Configmap Myconfigmap--from-file=./logging.conf

If the YAML configuration file is used, its contents are:

Be careful not to write the following Key logging.conf | Symbol.

Create and view Configmap:

Using this configmap in Pod, the configuration file is:

① specifies that the file relative path to the configuration information in volume is myapp/logging.conf.

② volume mount to the container's/etc directory.

Create Pod and read configuration information:

The configuration information has been saved to the/etc/myapp/logging.conf file. Like Secret, Volume forms of CONFIGMAP also support dynamic updates, leaving everyone to practice. Summary

In this chapter we learned how to pass configuration information to the Pod. Use Secret If the information requires encryption, or use Configmap if it is a generic configuration information.

Secret and Configmap support four methods of definition. Pod can choose Volume mode or environment variable mode when using them, but only the Volume mode supports dynamic update.

In the next section, we will begin to learn about the Helm-kubernetes package Manager.

Books:

1. "5 minutes a day to play Kubernetes"
Https://item.jd.com/26225745440.html

2. "5 minutes a day to play Docker container technology"
Https://item.jd.com/16936307278.html

3. "5 minutes a day to play OpenStack"
Https://item.jd.com/12086376.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.