Method and device for automatically building a container platform based on Ansible
The Kubernetes container platform is automatically installed through the Ansible automated operation and maintenance tool, which solves the environmental inconsistency and high cost problems caused by manual deployment, realizes standardized deployment, improves efficiency and scalability, and provides technical support for the application and popularization of microservices.
Patent Information
- Application Number
- CN202111643216.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-29
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2041-12-29
AI Technical Summary
In the existing technology, manual deployment of Kubernetes clusters results in inconsistent system environment versions, increased deployment time, high manual learning costs, and difficulty in transplantation, which hinders the application and popularization of microservices.
The Ansible automated operation and maintenance tool is used to configure the playbook and host list, and run the playbook to automatically install the Kubernetes container platform on the server to achieve a standardized and batch delivery and deployment model.
It significantly improves deployment efficiency, reduces costs, reduces client resource consumption, creates good technical conditions, and facilitates the application and promotion of microservices.
Smart Images

Figure CN114416290B
Abstract
Description
Technical Field
[0001] The present application relates to the field of microservice computer system deployment, and in particular to a method and device for automatically building a container platform based on Ansible. Background Art
[0002] With the transformation of enterprise IT architecture, container, orchestration, and microservice technologies have become popular, and container technology provides a guarantee for the implementation of microservices.
[0003] Kubernetes, or k8s for short, is a portable container orchestration management tool created for container services. More and more companies are embracing k8s. Currently, k8s has dominated cloud business processes and promoted the popularization and implementation of popular technologies such as microservice architecture. The availability and scalability that microservice architecture cares about can be well solved through k8s. At the deployment and operation level, k8s also provides good solutions for service deployment, service monitoring, application expansion and fault handling.
[0004] In the existing technology, k8s clusters are deployed manually on site, which causes problems such as inconsistent system environment versions, increased deployment time, high manual learning costs, and difficulty in transplantation, which brings great difficulties to the application and popularization of microservices. Summary of the invention
[0005] The purpose of this application is to provide a method for automatically building a container platform. This application also provides corresponding electronic equipment and computer storage media.
[0006] On the one hand, the present application provides a method for automatically building a container platform based on Ansible, including:
[0007] Configure a playbook, where the playbook includes multiple plays, which are used to install the Kubernetes container platform. Each play corresponds to at least one role.
[0008] Configure a host list, and set the IP address corresponding to each role in the host list;
[0009] Run the playbook to install the Kubernetes container platform on the server indicated by the IP address.
[0010] Optionally, the roles corresponding to the multiple plays include a role for system initialization, a role for installing a container, a role for installing an image repository, and a role for installing a Kubernetes orchestration platform.
[0011] Optionally, each of the roles is configured to perform at least one task, and the method further includes:
[0012] Before running the playbook, call the predefined module of Ansible to write the tasks corresponding to each role.
[0013] Optionally, the method further comprises:
[0014] Before running the playbook, multiple folders are created for each role, including a folder for storing static files, a folder for storing template files, a folder for setting variables, and a folder for storing at least one task executed by the role.
[0015] Optionally, the method further comprises:
[0016] If the server indicated by the IP address is at the first security level, run the playbook to remotely install the Kubernetes container platform on the server.
[0017] Optionally, running the playbook to remotely install the Kubernetes container platform on the server specifically includes:
[0018] Run the playbook and remotely install the Kubernetes container platform on the server based on the SSH protocol.
[0019] Optionally, the method further comprises:
[0020] If the server indicated by the IP address is at the second security level, the playbook is transplanted to a device connected to the server, and the playbook is run on the device to install the Kubernetes container platform on the server.
[0021] Optionally, install the Kubernetes container platform including:
[0022] Install the Kubernetes container platform in binary mode.
[0023] Another aspect of the present application provides an electronic device, the electronic device comprising:
[0024] A memory storing executable instructions;
[0025] A processor runs the executable instructions in the memory to implement the method for automatically building a container platform based on Ansible as described above.
[0026] In another aspect of the present application, a computer-readable storage medium is provided, which stores a computer program. When the computer program is executed by a processor, the method for automatically building a container platform based on Ansible as described above is implemented.
[0027] According to the technical solution disclosed in this application, the ansible automated operation and maintenance tool is introduced. By configuring playbooks in ansible, configuring host inventories, and running playbooks to install the Kubernetes container platform on the server, a standardized, batch delivery and deployment mode for building a k8s platform is realized, which significantly increases efficiency and reduces costs, creating good technical conditions for the application, popularization and promotion of microservices. In addition, using ansible to build a Kubernetes platform does not require the installation of an agent in the operating system on the client, which can also reduce the resource loss of the client. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] The above and other objects, features and advantages of the present application will become more apparent through a more detailed description of exemplary embodiments of the present application in conjunction with the accompanying drawings, wherein the same reference numerals generally represent the same components in the exemplary embodiments of the present application.
[0029] Figure 1 A flowchart showing a method for automatically building a container platform based on Ansible according to an embodiment of the present application.
[0030] Figure 2 A schematic diagram showing a process of building a container platform according to an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0031] The present application will be described in more detail below with reference to the accompanying drawings. Although preferred embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to make the present application more thorough and complete, and to fully convey the scope of the present application to those skilled in the art.
[0032] As mentioned above, Kubernetes is of great significance to the application, popularization and promotion of microservices. However, the current manual deployment of Kubernetes clusters has caused problems such as inconsistent system environment versions, increased deployment time, high manual learning costs, and difficulty in transplantation, which has brought great difficulties to the application of microservices.
[0033] After an in-depth understanding of numerous technical solutions and their combinations, the applicant chose to introduce Ansible into Kubernetes cluster deployment, realizing a standardized delivery and deployment model for building a Kubernetes container platform, significantly improving efficiency and reducing costs, creating good technical conditions for the application, popularization and promotion of microservices, and reducing resource loss on the client operating system.
[0034] Ansible is a simple, powerful and agentless automation language, which is written based on YAML text and is easy to read. Ansible does not require an agent and does not require the installation of additional agents on hosts or network devices. In addition, Ansible can also achieve cross-platform support, which can support Linux, Windows, Unix and network devices. Playbook, play, role, inventory (invertory), task, module, etc. are all important terms in Ansible. Playbook can be regarded as a task list of a role, which is a script file built based on YAML in Ansible. The main function of play is to dress up the hosts that have been grouped together in advance as roles that have been defined in advance through tasks. Role is a new feature introduced by Ansible since version 1.2, which is used to organize playbooks in a hierarchical and structured manner. Task calls the predefined module in Ansible to perform the desired task. Module is a predefined module in Ansible. Inventory is a list of roles. Ansible supports dynamic objects as well as static objects. Plugin refers to a code segment added to Ansible, which is used to extend the Ansible platform.
[0035] Figure 1 A flowchart showing a method for automatically building a container platform based on Ansible according to an embodiment of the present application is shown. Figure 1 As shown, the method includes step 102 , step 104 and step 106 .
[0036] Step 102: configure a playbook, where the playbook includes multiple plays, and the multiple plays are used to install the Kubernetes container platform, and each play corresponds to at least one role.
[0037] In some possible implementations, the roles corresponding to the multiple plays include a role for system initialization, a role for installing a container, a role for installing an image repository, a role for installing a Kubernetes orchestration platform, etc. The Kubernetes orchestration platform typically includes a master (master control object) and a node (controlled node).
[0038] In some possible implementations, each of the roles is configured to execute at least one task, and a predefined module of Ansible may be called to write a task corresponding to each of the roles.
[0039] The deployment task can be divided into multiple plays, each of which corresponds to at least one role. The play will dress up the hosts that are previously grouped together as roles that have been pre-defined through tasks in Ansible. You can call the pre-defined modules of Ansible to write the corresponding tasks. Copy, template, shell, yum, etc. are all commonly called modules in Ansible. The copy module is used to overwrite the files in the specified directory to the role; the template module is used to replace the configuration files on the overwritten role; the shell module is used to remotely execute shell scripts; the yum module is used to remotely install and uninstall software.
[0040] In some possible implementations, the method further includes: creating multiple folders for each role, the multiple folders including a folder for storing static files, a folder for storing template files, a folder for setting variables, a folder group for storing at least one task performed by the role, a file group for setting variables, and a file group for storing at least one task performed by the role.
[0041] You can create files, tasks, templates, and vars folders for each role. Files is used to store static files; templates is used to store template files; vars is used to set running variables; tasks is used to store one or more tasks performed by the role. The task file can call predefined modules in Ansible.
[0042] Step 104, configure a host list, and set the IP address corresponding to each role in the host list.
[0043] The IP address corresponding to each role can be set in the host list. The same role can be deployed on multiple servers to achieve batch deployment and facilitate high availability of the system.
[0044] Step 106: Run the playbook to install the Kubernetes container platform on the server indicated by the IP address.
[0045] The above server can be a host server or a network server.
[0046] In some possible implementations, if the server indicated by the IP address is at a first security level, the playbook is run to remotely install the Kubernetes container platform on the server. In one example, the Kubernetes container platform can be remotely installed on the server indicated by the IP address based on the SSH protocol.
[0047] In some possible implementations, if the server indicated by the IP address is at the second security level, the playbook is ported to a device connected to the server, and the playbook is run on the device to install the Kubernetes container platform on the server.
[0048] For servers in a normal production environment (first security level), you can use SSH authentication to connect to all these container platform servers for remote installation and deployment; and after the deployment is complete, delete the public and private keys and add them to the bastion host.
[0049] For a server in a network isolation environment (second security level), you can copy the playbook to a device connected to the server, which can be another server in the same network isolation environment as the server, or the server itself; run the playbook on the device to install and deploy it on the server; and delete the playbook on the device after installation.
[0050] According to the technical solution disclosed in this application, the ansible automated operation and maintenance tool is introduced. By configuring the playbook, configuring the host list, and running the playbook to install the Kubernetes container platform on the server, a standardized delivery and deployment mode for building the k8s platform is realized, which significantly increases efficiency and reduces costs, and creates good technical conditions for the application, popularization and promotion of microservices. In addition, using ansible to build the Kubernetes platform does not require the installation of an agent on the client, and can also reduce the resource loss of the client.
[0051] For example, by defining the init_system (system initialization) role in a play, unified configuration optimization of the operating system initialization can be achieved, which usually includes fixing security vulnerabilities, baseline repairs, etc. Through this application, setting init_system in the playbook can directly cover multiple remote container platform servers: sshd_config, selinux, localtime, limits.conf, sudo, sysctl.conf, login.defs, pwquality.conf, and can also upgrade the Linux kernel kube-apiserver, kubelet, kube-controller-manager, kube-scheduler, kube-prox, etc. at one time, install and delete RPM (RPM package manager), etc., which significantly improves deployment efficiency and reduces error rates. In addition, since the agent is not deployed on the client, it will not cause resource loss to its operating system.
[0052] For example, the deployment of the container platform kubernetesdocker is relatively complex. In the existing technology, it requires very experienced technicians to manually deploy it, and the delivery cycle is also long. By defining the role of installing the docker container in a play, it is possible to create certificates, etcd clusters, master high availability, automatic installation of multiple components, etc., and there is no need to understand the internal principles of the container and the module calling mechanism, so it can be delivered quickly. In addition, the role is stored in the form of files, which is highly portable and reusable, and can be quickly copied to other projects.
[0053] In some possible implementations, multiple plays in the playbook may install the Kubernetes container platform on the role in a binary manner.
[0054] Using binary mode for deployment makes it easier to troubleshoot problems, but its deployment is more complicated and prone to errors. According to this application, automatic deployment of binary mode is realized by introducing Ansible, avoiding the defects of binary deployment such as cumbersome configuration file modification and error-proneness.
[0055] Figure 2A flowchart for building a container platform according to an exemplary embodiment of the present application is shown. As shown in the figure, S202, start running the playbook. S204, execute the play corresponding to the system initialization role. S206, execute the play corresponding to the installation of the container (docker) role. S208, execute the play corresponding to the installation of the image repository (harbor) role. S210, execute the play corresponding to the installation of the etcd cluster role. When executing S210, the image in the image repository must also be pulled. S212, execute the play corresponding to the installation of the cluster master component (master) role. S214, execute the play corresponding to the installation of the cluster controlled node (node) role.
[0056] The embodiments of the present application have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments.
Claims
1. A method for automatically building a container platform based on Ansible, characterized in that: include: Configure a playbook, where the playbook includes multiple plays, and the multiple plays are used to install the Kubernetes container platform. Each play corresponds to at least one role, and the roles corresponding to the multiple plays include a role for system initialization, a role for installing containers, a role for installing image repositories, and a role for installing the Kubernetes orchestration platform. Configure a host list, and set the IP address corresponding to each role in the host list; Run the playbook to install the Kubernetes container platform on the server indicated by the IP address, wherein if the server indicated by the IP address is at a first security level, run the playbook to remotely install the Kubernetes container platform on the server; if the server indicated by the IP address is at a second security level, port the playbook to a device connected to the server, and run the playbook on the device to install the Kubernetes container platform on the server.
2. The method according to claim 1, characterized in that Each of the roles is configured to perform at least one task, and the method further comprises: Before running the playbook, call the predefined module of Ansible to write the tasks corresponding to each role.
3. The method according to claim 2, characterized in that The method further comprises: Before running the playbook, multiple folders are created for each role, including a folder for storing static files, a folder for storing template files, a folder for setting variables, and a folder for storing at least one task executed by the role.
4. The method according to claim 1, characterized in that: Running the playbook to remotely install the Kubernetes container platform on the server specifically includes: Run the playbook and remotely install the Kubernetes container platform on the server based on the SSH protocol.
5. The method according to claim 1, characterized in that Installing the Kubernetes container platform specifically includes: Install the Kubernetes container platform in binary mode.
6. An electronic device, characterized in that: The electronic device comprises: A memory storing executable instructions; A processor that runs the executable instructions in the memory to implement the method for automatically building a container platform based on Ansible according to any one of claims 1 to 5.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the method for automatically building a container platform based on Ansible according to any one of claims 1 to 5.
