Rapid configuration method and system based on kubernetes resource objects
Patent Information
- Application Number
- CN202311782459.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-22
- Publication Date
- 2026-09-25
- Estimated Expiration
- 2043-12-22
AI Technical Summary
[0006]本发明的目的是克服现有技术中在Kubernetes集群环境的容器中各项目软件运行配置和部署操作复杂,花费时间较长,操作人员需要学习多种资源对象数据增加学习成本的缺陷,提供一种基于Kubernetes资源对象的快速配置方法和系统
[0020]本发明的有益效果是:通过本发明的方法操作人员只需配置软件服务使用的表格文件,并在文件中设置对应服务部署的Kubernetes资源对象参数。各项目的填写内容都用统一的表格文件sheet模板,服务集中化配置方式使得更直观的掌握软件微服务使用情况,减少配置时间,降低学习成本;
Smart Images

Figure CN117908980B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to cloud-native technologies, and in particular to a rapid configuration method and system based on Kubernetes resource objects. Background Technology
[0002] Currently, the self-developed signal software is built using cloud-native technologies. Each project's software runs and is deployed in containers within a Kubernetes cluster environment, which is created and managed by Rancher. As the number of microservices in the software increases, so do the corresponding resource configuration items. Ensuring the correctness, convenience, and efficiency of creating and running service containers is crucial. In practice, starting the software in the Kubernetes environment requires operations on the Rancher platform. Each service's resource object is configured individually in the Rancher page before starting, and Rancher then creates the container in the Kubernetes environment in the background. Since each service in a microservice architecture needs a corresponding container program to start in Kubernetes, this approach presents the following problems: 1. When deploying workload resource objects for services in the Rancher interface, you need to fill in configuration information such as type, Docker image, namespace, host scheduling, data volume mounting, command, port mapping rules, scaling strategy, etc. There are many configuration items and the operation is complicated. Different services have different configurations and errors often occur.
[0003] 2. The software contains hundreds of microservices, and the workload of each service must be created by Rancher, which will take a long time to configure and deploy.
[0004] 3. The number of microservices that need to be deployed varies from project to project depending on the on-site usage. There is no unified and intuitive microservice deployment configuration file to help identify the microservices that need to be deployed.
[0005] 4. The deployment process requires operators to understand the resource object data that different service programs need to configure, which increases the learning cost of the software deployment process. Summary of the Invention
[0006] The purpose of this invention is to overcome the shortcomings of existing technologies, such as the complexity and time-consuming operation of software configuration and deployment in containers within a Kubernetes cluster environment, and the increased learning cost for operators who need to learn various resource object data. This invention provides a rapid configuration method and system based on Kubernetes resource objects.
[0007] The objective of this invention is achieved through the following technical solution: A quick configuration method based on Kubernetes resource objects includes the following steps: Step 1: Each project configures basic Kubernetes configuration parameters using a table document; Step 2: Define the structure data format file for public resource objects; Step 3: Execute the programming language program to read the table document information. At the same time, the programming program loads the content of the data format file, associates the public resource object structure with the content set in the table document, and automatically fills in the parameters of each service-related resource object to generate a complete data format resource object structure. Step 4: The programming language program outputs the complete data format resource object structure content generated in Step 3 to the specified data format file one by one. A data format file can contain the structure of multiple resource objects. Step 5: Automatically generate command-line scripts in the programming language program; Step 6: Execute the command-line script in the Kubernetes cluster environment to automatically deploy and create all resource objects in the data format file with one click.
[0008] Preferably, the data format file is a YAML file, the programming language is Python, and the command-line script is a shell script.
[0009] Kubernetes (K8s) is an open-source application used to manage containerized applications across multiple hosts in a cloud platform. Kubernetes aims to make deploying containerized applications simple and efficient, providing a mechanism for application deployment, planning, updating, and maintenance. YAML is a highly readable format used to express data serialization. Python is a programming language.
[0010] Preferably, step 1 specifically involves setting up a table document with the software service usage information and the workloads to be created, including the image name and version in the service container to be started by the workload, YAML structure keywords, deployment host node, virtual IP, port and port mapping, service association configuration, and image startup command information.
[0011] Preferably, in step 2, the YAML file includes the scheduling policy, affinity, resource limits, and data volume association usage information for all workloads' pods.
[0012] Preferably, the table documents in step 1 include sheet 1 and sheet 2, sheet 1 lists the service information in the software, and sheet 2 sets the workload to be created for the service.
[0013] Preferably, the content to be filled in sheet 1 includes: Program service name: The name of each service in the software; Service image address: The service image used by the container in the Kubernetes workload resource object, which is the image that needs to be pulled when starting the resource object; Service image version: Specifies the version number of the service image; Structure keywords: Structure keywords in a YAML file that associate public resource object structures; Program startup command: The command to start a service within a container.
[0014] Preferably, the content to be filled in sheet 2 includes: Service Name: The service name associated with service_images; Deployment Nodes: Deploy to the corresponding worker nodes in the Kubernetes cluster based on the information provided. Virtual IPs and ports for service applications: The virtual IPs and ports of each service image in the Kubernetes cluster; CPU / Memory Limits: Limits on CPU and memory resources used by individual services during operation in a Kubernetes cluster.
[0015] Preferably, in step 3, the public resource object structure specifically includes: Service discovery: Utilizes NodePort to map container ports, service ports, and Kubernetes cluster node ports to the ports configured in Kubernetes_apps. After configuration, access to the corresponding container interface is via kube-dns or a virtual IP address. CronJob batched periodic task workloads: Periodically start pods to execute corresponding commands based on defined cycle times. DaemonSet daemon workloads: This workload creates a pod on each node in the cluster to copy the service program's configuration file to each node's disk. Deployment: A stateless workload type used by all microservice applications. Containers in a pod must mount a node path data volume to obtain the service application's configuration.
[0016] A rapid configuration system based on Kubernetes resource objects, including: A table document used to configure basic Kubernetes configuration parameters; A Python program used to automatically generate shell scripts; The deployment module is used to execute shell scripts in a Kubernetes cluster environment to automatically deploy and create all resource objects in a YAML file with a single click.
[0017] The aforementioned forms, Python programs, and deployment modules are all integrated on the computer.
[0018] As a preferred option, the rapid configuration system based on Kubernetes resource objects also includes a processor and memory; The processor is connected to the memory; The memory is used to store executable program code; The processor reads executable program code stored in the memory and runs a program corresponding to the executable program code to perform the steps of the above method.
[0019] A computer-readable storage medium having a computer program stored thereon, the computer-readable storage medium storing instructions that, when executed on a computer or processor, cause the computer or processor to perform the steps of the above-described method.
[0020] The beneficial effects of this invention are: Using the method of this invention, operators only need to configure the form file used by the software service and set the Kubernetes resource object parameters for the corresponding service deployment in the file. All items use a unified form file template, and the centralized service configuration method allows for a more intuitive understanding of the software microservice usage, reducing configuration time and lowering the learning cost. Services configured in the service usage form file will automatically generate a YAML resource object structure. This process verifies the resource object structure for errors, checks the validity of resource object parameters, and ensures service port conflicts. This guarantees the correctness and validity of the resource object structure, and the entire execution process is highly efficient, quickly outputting the resource object structure YAML files for all software microservices. This invention provides one-click automated deployment of Kubernetes resource objects, eliminating the need for manual operation using the Rancher interface during the startup process of hundreds of microservice containers. This simplifies the operation, making it accessible to ordinary users and shortening software deployment time. Attached Figure Description
[0021] Figure 1 This is a flowchart of the present invention; Figure 2 This invention uses an Excel document content image; Figure 3 This is a diagram of the public resource object structure of this invention; Figure 4 This is a flowchart of the Python program processing of this invention. Detailed Implementation
[0022] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0023] Example: A rapid configuration method based on Kubernetes resource objects, such as Figure 1 As shown, it includes the following steps: Step 1: Each project configures basic Kubernetes configuration parameters using an Excel document; Step 2: Define the public resource object structure YAML file; Step 3: Execute the Python program to read the information in the Excel document. At the same time, the Python program loads the contents of the YAML file, associates the public resource object structure with the contents set in the Excel document, and automatically fills in the parameters of each service-related resource object to generate a complete YAML format resource object structure. Step 4: In the Python program, the complete YAML format resource object structure generated in Step 3 is output to the specified YAML file one by one. A YAML file can contain the structure of multiple resource objects. Step 5: Automatically generate a shell script in the Python program; Step 6: Execute a shell script in the Kubernetes cluster environment to automatically deploy and create all resource objects in the yaml file with one click.
[0024] Step 1 specifically involves setting up the software service usage information and the workloads to be created in the Excel document, including the image name and version in the service container to be started by the workload, YAML structure keywords, deployment host node, virtual IP, port and port mapping, service association configuration, and image startup command information.
[0025] In step 2, the YAML file includes scheduling policies, affinity, resource limits, and data volume association information for all workloads' pods. Most resource object structures in the Excel document are shared, but some include custom resource object structures. The common resource object structure YAML file can be used across various projects.
[0026] In step 1, the Excel document includes Sheet 1 and Sheet 2. Sheet 1 contains service information from the software, and Sheet 2 sets the workload to be created for the service.
[0027] like Figure 2 As shown, Sheet 1 is the service_images table, and the content to be filled in includes: Program service name: The name of each service in the software; Service image address: The service image used by the container in the Kubernetes workload resource object, which is the image that needs to be pulled when starting the resource object; Service image version: Specifies the version number of the service image; Structure keywords: Structure keywords in a YAML file that associate public resource object structures; Program startup command: The command to start a service within a container.
[0028] Sheet 2 is the k8s_apps table, and the content to be filled in includes: Service Name: The service name associated with service_images; Deployment Nodes: Deploy to the corresponding worker nodes in the Kubernetes cluster based on the information provided. Virtual IPs and ports for service applications: The virtual IPs and ports of each service image in the Kubernetes cluster; CPU / Memory Limits: Limits on CPU and memory resources used by individual services during operation in a Kubernetes cluster.
[0029] like Figure 3 As shown, in step 3, the public resource object structure specifically includes: Service discovery: Using NodePort, ports within containers, service ports, and Kubernetes cluster node ports can be mapped. Figure 2 The port configured in k8s_apps can be accessed via kube-dns or a virtual IP after setting. CronJob batch periodic task workload: According to the periodic time definition, it periodically starts pods to execute corresponding command operations. DaemonSet daemon process workload: This workload creates a pod on each node in the cluster to copy the configuration file of the service program to the disk of each node. Deployment: A stateless workload type used by all microservice applications. Containers in a pod must mount a node path data volume to obtain the service application's configuration.
[0030] The core of this embodiment's method lies in the Python processing program, which converts manually visualized input into resource object structure files recognizable by the Kubernetes runtime environment and generates a one-click deployment creation script. The specific processing flow is as follows: Figure 4 As shown: 1. The program first loads the various resource objects defined in the common resource object structure YAML file and stores them in a dict type object, which is a key-value data structure.
[0031] 2. Define a KubernetesRes resource object class. Class attributes include the namespace, domain, service, structural key, port, image, deployment node, resource limits, and startup command. The program parses the content from the Excel document used by the service and validates these values. For each service's workload, an instance variable of the KubernetesRes class is created, and the content from the document is integrated and assigned to the variable's attribute. All KubernetesRes instance variables are stored in a list collection.
[0032] 3. Iterate through the list of instance variables of the KubernetesRes class and create a corresponding YAML format resource object structure based on the attribute value of each KubernetesRes instance variable.
[0033] a. First, obtain the corresponding workload resource object structure from the basic resource structure dict object through the structure key in the attribute, and then populate the basic structure according to the attribute.
[0034] b. Configure workload deployment and scheduling strategies and node affinity.
[0035] c. Determine the specific service and set the environment variables to be used within the container structure.
[0036] d. Some service containers require other services to start first, setting the readiness conditions for the working service status.
[0037] e. The images used by containers in a workload.
[0038] f. Configuration related to container resource limits.
[0039] g. Container startup command settings.
[0040] h. Configuration of data volume relationships mounted on the container.
[0041] i. Create the service discovery resource object associated with the workload and complete the port adaptation.
[0042] j. Combine the configuration structures generated above to generate a complete YAML format resource object structure.
[0043] 4. Export the obtained workload and service discovery resource object structure content to the corresponding YAML file according to the service function domain.
[0044] 5. The program combines all the generated YAML files to define statements based on the `kubectl apply` command and outputs them to a shell script file.
[0045] A rapid configuration system based on Kubernetes resource objects, including: An Excel document used to configure basic Kubernetes configuration parameters; A Python program used to automatically generate shell scripts; The deployment module is used to execute shell scripts in a Kubernetes cluster environment to automatically deploy and create all resource objects in a YAML file with a single click.
[0046] The Excel document, Python program, and deployment module are all integrated on the computer.
[0047] The rapid configuration system based on Kubernetes resource objects also includes processors and memory; The processor is connected to the memory; The memory is used to store executable program code; The processor reads executable program code stored in the memory and runs a program corresponding to the executable program code to perform the steps of the above method.
[0048] Embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program including a computer program for performing the methods shown in the flowchart. In such embodiments, the computer program can be downloaded and installed from a network via communication section 509, and / or installed from removable medium 511. When the computer program is executed by central processing unit (CPU) 501, it performs various functions defined in the system of this application.
[0049] It should be noted that the computer-readable medium shown in the embodiments of this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, portable compact disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying a computer-readable computer program. The transmitted data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to wireless, wired, etc., or any suitable combination thereof.
[0050] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. Each block in a flowchart or block diagram may represent a module, segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0051] The units described in the embodiments of this application can be implemented in software or hardware, and the described units can also be located in a processor. The names of these units do not necessarily limit the specific unit itself.
[0052] In another aspect, this application also provides a computer-readable medium, which may be included in the electronic device described in the above embodiments; or it may exist independently and not assembled into the electronic device. The computer-readable medium carries one or more programs that, when executed by the electronic device, cause the electronic device to perform the methods described in the above embodiments.
[0053] It should be noted that although several modules or units for the device used to perform actions have been mentioned in the detailed description above, this division is not mandatory. In fact, according to the embodiments of this application, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0054] Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, touch terminal, or network device, etc.) to execute the method according to the embodiments of this application.
[0055] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the embodiments disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein.
[0056] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.
Claims
1. A rapid configuration method based on Kubernetes resource objects, characterized by: Includes the following steps: Step 1: Each project configures basic Kubernetes configuration parameters using a spreadsheet document. Specifically, the spreadsheet document sets the software service usage information and the workloads to be created, including the image name and version of the service container to be started for the workload, YAML structure keywords, deployment host node, virtual IP, port and port mapping, service association configuration, and image startup command information. The spreadsheet document includes Sheet 1 and Sheet 2. Sheet 1 lists the service information in the software, and Sheet 2 sets the workloads to be created for the service. The content filled in Sheet 1 includes: Program service name: The name of each service in the software; Service image address: The service image used by containers in the Kubernetes workload resource object, which is the image that needs to be pulled when starting the resource object; Service image version: Specifies the version number of the service image; Structure keywords: Structure keywords in a YAML file that associate public resource object structures; Program startup command: The command to start a service within a container. The content to be filled in Sheet 2 includes: Service Name: The service name associated with service_images; Deployment Nodes: Deploy to the corresponding worker nodes in the Kubernetes cluster based on the information provided. Virtual IPs and ports for service applications: The virtual IPs and ports of each service image in a Kubernetes cluster; CPU / Memory Limits: Limits on CPU and memory resources used by each service during operation in a Kubernetes cluster; Step 2: Define the structure data format file for public resource objects; Step 3: Execute the programming language program to read the information from the table document. Simultaneously, the programming language program loads the contents of the data format file, associates the common resource object structure with the content set in the table document, and automatically populates the parameters of each service-related resource object, generating a complete data format resource object structure. The common resource object structure specifically includes: Service discovery: Using NodePort, ports in containers, service ports, and K8S cluster node ports are mapped to the ports configured in Kubernetes_apps. After configuration, the corresponding container interfaces can be accessed via kube-dns or virtual IPs. CronJob batches periodic task workloads: Based on the defined periodic time, it periodically starts pods to execute corresponding command operations; DaemonSet workload: This workload creates a Pod on each node in the cluster to copy the service program's configuration file to each node's disk; Deployment: A stateless workload type used by all microservice applications. Containers in a pod must mount a node path data volume to obtain the service application's configuration. Step 4: The programming language program outputs the complete data format resource object structure content generated in Step 3 to the specified data format file one by one. A data format file can contain the structure of multiple resource objects. Step 5: Automatically generate command-line scripts in the programming language program; Step 6: Execute the command-line script in the Kubernetes cluster environment to automatically deploy and create all resource objects in the data format file with one click.
2. The rapid configuration method based on Kubernetes resource objects according to claim 1, characterized in that, The data format file is a YAML file, the programming language is Python, and the command-line script is a shell script.
3. The rapid configuration method based on Kubernetes resource objects according to claim 2, characterized in that, In step 2, the YAML file includes scheduling policies, affinity, resource limits, and data volume association information for all workloads' pods.
4. A rapid configuration system based on Kubernetes resource objects, based on the method described in any one of claims 1-3, characterized in that, include: A table document used to configure basic Kubernetes configuration parameters; Programming language programs used to automatically generate command-line scripts; The deployment module is used to execute shell scripts in a Kubernetes cluster environment to automatically deploy and create all resource objects in the data format file with one click. The aforementioned forms, programming language programs, and deployment modules are all integrated on the computer.
5. The rapid configuration system based on Kubernetes resource objects according to claim 4, characterized in that, It also includes the processor and memory; The processor is connected to the memory; The memory is used to store executable program code; The processor runs a program corresponding to the executable program code stored in the memory to perform the steps of the method as described in any one of claims 1-3.
Citation Information
Patent Citations
Service module cross-platform deployment method, device and equipment
CN113434251A
Centralized configuration method, system and apparatus based on distributed service and medium
CN113986396A