In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to solve the pit in kubernetes automatic generation ConfigMap", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to solve the pit in kubernetes automatic generation ConfigMap"!
Background problem
Recently, in the process of using Kubernetes ConfigMap, due to the need to copy the configuration file to the ConfigMap yaml orchestration file, it is easy to make mistakes in the process of copy, so Kustomize ConfigMapGenerate is introduced to automatically generate the configuration by referencing the external configuration file, but new problems are encountered in the process of use.
The ConfigMap name generates an extra hash. The content loaded into the configuration file is malformed.
The following are the analysis of these two problems and the specific solutions.
ConfigMapGenerate usage
ConfigMapGenerator is an auto-generated configuration plug-in for Kustomize ConfigMap. It is easy to use, as shown in the following figure:
Execute kubectl apply-k. After the execution is completed, check the ConfigMap, ConfigMap is generated, but after a bunch of hash strings such as: test-conf-tmc5f824gt.
Why?
Do you still need to reference this ConfigMap in deployment? Through the test, it is found that the hash suffix is the hash generated for the content of the file. If the content of the file does not change, the hash will not change, otherwise it will be regenerated.
It turns out that this hash is similar to a concept of the ConfigMap version, but I don't have any requirements for the version of the configuration file during my use.
Solution
You can find https://github.com/kubernetes-sigs/kustomize/blob/master/examples/generatorOptions.md by viewing the document, and you only need to add parameters to control the change of the version number:
After a meal of operation, you can configure the automatic ConfigMap resource object through a reference, we only need to modify our original configuration file, and then regenerate to complete the update of ConfigMap, and there will be no extra strings, of course, if you use template tools such as helm, you can consider using this version number, so ConfigMap also has the concept of version.
ConfigMap Chinese text is out of order
When I get the ConfigMap configuration information through kubectl, there are a lot of\ n\ t in the log xml text, which does not affect the use, but looks bad, and when we need to temporarily modify the configuration, it looks dazzling and affects productivity. (of course, this problem may also occur in ordinary properties configuration files, but KV rarely uses tab indentation for configuration files.)
Why?
Open hidden characters through the idea editor (or through the vim set list feature, you can also show hidden characters), you will find that there are tab indentation characters in xml files, while tab is not allowed for Kubernetes yaml orchestration files, only spaces can be used, as shown in the following figure.
Cause analysis
The reason for the guess is that Kubernetes ConfigMap found that tab was included in the file during the load process, which was directly converted to\ n\ t. If you replace all the tab spaces in the text, will it solve the problem directly? According to this line of thinking, I have got the following two solutions.
Solution (1)
Replace\ t with 4 spaces through the editor regular expression, upload the log configuration file again, and then find that the problem has been solved when you generate the configuration through ConfigMapGenerate, as shown below:
Solution (2)
The above problem can also be solved by using xmllint-- format logback.xml-o logback.xml to format the configuration file.
In addition, because the editing of the configuration file may be on the windows operating system, and the ConfigMap is generated in linux, this will cause ^ M invisible characters in the file, so you can use dos2unix to convert the file format to solve this problem.
At this point, I believe that everyone on the "kubernetes automatic generation of ConfigMap in how to solve the pit" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.