This is the 20th day of my participation in the August Text Challenge.More challenges in August
- 📢 welcome to like: 👍 collect ⭐ message 📝 if there are mistakes please correct, give people rose, hand left lingering fragrance!
- 📢 This article was originally written by Webmote and originally published by Nuggets.
- 📢 author’s motto: life is toss about, when you don’t toss about life, life will start to toss about you, let us come on together! 💪 💪 💪
Preface 🎏
Every application or service comes into contact with configuration parameters to some extent. The simplest application may hardcode the configuration into program code, while more complex microservices may require a unified configuration center to publish configuration parameters. Let’s take a look at their evolution.
🎏 1. Hardcode the configuration
Hard coding is simply writing configuration parameters directly into code, and while it may not seem perfect, it comes up all the time.
Most of our common desktop software, for example, is hard-coded into built-in code without requiring the user to modify any parameters.
As we use notepad on Windows, drawing, etc., they may have simple internal parameters, or even no redundant parameters, of course, since there is no exposed configuration file, it will be hard-coded into the system.
Sometimes we develop simple gadgets for internal use and simply hard-code them into code.
The hard-coded form is as follows:
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Data Source=.; Integrated Security=true; Initial Catalog=Time";
conn.Open();
Copy the code
🎏 2. Configuration file
As the system environment becomes more and more complex, we may need to set different parameters in different environment, so the most popular configuration method emerged, it is the configuration file.
Asp.net Core also has built-in support for configuration files, making it easy to use. By monitoring extended extension files, different configuration files can be loaded for different environments.
Take appSetting. json as an example to see what the configuration file looks like.
"profiles": { "IIS Express":
{ "commandName": "IISExpress"."launchBrowser": true."environmentVariables":
{ "ASPNETCORE_ENVIRONMENT": "Development" }, "nativeDebugging": true }
Copy the code
Json files are now popular as configuration files, and there are many more, such as the classic INI file format, the once-popular XML file, and now the ubiquitous YAML format used by cloud native.
languages:
- Ruby
- Perl
- Python
websites:
YAML: yaml.org
Ruby: ruby-lang.org
Python: python.org
Perl: use.perl.org
Copy the code
🎏 3. Configure data to databases and remote files
Configuration files can also be stored in databases or remote files, which are slightly different from local configuration files and have distributed access. If the configuration center cannot be implemented, microservices can be configured in this way as a centralized configuration management mode with unified configuration and independent distribution. The run-time update effect can even be achieved with some timed pull.
Borrow an image from the Internet to see the storage of the database.
🎏 4. Apollo Configuration center
As the leader of micro service configuration center, Ctrip Apollo, complex architecture, simple to use. Its structure is as follows:
It’s feature-rich and configurable, right out of the box, and of course its deployment is heavyweight as a configuration center.
- Push the configuration
- Pull configuration
- gray
- version
- .
🎏 5. In cloud native configuration
When it comes to cloud native configuration, it must be K8s’s ConfigMap resource, which configmap files that can be loaded into the container’s environment variables when each container starts for use.
Although the bottom layer does not support hot update, but the use of K8s own instance loading function, also can be indirectly implemented hot update.
🎏 6. Summary
Well, this chapter is a bit watery, which will be added later in the summary.
Routine summary, rational view!
Knot is what ah, knot is I want you to praise but can not get lonely. 😳 😳 😳
👓 have seen this, but also care about a thumbs-up?
👓 has been liked, but also care about a collection?
👓 are collected, but also care about a comment?