当前位置:网站首页>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.comTo save your valid login information .Docker Generally, the key of the private warehouse will be saved in$HOME/.docker/config.jsonIn 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

边栏推荐
- Playwright recording
- 大专学历,33岁宝妈又怎样?我照样销售转测试,月入13k+
- leetcode518,377
- Global and Chinese markets for stratospheric UAV payloads 2022-2028: Research Report on technology, participants, trends, market size and share
- Arbitrum:二维费用
- Senior Test / development programmers write no bugs? Qualifications (shackles) don't be afraid of mistakes
- 揭露测试外包公司,关于外包,你或许听到过这样的声音
- Relationship between classes and objects
- Getting started with Paxos
- Open3d uses GICP to register point clouds
猜你喜欢

Take you ten days to easily complete the go micro service series (IX. link tracking)

Arbitrum:二维费用
![[development of large e-commerce projects] performance pressure test - Optimization - impact of middleware on performance -40](/img/e4/0bdee782a65028b2bc87db85d48738.png)
[development of large e-commerce projects] performance pressure test - Optimization - impact of middleware on performance -40

There is a new Post-00 exam king in the testing department. I really can't do it in my old age. I have

Leetcode70 (Advanced), 322

4. Scala writes HelloWorld in idea, in-depth analysis of accompanying objects, and association of source packages

dotnet-exec 0.6.0 released

Parameter passing mechanism of member methods

1189. Maximum number of "balloons"

Two numbers replace each other
随机推荐
[circuit design] optocoupler use and circuit design summary
PyTorch: In-place Operation
【微处理器】基于FPGA的微处理器VHDL开发
How to use words to describe breaking change in Spartacus UI of SAP e-commerce cloud
Maximum number of "balloons"
【大型电商项目开发】性能压测-性能监控-堆内存与垃圾回收-39
[selenium automation] common notes
SAP UI5 应用的主-从-从(Master-Detail-Detail)布局模式的实现步骤
What if the programmer's SQL data script coding ability is weak and Bi can't do it?
Two numbers replace each other
那些一门心思研究自动化测试的人,最后都怎样了?
107. SAP UI5 OverflowToolbar 容器控件以及 resize 事件处理的一些细节介绍
[pure tone hearing test] pure tone hearing test system based on MATLAB
Mongodb series learning notes tutorial summary
Getting started with Paxos
dotnet-exec 0.6.0 released
【C】 (written examination questions) pointer and array, pointer
Inventory of more than 17 typical security incidents in January 2022
Call Huawei order service to verify the purchase token interface and return connection reset
Global and Chinese market of optical densitometers 2022-2028: Research Report on technology, participants, trends, market size and share