This is a creation in Article, where the information may have evolved or changed.
"Editor's note" As Docker technology grows, Docker plays an increasingly important role in code-building publishing. Docker allows developers to package their apps and dependencies into a portable container and publish them to popular Linux machines. Docker is ideal for the following scenarios:
- Automated packaging and publishing of application containers;
- Automated testing and continuous integration, release;
This time I'll talk to you about the problems that application containers encounter in configuration management. The first is to introduce the common configuration file loading methods for existing containers, and then focus on the problems and solutions that are encountered in automating the packaging and publishing of the digital cloud components.
How the existing main Docker load configuration is
Let's start with a brief introduction to the way the configuration files are loaded for existing containers.
How to mount a host configuration file
Mount the configuration file on the host to the container in the specified directory via the docker run-v parameter as:
Docker run-v/myredis/conf/redis.conf:/usr/local/etc/redis/redis.conf--name Myredis redis redis-server/usr/local/ Etc/redis/redis.conf
This method is more convenient for single-instance applications.
How to download the Configuration center file
This method first needs to establish the configuration center, for example, with Nginx and other Web services components, in advance to put the configuration file in the specified directory, in the Dokcerfile entrypoint to pull the configuration center file script, and then the container starts to automatically pull configuration center configuration.
Passing through environment variables into the container
Use the Docker run-e parameter to pass environment variables to the container such as:
Docker run--name some-mysql-e mysql_root_password=my-secret-pw-d mysql:5.6
Issues encountered in automating packaging and publishing of application containers
The digital cloud component uses the MicroServices architecture, splits the service, uses the relative independent service to manage each aspect separately, uses the unified interface to communicate with each other, the architecture becomes complex, but the advantage is very obvious. To ensure high availability, these containers typically run on multiple VMS, before the service instances are a layer of load balancers such as Haproxy, which are responsible for distributing requests between instances. Several people cloud sub-test, demonstration, production three kinds of environment for continuous integration, release, and several people cloud components through the Docker+mesos+marathon application container packaging issued and managed. First of all, we have the issue of container release-more configuration files, how to manage the unified?
Due to the use of micro-service architecture, the configuration of the various modules, resulting in a large number of configuration files, and then several people cloud three sets of environment, such as MySQL and other basic components such as IP, port configuration, resulting in a doubling of configuration, and finally the use of high-availability architecture, resulting in increased configuration files. The following is a number of people cloud Mesos system Architecture Flowchart:
Marathon, Jenkins as the framework register on the Mesos-master, dynamically dispatching Mesos-slave resources.
- Marathon responsible for the release of the application
- Jenkins is responsible for code packaging, image building
The Mesos framework is as follows:
If the simple-to-V Mount mode needs to be placed in advance configuration files on the Mesos-slave host, the new add slave also need to do the same operation, and when the configuration file needs to be updated, need to update each mesos-slave host configuration file, which is obviously not flexible, So we just started using the application container to start downloading the configuration center files.
The early configuration center, as shown in:
The problems that exist at this time are:
- Because it is a variety of environments, although these configurations are centrally configured on Configserver, these configurations need to be modified manually. Manual modifications are error-prone, such as dev updates a service that may take a week before it is updated to a production environment. At that time, it was easy to make mistakes and make it impossible to run.
- Manual modification is not appropriate if the configuration has a bug that needs to be rolled back.
We have improved the introduction of Jenkins after the working process such as:
We use Jenkins to string them together, our first job is to abstract all the configuration files, various environment files abstracted out a template, placed on the Gitlab. Its data is placed in the database, so that together is a complete configuration file. The values for each environment are not the same. Our OPS platform triggers Jenkins,jenkins to dispatch our Configcenter API, which passes two parameters, one that needs to be updated, and the other is which service to update. After the API to do the comparison, from the database to read the existing configuration file template tag, then read the new template tag to compare.
If the file needs to be updated, pull it from the database, match the data, render it our final configuration file, and upload it to Gitlab. The rest is triggered by Jenkins trigger configserver gitlab Download the latest configuration file to Configserver server, Jenkins again to call Marathon to restart the service, the service will successfully update the configuration file. This solves the configuration file file, but there are some problems with the following:
- Configuration formats are not uniform, configured with Env, Congfig.js,. Yaml,. xml and other configuration files, the various profiles need to be replaced before the application container is published, when the new profile item, the need to rewrite the template, replace the matching content is more cumbersome.
- Marathon release application adopted a configuration file, in the marathon interface can not see the contents of the configuration file, need to view the background, increased operational complexity.
Later, we made an env transformation of the application, unified the configuration file format, and the configuration was passed to the marathon through the variables, making all configurations visible on the marathon interface.
The following is a specific work, we have a statute of development.
Product Module GitHub Directory specification structure
In addition to some documentation for code and product development, it is also necessary to regulate the directory structure:
Module_name-
|
-Deploy-
|
-ENV
|
-deploy-marathon.sh
|
-compile.sh
|
-Dockerfiles-
|
-Dockerfile_compile_env
|
-Dockerfile_runtime
Update the env file on GitHub, which is maintained by the development, which has a corresponding env file such as:
The following are the specific flowchart of the improvement:
The above mainly env the configuration file, reduce the configuration replacement complexity, the configuration exists in the marathon release script.
Marathon Applist generated after the update:
Single App container configuration:
- Using ENV to facilitate the unified maintenance and management of configuration files, the new version of Marathon well support the application of the update and rollback, remove the container to start the static configuration file dependency, so that the application container update release, rollback more convenient. All container configuration information can be seen from the interface, making troubleshooting easier.
- The Offline people cloud Enterprise component uses the same mirroring and env variables as the line, gets the corresponding version of Envfile and Docker images through the API, and then takes all the profiles out to a profile, and the implementation colleague simply modifies the configuration file, eliminating the need to modify other configuration files. Make the implementation process more simple.
The above is a few people cloud component configuration management encountered problems, as well as the Env solution, we welcome your valuable comments.
Q&a
Q:mesos running a task, if it is found that the task needs to increase the resources, mesos how to achieve the elastic capacity of the task resources? If you are using Docker, do you create more Docker containers or expand the size of existing Docker directly?
A: It is generally possible to expand the number of Docker containers, only to enlarge the size of a single docker unless there is a minimum resource requirement for a task.
Q: How are local environment variables used by developers managed? For example, an application, a database, a search engine, and two Java apps, different development may need to be different, such as the development of the search function, I need to link the public database, and some development need to own a database, search engines need to link the public. How is this configuration managed?
A: This is best to differentiate the database environment and configure two or more similar environment variables.
Q: How does the MySQL database migrate with Docker? Is there any good advice for backup and recovery?
A:mysql is now a fixed host master-slave synchronization, do not migrate to MySQL, our data is now backup is scheduled full backup, is trying to use the MARIADB cluster Galera Cluster, but not on the production, of course, there is shared storage is best.
Q: Can the online service update the war package, how to make the external service uninterrupted?
A: Several people cloud is currently using the code version and the image version of the unified, external service uninterrupted, the current practice of several people cloud is the application of a stateless transformation, after the marathon put update container.
Q: What is the difference between the production environment and the development environment of the configuration file?
A: Both the production and test environments are isolated and configuration files are configured with different parameters.
Q: How do you manage configuration files like JDBC, Spring.xml, and other Java applications?
The A:xml configuration replaces the incoming environment variable with SED.
Q: How do I change the configuration item on production?
A: When the value of the production configuration needs to be modified, it is modified in the Configcenter page, then the job of Jenkins Update profile is triggered, the new configuration file is produced, and the marathon API update task is called for update.
Q: Is the configuration of the business put together with the environment configuration?
A: Yes, they are all unified through the envfile.
Q: Are you self-sensing for applying elastic extensions? If yes, what strategy is based on what is done, monitoring alarm or what?
A: Several people cloud is triggered by monitoring the alarm to expand the elastic, such as monitoring the return time of the interface, container memory utilization, etc.
Q: What kind of management method do you use for environmental variables? Do you have the appropriate naming conventions? Environment variables are many, there will be management problems it.
A: The environment variable key value by the development maintenance, operations need to know in advance the new environment variables, the current configuration in mind maintenance, container environment variable variable naming specification is very important, we currently use the service name + need to connect the component name + attribute named, and environment variables all uppercase.
The above content is organized according to the July 14, 2016 night group sharing content. Share people
Fang Zhihao, the 92 ape, has been a few people after graduating from the cloud, the Docker and Mesos have in-depth research, currently do a few people cloud platform packaging deployment and some customer project implementation work, like in practice to try new things and summary. Dockone Weekly will organize the technology to share, welcome interested students add: Liyingjiesz, into group participation, you want to listen to the topic or want to share the topic can give us a message.