Hybrid architecture k8s cluster offline deployment method, system, device and storage medium
By generating predefined configuration files and importing local images, the problem that existing k8s cluster offline deployment solutions cannot be applied to multi-architecture deployment is solved, and offline deployment is implemented for multi-cpu architectures to meet the needs of continuous integration of enterprise microservices.
Patent Information
- Application Number
- CN202411230148.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-04
- Publication Date
- 2025-02-21
- Estimated Expiration
- 2044-09-04
AI Technical Summary
The existing k8s cluster offline deployment solution cannot be applied to multi-architecture deployment, and the steps are cumbersome, not suitable for on-site deployment environments, and cannot meet the needs of continuous integration of enterprise microservices.
Provide a hybrid architecture k8s cluster offline deployment method. By generating predefined configuration files, obtaining local software offline files and image files, building image file name parameters in multi-architecture deployment, and importing local images to realize multi-architecture and offline deployment.
This method can be applied to offline deployment of K8s multi-cpu architecture clusters, without the need to install file servers and mirror warehouses, and is suitable for on-site mobile deployment to meet the needs of continuous integration of enterprise microservices.
Smart Images

Figure CN118733068B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of microservice integration technology, and in particular to a hybrid architecture k8s cluster offline deployment method, system, device and storage medium. Background Art
[0002] Kubernetes (k8s for short) is an open source container cluster management system that can realize the functions of automated deployment, automated expansion and contraction, maintenance, and monitoring of container clusters, and has been widely used in the market. For enterprises with too many microservices, continuous integration is required, and they do not want to execute commands manually. They only need to submit the yaml configuration file of kubernetes to deploy in a pipeline and improve production efficiency. There are already widely used products. Kubespray can run on bare metal and most clouds. It is a common deployment method at the operating system level, and uses ansible as its configuration and orchestration. It is more flexible and easier to use, and has been widely used in k8s automated deployment. When using the Kubespray document, provide node information, submit yaml file configuration, and execute a command to install it with one click, but most of the files and images are in foreign addresses, and there are problems such as failure to download or slow speed, which does not meet the needs of continuous integration and offline deployment.
[0003] In k8s installation, after installing kubeadm, you also need to install kube-apiserver, kube-proxy, kube-controller, coredns, ingress components, cni network plug-ins such as flannel or calico and other components. These components are installed in a k8s cluster using yaml files. Each yaml file uses the same image name, so an image name needs to adapt to the architecture of all machines in the cluster. In existing k8s cluster offline deployment solutions, such as Chinese patent CN115857955A, a method, device, equipment and storage medium for offline deployment of K8S clusters, this solution has different architectures due to the predefined configuration information may be the same, and the yaml files in k8s are the same, and the predefined image warehouse projects generated using config-sample.yaml are consistent, which makes it impossible to use for multi-architecture deployment; another example is Chinese patent CN114020288A, a method for offline deployment of Kubernetes clusters, which requires using centos to create an offline software warehouse before deploying the cluster, and then using re As a container image repository, gistry has cumbersome steps and needs to modify the software and image repository address in the default configuration of kubespray. If it needs to be deployed on site, it will not only take more time, but also occupy server resources to deploy software warehouses and image warehouses, which is not suitable for on-site deployment environments. Another example is Chinese patent CN116009897A, a multi-architecture harbor-operator integration and deployment method, system, device and storage medium. This solution also needs to deploy the image warehouse first, and also requires the software and image warehouse address of the default configuration of kubespray. The steps are cumbersome and not suitable for on-site deployment environments. Therefore, there is an urgent need for a solution that can be deployed in multiple architectures and offline to meet the needs of continuous integration of enterprise microservices. Summary of the invention
[0004] To this end, the present invention provides a hybrid architecture k8s cluster offline deployment method, system, device and storage medium to solve the problem that the existing k8s cluster offline deployment application is limited and not suitable for on-site deployment environment.
[0005] According to the design scheme provided by the present invention, on the one hand, a hybrid architecture k8s cluster offline deployment method is provided, comprising:
[0006] Generate predefined configuration files based on application deployment requirements;
[0007] Obtain the local software offline files required for application deployment according to the predefined configuration files, install the local software offline files to the target host of the k8s cluster and install the files;
[0008] Build the image file name parameters in multi-architecture deployment according to the predefined configuration file, and obtain the target image file name parameters in the specified architecture;
[0009] Obtain the offline image file package according to the target image file name parameter, and import the local image on the target host of the k8s cluster based on the offline image file package.
[0010] As the hybrid architecture k8s cluster offline deployment method of the present invention, further, a predefined configuration file is generated according to the application deployment requirements, including:
[0011] Set the file download address and version number according to the application deployment requirements, and generate a predefined configuration file to configure the server resource k8s cluster information;
[0012] Build a script based on the predefined configuration file and k8s cluster information to use the script to generate the application required software file and image file download address.
[0013] As the hybrid architecture k8s cluster offline deployment method of the present invention, further, obtaining the local software offline file required for application deployment according to the predefined configuration file includes:
[0014] Generate file parameter data according to a predefined configuration file, wherein the file parameter data includes file parameters and image parameters to be downloaded, wherein the file parameters include: file name, file format, file version number, file destination address, file checksum, file URL path, file permissions and file group, and the image parameters include: image name, image repository, image version number, image signature summary and image group;
[0015] Generate a local file directory and format based on the file parameter data to copy the local file to the k8s cluster target host based on the file destination address, file permissions, and the group to which the file belongs.
[0016] As the hybrid architecture k8s cluster offline deployment method of the present invention, further, the image file name parameter in the multi-architecture deployment is constructed according to the predefined configuration file, including:
[0017] Construct the image file name parameter based on the image name and image version number;
[0018] The image name in the image file name parameter is adjusted to the image name under multi-architecture deployment, where the image name under multi-architecture deployment is represented by a SHA256 digest.
[0019] As the hybrid architecture k8s cluster offline deployment method of the present invention, further, the image name under the multi-architecture deployment is expressed as: image name@sha256:digest, wherein digest is the architecture name summary.
[0020] As the hybrid architecture k8s cluster offline deployment method of the present invention, further, obtaining the target image file name parameter in the specified architecture includes:
[0021] Set the target host architecture in the current deployment environment of the k8s cluster as the target architecture name;
[0022] Adjust the image name in the image file name parameter under multi-architecture deployment according to the target architecture name to obtain the target image file name parameter in the specified architecture.
[0023] As the hybrid architecture k8s cluster offline deployment method of the present invention, further, the offline image file package is obtained according to the target image file name parameter, including:
[0024] According to the target image file name parameter, use the script to obtain the folder hierarchy relationship and build a complete image compression package file name parameter;
[0025] Get the local offline image compression package file according to the complete image compression package file name parameter, and copy the local offline image compression package file to the k8s cluster target host according to the image destination address, image file permissions and the group to which the image belongs.
[0026] On the other hand, the present invention also provides a hybrid architecture k8s cluster offline deployment system, comprising: a software configuration module, a software installation module, an image configuration module and an image import module, wherein:
[0027] Software configuration module, used to generate predefined configuration files according to application deployment requirements;
[0028] The software installation module is used to obtain the local software offline files required for application deployment according to the predefined configuration files, install the local software offline files to the target host of the k8s cluster and perform file installation;
[0029] The image configuration module is used to construct the image file name parameters in the multi-architecture deployment according to the predefined configuration file, and obtain the target image file name parameters in the specified architecture;
[0030] The image import module is used to obtain the offline image file package according to the target image file name parameter, and import the local image on the target host of the k8s cluster based on the offline image file package.
[0031] In another aspect, the present invention further provides an electronic device, comprising:
[0032] at least one processor, and a memory coupled to the at least one processor;
[0033] The memory stores a computer program, and the computer program can be executed by the at least one processor to implement the method as described above.
[0034] In yet another aspect, the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed, the method as described above can be implemented.
[0035] Beneficial effects of the present invention:
[0036] The present invention can be applied to offline deployment of k8s multi-CPU architecture clusters through image name replacement and local image import. It does not need to install file servers and image repositories before using kubespray, and does not need to configure files and image repositories names before each installation. It can be applied to on-site mobile deployment, and all installation files, software files and images are copyable and movable, which can meet the application deployment requirements of enterprise microservice continuous integration. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 This is a schematic diagram of the offline deployment process of the hybrid architecture k8s cluster in the embodiment;
[0038] Figure 2 The following is an illustration of the principle of the offline deployment algorithm in the embodiment. DETAILED DESCRIPTION
[0039] In order to make the purpose, technical solutions and advantages of the present invention clearer and more understandable, the present invention is further described in detail below in conjunction with the accompanying drawings and technical solutions.
[0040] Embodiments of the present invention, see Figure 1 As shown, a hybrid architecture k8s cluster offline deployment method is provided, including:
[0041] S101. Generate a predefined configuration file according to application deployment requirements.
[0042] Specifically, the file download address and version number can be set according to the application deployment requirements, and a predefined configuration file can be generated to configure the server resource k8s cluster information; a script can be built based on the predefined configuration file and k8s cluster information to use the script to generate the application requirement software file and image file download address.
[0043] You can modify the file download URL and version number as needed, modify the predefined configuration file, and configure the server resource k8s cluster information. Based on the predefined configuration file and k8s cluster information and the running file generation script generate_list.sh, generate the required software files files.list and image file download address images.list.
[0044] S102. Obtain the local software offline files required for application deployment according to the predefined configuration file, install the local software offline files to the k8s cluster target host and install the files.
[0045] Specifically, file parameter data can be generated according to a predefined configuration file, and the file parameter data include the file parameters and image parameters to be downloaded, and the file parameters include: file name, file format, file version number, file destination address, file verification code, file URL path, file permissions and the group to which the file belongs. The image parameters include: image name, image warehouse, image version number, image signature summary and the group to which the image belongs; a local file directory and format are generated according to the file parameter data to copy local files to the target host of the k8s cluster according to the file destination address, file permissions and the group to which the file belongs.
[0046] Execute the kubespray command to install the k8s cluster. Kubespray is a tool that can be used to deploy production-level k8s clusters. It can be used to deploy k8s clusters in environments such as GCE, Azure, OpenStack, and AWS. In Kubespray, cluster configuration is mainly performed through inventory files and variable files. The inventory file defines the hosts that Ansible needs to manage, while the variable file is used to customize the Kubernetes cluster. In terms of cluster management, Kubespray relies on executing a series of Ansible-playbook commands. Each operation on the cluster has a corresponding Ansible script, which covers cluster deployment, scaling, upgrading, cleanup, and other cluster life cycle management. In this case embodiment, see Figure 2 The algorithm shown generates the file parameter downloads according to the predefined configuration file. The file directory and format can be generated according to downloads, and the files in the specified directory of the local machine can be obtained. According to the file destination address, file permissions, and group, the local offline files are copied to the target host of the k8s cluster, and then decompressed and installed.
[0047] S103: Construct image file name parameters in multi-architecture deployment according to a predefined configuration file, and obtain target image file name parameters in a specified architecture.
[0048] Specifically, an image file name parameter may be constructed according to the image name and the image version number; the image name in the image file name parameter is adjusted to the image name under multi-architecture deployment, and the image name under the multi-architecture deployment is represented by a SHA256 digest.
[0049] Generate the image file name parameter according to the image name and version number generated by downloads, change the image name: tag mode to image name@sha256:digest, and replace digest with the architecture name X86 or Arm. Then the target image file name parameter can be changed to image name@sha256:architecture name.
[0050] The target host architecture in the current deployment environment of the k8s cluster is used as the target architecture name; the image name in the image file name parameter under multi-architecture deployment can be adjusted according to the target architecture name to obtain the target image file name parameter in the specified architecture.
[0051] S104. Obtain an offline image file package according to the target image file name parameter, and import the local image on the target host of the k8s cluster based on the offline image file package.
[0052] Specifically, according to the target image file name parameter, the script can be used to obtain the folder hierarchy relationship and construct a complete image compression package file name parameter; based on the complete image compression package file name parameter, the local offline image compression package file is obtained to copy the local offline image compression package file to the k8s cluster target host according to the image destination address, image file permissions and the group to which the image belongs.
[0053] According to the image name parameter, you can execute the shell script, separate the folder hierarchy with underscores, and generate a completed image tar package file name parameter. According to the image tar package file name parameter, add a judgment module to determine whether the image tar package exists in the specified directory of the local machine, copy the local image to the target host of the k8s cluster according to the image destination address in downloads, the image file permissions, and the group to which it belongs, and import the local image.
[0054] Continue to execute kubespray until the k8s cluster hybrid architecture deployment and installation is completed.
[0055] like Figure 2 The offline deployment algorithm shown can be applied to k8s multi-CPU architecture clusters through image name adjustment and local image import. It does not need to install file servers and image repositories before using kubespray, and does not need to configure files and image repositories names before each installation. The algorithm only needs to configure and generate predefined files once, which is applicable to on-site mobile deployment. All installation files, software files and images are copyable and movable, and has good application prospects in the field of continuous integration and deployment of enterprise microservices.
[0056] For kubespray installation of k8s cluster, you can add cni network plug-in selection. For the upgrade of the current network plug-in version, modify the original network plug-in mode of kubespray, separate the network plug-in installation, and change it to playbook installation. Then, each time the network plug-in is upgraded, you do not need to modify kbuespray, but only need to modify the separate network plug-in playbook.
[0057] Further, based on the above method, an embodiment of the present invention also provides a hybrid architecture k8s cluster offline deployment system, comprising: a software configuration module, a software installation module, an image configuration module and an image import module, wherein:
[0058] Software configuration module, used to generate predefined configuration files according to application deployment requirements;
[0059] The software installation module is used to obtain the local software offline files required for application deployment according to the predefined configuration files, install the local software offline files to the target host of the k8s cluster and perform file installation;
[0060] The image configuration module is used to construct the image file name parameters in the multi-architecture deployment according to the predefined configuration file, and obtain the target image file name parameters in the specified architecture;
[0061] The image import module is used to obtain the offline image file package according to the target image file name parameter, and import the local image on the target host of the k8s cluster based on the offline image file package.
[0062] Furthermore, an embodiment of the present invention further provides an electronic device, including:
[0063] at least one processor, and a memory coupled to the at least one processor;
[0064] The memory stores a computer program, and the computer program can be executed by the at least one processor to implement the method as described above.
[0065] Furthermore, an embodiment of the present invention also provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed, the method described above can be implemented.
[0066] Unless otherwise specifically stated, the relative steps, numerical expressions and values of the components and steps set forth in these embodiments do not limit the scope of the present invention.
[0067] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the system disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0068] The units and method steps of each example described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. A person of ordinary skill in the art may use different methods to implement the described functions for each specific application, but such implementation is not considered to be beyond the scope of the present invention.
[0069] Those skilled in the art will appreciate that all or part of the steps in the above method can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium, such as a read-only memory, a disk or an optical disk. Optionally, all or part of the steps in the above embodiment can also be implemented using one or more integrated circuits, and accordingly, each module / unit in the above embodiment can be implemented in the form of hardware or in the form of software function modules. The present invention is not limited to any specific form of combination of hardware and software.
[0070] Finally, it should be noted that the above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims
1. A hybrid architecture k8s cluster offline deployment method, characterized in that: Include: Generate predefined configuration files based on application deployment requirements; Obtain the local software offline files required for application deployment according to the predefined configuration file, install the local software offline files to the k8s cluster target host and perform file installation; wherein, obtaining the local software offline files required for application deployment according to the predefined configuration file includes: generating file parameter data according to the predefined configuration file, the file parameter data includes the software binary file parameters and image parameters required to be downloaded, the software binary file parameters include: file name, file format, file version number, file destination address, file checksum, file URL path, file permissions and file group, the image parameters include: image name, image warehouse, image version number, image signature summary and image group; generating a local file directory and format according to the software binary file parameter data, so as to copy the local file to the k8s cluster target host according to the file destination address, file permissions and file group; Constructing the image file name parameter in the multi-architecture deployment according to the predefined configuration file, and obtaining the target image file name parameter in the specified architecture; wherein, constructing the image file name parameter in the multi-architecture deployment according to the predefined configuration file includes: constructing the image file name parameter according to the image name and the image version number; adjusting the image name in the image file name parameter to the image name under the multi-architecture deployment, wherein the image name under the multi-architecture deployment is represented by the SHA256 digest; obtaining the target image file name parameter in the specified architecture, including: taking the target host architecture in the current deployment environment of the k8s cluster as the target architecture name; adjusting the image name in the image file name parameter under the multi-architecture deployment according to the target architecture name to: image name@sha256: target architecture name, so as to obtain the target image file name parameter in the specified architecture; Obtain the offline image file package according to the target image file name parameter, and import the local image on the target host of the k8s cluster based on the offline image file package.
2. The hybrid architecture k8s cluster offline deployment method according to claim 1 is characterized in that: Generate predefined configuration files based on application deployment requirements, including: Set the file download address and version number according to the application deployment requirements, and generate a predefined configuration file to configure the server resource k8s cluster information; Build a script based on the predefined configuration file and k8s cluster information to use the script to generate the application required software file and image file download address.
3. The hybrid architecture k8s cluster offline deployment method according to claim 1 is characterized in that: The image name under the multi-architecture deployment is expressed as: image name@sha256:digest.
4. The hybrid architecture k8s cluster offline deployment method according to claim 1 is characterized in that: Get the offline image file package according to the target image file name parameter, including: According to the target image file name parameter, use the script to obtain the folder hierarchy relationship and build a complete image compression package file name parameter; Get the local offline image compression package file according to the complete image compression package file name parameter, and copy the local offline image compression package file to the k8s cluster target host according to the image destination address, image file permissions and the group to which the image belongs.
5. A hybrid architecture k8s cluster offline deployment system, characterized in that: Contains: software configuration module, software installation module, image configuration module and image import module, among which, Software configuration module, used to generate predefined configuration files according to application deployment requirements; The software installation module is used to obtain the local software offline files required for application deployment according to the predefined configuration file, install the local software offline files to the k8s cluster target host and perform file installation; wherein, obtaining the local software offline files required for application deployment according to the predefined configuration file includes: generating file parameter data according to the predefined configuration file, the file parameter data includes the software binary file parameters and image parameters required to be downloaded, the software binary file parameters include: file name, file format, file version number, file destination address, file checksum, file URL path, file permissions and file group, the image parameters include: image name, image warehouse, image version number, image signature summary and image group; generating a local file directory and format according to the software binary file parameter data, so as to copy the local file to the k8s cluster target host according to the file destination address, file permissions and file group; An image configuration module is used to construct an image file name parameter in a multi-architecture deployment according to a predefined configuration file, and obtain a target image file name parameter in a specified architecture; wherein, constructing an image file name parameter in a multi-architecture deployment according to a predefined configuration file includes: constructing an image file name parameter according to an image name and an image version number; adjusting the image name in the image file name parameter to an image name under a multi-architecture deployment, wherein the image name under the multi-architecture deployment is represented by a SHA256 digest; obtaining a target image file name parameter in a specified architecture, including: using a target host architecture in the current deployment environment of the k8s cluster as a target architecture name; adjusting the image name in the image file name parameter under the multi-architecture deployment to: image name@sha256: target architecture name according to the target architecture name, so as to obtain a target image file name parameter in the specified architecture; The image import module is used to obtain the offline image file package according to the target image file name parameter, and import the local image on the target host of the k8s cluster based on the offline image file package.
6. An electronic device, characterized in that: include: at least one processor, and a memory coupled to the at least one processor; The memory stores a computer program, and the computer program can be executed by the at least one processor to implement the method according to any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed, the method according to any one of claims 1 to 4 can be implemented.
Citation Information
Patent Citations
Multi-architecture harbor-operator integration and deployment method, system and device and storage medium
CN116009897A
Method for offline deployment of Kubernetes cluster
CN114020288A
Updating deployment method, device and equipment based on k8s micro-service cluster and medium
CN114816476A