当前位置:网站首页>Yyds dry goods inventory kubernetes management business configuration methods? (08)
Yyds dry goods inventory kubernetes management business configuration methods? (08)
2022-07-05 01:04:00 【wzlinux】
Learn from the previous chapters , We're right Kubernetes Medium Pod And some business loads . You can use the examples provided in the course , Try to practice in the cluster by yourself .
In use , We often need to be aware of Pod Do some configuration management , For example, how to use parameter configuration files , How to save and transfer sensitive data , wait . Some people might think , Why not put these configurations ( Not limited to parameters 、 The configuration file 、 Key, etc ) Package it into the image ? At first glance to , It seems a little feasible , But that's how it works “ Indifference to ” Too much .
- Some unchanged configurations can be packaged into the image , What about the variable configuration ?
- Information leakage , It is easy to cause security risks , Especially some sensitive information , such as password、 Secret key, etc .
- After each configuration update , All need to be repackaged , Upgrade apps . Too many mirrored versions , It also brings a great burden to image management and image center storage .
- Customization is too serious , Poor scalability , And it is not easy to reuse .
So a best practice here is to decouple the configuration information from the container image , With “ The same should change ”. stay Kubernetes in , Generally speaking, there are ConfigMap and Secret Two kinds of objects , It can be used for configuration management .
ConfigMap
First of all, let's talk about ConfigMap This object , It is mainly used to save some non sensitive data , Can be used as an environment variable 、 Command line parameters or mount to the storage volume .
ConfigMap Store information through key value pairs , It's a namespace Level of resources . stay kubectl When using , We can abbreviate it to cm.
Let's take a look at two ConfigMap Of API Definition :
so , We go through ConfigMap It can store simple key value pairs , It can also store multiple lines of text .
Now let's create these two ConfigMap:
establish ConfigMap, You can also pass kubectl create cm
be based on Catalog 、 file perhaps Face value To create , Please refer to this for details Official documents .
Once created , We can view the created objects in the following ways .
Now let's see how to communicate with Pod Use in combination . In use , There are several areas that need special attention :
- Pod It has to be with ConfigMap In the same namespace below ;
- Creating Pod Before , Please make sure ConfigMap Already exist , otherwise Pod Error will be reported when creating .
In the example above , It almost covers ConfigMap Several usage scenarios of :
- Command line arguments ;
- environment variable , You can inject only some variables , It can also be fully injected ;
- Mount the file , It can be a single file , It can also be all key value pairs , Use each key value as the file name .
So let's create :
Once created , We exec Look into the container :
You can see , Environment variables have been injected correctly , The corresponding files and directories are also mounted .
on top ls -alh /config/
after , We see that there are soft links in the mounted files , All point to ..data
A file in a directory . The benefits of doing this , yes kubelet It will regularly check the attached ConfigMap Is it the latest , If it's updated , Is to create a new folder to store the latest content , And synchronously modify ..data
Soft link to .
Generally, we only save some non sensitive data to ConfigMap in , Sensitive data should be saved to Secret It's in .
Secret
We can use Secret To save some sensitive data information , Like passwords 、 secret key 、token etc. . In use , Follow ConfigMap The usage is basically the same , Can be used as environment variables or file mount .
Kubernetes It also has some built-in Secret, It is mainly used to save access APIServer Of service account token, Let's talk about it later in the permissions section , Let's skip .
besides , It can also be used to save the identity information of the private image center , such kubelet You can pull the image .
notes : If you're using Docker, You can also run on the target machine in advance
docker login yourprivateregistry.com
To save your valid login information .Docker Generally, the key of the private warehouse will be saved in$HOME/.docker/config.json
In file , Distribute the file to all nodes .
Let's see how to pass kubectl To create secret, From the command line help You can see kubectl Be able to create many types of Secret.
Let's create a Secret To save the identity information of accessing the private container warehouse :
Here we can see , created Secret The type is kubernetes.io/dockerconfigjson
:
In order to prevent Secret The content in is leaked ,kubectl get
and kubectl describe
It will avoid directly displaying the content of the password . But we can get the complete Secret Object to further view its data :
Here we find .dockerconfigjson
It's a piece of garbled code , We use it base64 Try decompression :
This actually passed with us docker login After ~/.docker/config.json
It's the same in .
thus , We found that Secret and ConfigMap The biggest difference in data storage .Secret The saved data is through base64 Encrypted data .
We usually use another kind more widely Opaque
Type of Secret:
Or we can use the following equivalent kubectl Command to create :
Or create objects through files , such as :
Sometimes for convenience , You can also use stringData
, In this way, you can avoid using it manually in advance base64 To encrypt .
And now we have Pod Use in Secret:
Once created , Let's take a look at :
We can see the command in the log env
Output , See environment variables username
and password
Has been injected correctly . Similarly , We can also put Secret As Volume Mount to Pod Inside .
Last
ConfigMap and Secret yes Kubernetes Common objects for saving configuration data , You can choose the right object to store data according to your needs . adopt Volume How to mount to Pod Internal ,kubelet Will be updated regularly . But inject into the container through environment variables , So you can't feel ConfigMap or Secret Content update for .
How to make Pod The business inside is aware of ConfigMap or Secret The change of , It is still a problem to be solved . But we still have some Workaround Of .
- If the business supports reload Configuration , such as
nginx -s reload
, Can pass inotify Aware of file updates , Or directly and regularly reload( We can cooperate here readinessProbe Use it together ). - If our business does not have this ability , Considering the idea of immutable infrastructure , Can we use rolling upgrade ? you 're right , This is a very good way . There is currently an open source tool Reloader, It is in this way , adopt watch ConfigMap and Secret, Once the object is found to be updated , It will automatically trigger right Deployment or StatefulSet Wait for workload objects to roll up . Specific usage , Refer to the documentation of the project .
For this question , In fact, the community has been discussing better solutions , We'll see .
Welcome to scan the code to pay attention to , For more information
边栏推荐
- Basic operation of database and table ----- the concept of index
- [Yocto RM]10 - Images
- Huawei employs millions of data governance experts! The 100 billion market behind it deserves attention
- There is a new Post-00 exam king in the testing department. I really can't do it in my old age. I have
- [development of large e-commerce projects] performance pressure test - Performance Monitoring - heap memory and garbage collection -39
- 实战模拟│JWT 登录认证
- Arbitrum: two-dimensional cost
- Recursive execution mechanism
- [selenium automation] common notes
- Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
猜你喜欢
107. Some details of SAP ui5 overflow toolbar container control and resize event processing
Postman automatically fills headers
4. Scala writes HelloWorld in idea, in-depth analysis of accompanying objects, and association of source packages
大专学历,33岁宝妈又怎样?我照样销售转测试,月入13k+
抓包整理外篇——————状态栏[ 四]
User login function: simple but difficult
Two numbers replace each other
26.2 billion! These universities in Guangdong Province have received heavy support
Pandora IOT development board learning (RT thread) - Experiment 4 buzzer + motor experiment [key external interrupt] (learning notes)
FEG founder rox:smartdefi will be the benchmark of the entire decentralized financial market
随机推荐
Implementation steps of master detail detail layout mode of SAP ui5 application
兩個數相互替換
"Upside down salary", "equal replacement of graduates" these phenomena show that the testing industry has
[STM32] (I) overview and GPIO introduction
Check if this is null - checking if this is null
TS quick start - functions
Global and Chinese markets for industrial X-ray testing equipment 2022-2028: Research Report on technology, participants, trends, market size and share
测试部新来了个00后卷王,上了年纪的我真的干不过了,已经...
程序员SQL数据脚本编码能力弱,BI做不出来怎么办?
【海浪建模3】三维随机真实海浪建模以及海浪发电机建模matlab仿真
【大型电商项目开发】性能压测-性能监控-堆内存与垃圾回收-39
Parameter passing mechanism of member methods
Arbitrum: two-dimensional cost
Arbitrum:二维费用
const、volatile和restrict的作用和用法总结
[FPGA tutorial case 9] design and implementation of clock manager based on vivado core
当产业互联网时代真正发展完善之后,将会在每一个场景见证巨头的诞生
每日刷题记录 (十三)
There is a new Post-00 exam king in the testing department. I really can't do it in my old age. I have
Global and Chinese market of network connected IC card smart water meters 2022-2028: Research Report on technology, participants, trends, market size and share