K8S deployment method and device
By pre-installing the kubeadm basic components and modifying the configuration parameters of the yaml static files, the problem of environmental conflicts during the K8S deployment process was solved, and the successful deployment of K8S and the improvement of deployment efficiency were achieved.
Patent Information
- Application Number
- CN202410937916.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-12
- Publication Date
- 2024-10-11
AI Technical Summary
During the K8S deployment process, the configuration parameters conflict with the deployment environment, causing the deployment to fail.
Pre-install basic components through the kubeadm deployment software, create and modify the K8S configuration parameters in the yaml static file to adapt it to the deployment environment, and skip the pre-check and yaml static file creation steps during the installation process.
Achieved successful deployment of K8S, avoided conflicts between configuration parameters and the environment, and improved deployment efficiency.
Smart Images

Figure CN118760445A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of server technology, and in particular to a K8S deployment method and device. Background Art
[0002] Kubernetes, or K8S for short, is a cluster application orchestration management tool. K8S is deployed and runs on the server, carrying the operation and management of applications. In the K8S cluster, you can install, expand, upgrade, delete, and other operations on the applications running in the cluster.
[0003] In related technologies, the official kubeadm deployment software is used to deploy K8S. However, during the deployment process of K8S, some configuration parameters may conflict with the environment of the deployment end, resulting in the inability to complete the deployment of K8S. Summary of the invention
[0004] The present invention provides a K8S deployment method and device. The technical solution is as follows:
[0005] On the one hand, a K8S deployment method is provided, the method comprising:
[0006] In response to the component installation command, the basic components for providing a command execution platform in the kubeadm deployment software are installed on the deployment end;
[0007] In response to a file creation command, a yaml static file is created; the file creation command is provided by the kubeadm deployment software; the yaml static file includes K8S configuration parameters;
[0008] In response to the parameter modification command, modify the configuration parameters of K8S in the yaml static file according to the installation environment of the deployment end;
[0009] In response to the K8S installation instruction, K8S is installed according to the modified yaml static file; the K8S installation instruction carries a skip instruction, and the skip instruction is used to indicate to skip the pre-check and yaml static file creation steps during the K8S installation process.
[0010] On the other hand, a K8S deployment device is provided, the device comprising:
[0011] A component installation unit, which is used to install the basic components for providing a command execution platform in the kubeadm deployment software on the deployment end in response to the component installation command;
[0012] A file creation unit, configured to create a yaml static file in response to a file creation command; the file creation command is provided by the kubeadm deployment software; the yaml static file includes K8S configuration parameters;
[0013] A parameter modification unit, configured to modify the configuration parameters of K8S in the yaml static file according to the installation environment of the deployment end in response to a parameter modification command;
[0014] The K8S installation unit is used to respond to the K8S installation instruction and install K8S according to the modified yaml static file; the K8S installation instruction carries a skip instruction, and the skip instruction is used to indicate skipping the pre-check and yaml static file creation steps during the K8S installation process.
[0015] On the other hand, a computer device is provided, which includes a memory and a processor, the memory is used to store computer programs, and the processor is used to execute the computer programs stored in the memory to implement the steps of the K8S deployment method described above.
[0016] On the other hand, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned K8S deployment method are implemented.
[0017] On the other hand, a computer program product is provided, comprising a computer program, which implements the steps of the above-mentioned K8S deployment method when executed by a processor.
[0018] The technical solution provided by the present invention can at least bring the following beneficial effects:
[0019] Before installing K8S, use the kubeadm deployment software to install the basic components for providing the command execution platform on the deployment side. Then, use the file creation command provided in the kubeadm deployment software to create a yaml static file in the command execution platform. The yaml static file includes the configuration parameters of K8S. Modify the configuration parameters of K8S in the yaml static file according to the installation environment of the deployment side so that the modified configuration parameters are adapted to the installation environment of the deployment side. In this way, conflicts between some configuration parameters of K8S and the environment of the deployment side itself can be avoided during the installation of K8S, thereby achieving successful deployment of K8S. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0021] Figure 1 This is a flow chart of a K8S deployment method provided by an embodiment of the present invention;
[0022] Figure 2 This is a structural diagram of a K8S deployment device provided by an embodiment of the present invention;
[0023] Figure 3 It is a hardware architecture diagram of a computer device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0024] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0025] As mentioned above, K8S is deployed using the officially released kubeadm deployment software. However, during the deployment process, some configuration parameters of K8S may conflict with the deployment end environment, resulting in the inability to deploy K8S.
[0026] Based on this, by analyzing the kubeadm deployment software and K8S, it is concluded that the configuration parameters of K8S are located in the yaml static file, and the yaml static file can be created through the commands provided in the kubeadm deployment software. In this way, you can consider creating a yaml static file in advance to modify the configuration parameters of K8S so that the modified configuration parameters are compatible with the deployment end installation environment.
[0027] The specific implementation of the above concept is described below.
[0028] Please refer to Figure 1 , an embodiment of the present invention provides a K8S deployment method, the method comprising:
[0029] Step 100, in response to a component installation command, installing a basic component for providing a command execution platform in the kubeadm deployment software on the deployment end;
[0030] Step 102, in response to a file creation command, create a yaml static file; the file creation command is provided by the kubeadm deployment software; the yaml static file includes K8S configuration parameters;
[0031] Step 104, in response to the parameter modification command, modify the configuration parameters of K8S in the yaml static file according to the installation environment of the deployment end;
[0032] Step 106, in response to the K8S installation instruction, install K8S according to the modified yaml static file; the K8S installation instruction carries a skip instruction, and the skip instruction is used to indicate to skip the pre-check and yaml static file creation steps during the K8S installation process.
[0033] In an embodiment of the present invention, before K8S is installed, the basic components for providing a command execution platform are installed on the deployment end using the kubeadm deployment software in advance, and then a yaml static file is created in the command execution platform using the file creation command provided in the kubeadm deployment software. The yaml static file includes the configuration parameters of K8S. The configuration parameters of K8S in the yaml static file are modified according to the installation environment of the deployment end, so that the modified configuration parameters are adapted to the installation environment of the deployment end. In this way, the problem of conflict between some configuration parameters of K8S and the environment of the deployment end itself can be avoided during the installation of K8S, thereby achieving successful deployment of K8S.
[0034] Described below Figure 1 How the various steps are performed.
[0035] First, for step 100, in response to the component installation command, the basic components for providing a command execution platform in the kubeadm deployment software are installed on the deployment end.
[0036] In order to modify the configuration parameters of K8S in advance, you need to run the file creation command and the running parameter modification command provided in the kubeadm deployment software in advance. In order to run the file creation command and the running parameter modification command provided in the kubeadm deployment software on the deployment side, you need to ensure that the deployment side can provide a command execution platform.
[0037] In an embodiment of the present invention, a component installation command can be generated by manual triggering, and by responding to the component installation command, a basic component for providing a command execution platform in the kubeadm deployment software is installed on the deployment end.
[0038] In one embodiment of the present invention, in order to provide a command execution platform so that commands can be executed, the basic components at least include: kubelet proxy component, kubectl command component and kubeadm installation component. The functions of the above basic components are:
[0039] The kubelet proxy component is used to manage applications and various K8S resources running on the server and monitor the status of the server;
[0040] The kubectl command component is a command-line tool that uses the Kubernetes API to communicate with the control plane of the Kubernetes cluster;
[0041] The kubeadm installation component is a tool for creating a K8S cluster. It can initialize a customized K8S cluster through specified parameters or files and enable other servers to join the cluster.
[0042] By installing the above three basic components, not only the kubeadm deployment software is installed, providing the premise for the installation and deployment of K8S, but also a command execution platform can be provided so that the commands provided by the kubeadm deployment software can be recognized and responded to.
[0043] Then, for step 102, in response to a file creation command, a yaml static file is created; the file creation command is provided by the kubeadm deployment software; the yaml static file includes the configuration parameters of K8S.
[0044] K8S configuration parameters are located in the yaml static file. In the traditional way, the yaml static file is generated during the installation process of K8S. Considering that the kubeadm deployment software provides a file creation command for creating a yaml static file, the file creation command is used to generate a yaml static file in a specified format. Therefore, in an embodiment of the present invention, after the basic components are installed on the deployment end, the command execution platform is used to run the file creation command, and then respond to the file creation command to create the corresponding yaml static file.
[0045] In an embodiment of the present invention, the file creation command may include at least one of the following two commands:
[0046] The first file creation command: the command body is the kubeadminitphase command of control-plane-endpoint;
[0047] The second file creation command: The command body is the kubeadminit phase command of etcd local.
[0048] The above two commands are described below.
[0049] For the first type of file creation command, in response to the kubeadminit phase command whose command body is control-plane-endpoint, the following YAML static files can be created: kube-apiserver static file, kube-controller-manager static file, and kube-scheduler static file;
[0050] Among them, when triggering the first file creation command, it is necessary to trigger it by specifying the IP address and subnet segment. That is to say, the kubeadminit phase command with the command body as control-plane-endpoint also carries the IP address and subnet segment that conform to the installation environment of the deployment end. The IP address and the subnet segment are located in the created yaml static file, which is used to instruct the K8S to configure K8S according to the IP address and the subnet segment during the K8S installation process.
[0051] In an embodiment of the present invention, by responding to the first file creation instruction, not only can three yaml static files be created, but also the IP address and subnet segment can be specified according to the installation environment of the deployment end, so that K8S can be configured according to the IP address and the subnet segment during the installation process, avoiding conflicts with the deployment end IP during the K8S installation process.
[0052] Furthermore, when the first file creation instruction is triggered, the kubeadminit phase command whose command body is control-plane-endpoint also carries the image warehouse address of K8S. The image warehouse address is located in the created yaml static file, which is used to indicate that the K8S image file is obtained from the image warehouse address during the K8S installation process.
[0053] In the traditional installation method, the K8S image is stored in a foreign warehouse. When installing K8S, it is necessary to pull the K8S image from the foreign warehouse. The process of pulling the image from the foreign warehouse is limited by the network speed, which affects the installation speed of K8S. Based on this, the first file creation instruction can be used to specify the image warehouse address of K8S. The image warehouse address can be selected from a domestic warehouse. By storing the K8S image file in the domestic warehouse in advance, the K8S image file can be pulled from the domestic warehouse during the installation process, thereby increasing the pulling speed and thus increasing the installation speed of K8S.
[0054] An example of the first type of file creation instruction may be:
[0055] kubeadminit phase control-plane all--kubernetes-version=v1.28.2--control-plane-endpoint=192.168.193.246--pod-network-cidr=10.244.0.0 / 16--image-repository=registry.aliyuncs.com / google_containers;
[0056] It can be seen that the specified IP is 192.168.193.246, the subnet segment is 10.244.0.0 / 16, and the image warehouse address of K8S is registry.aliyuncs.com.
[0057] For the second file creation command, when responding to the kubeadminit phase command whose command body is etcd local, etcd static files can be created.
[0058] In an embodiment of the present invention, when triggering the second file creation command, the command body may also carry the image warehouse address of the etcd file. The image warehouse address is located in the created etcd static file, and is used to indicate that the etcd image file is obtained from the image warehouse address during the K8S installation process.
[0059] Similar to the specification of the image repository address of K8S, in the traditional installation method, it is necessary to pull the etcd image file from the foreign warehouse, which will affect the installation speed of K8S. Therefore, the embodiment of the present invention can increase the pulling speed of the etcd image file by specifying the etcd image repository address of the domestic warehouse, thereby increasing the installation speed of K8S.
[0060] An example of the second file creation instruction may be: kubeadminit phase etcd local --image-repository=registry.aliyuncs.com / google_containers;
[0061] It can be seen that the specified etcd mirror repository address is registry.aliyuncs.com.
[0062] Next, for step 104, in response to the parameter modification command, the configuration parameters of K8S in the yaml static file are modified according to the installation environment of the deployment end.
[0063] In an embodiment of the present invention, it is possible to determine which configuration parameters of K8S to modify based on the installation environment of the deployment end, and to modify the configuration parameters to be modified by triggering parameter modification commands to implement modification of the corresponding configuration parameters in the yaml static file.
[0064] In the embodiment of the present invention, the following K8S configuration parameters can be modified for each yaml static file:
[0065] For the kube-apiserver static file, you can modify at least one of the following K8S configuration parameters:
[0066] advertise-address: advertise address;
[0067] allow-privileged: whether to allow the container to request privileged mode;
[0068] authorization-mode: authorization mode;
[0069] enable-admission-plugins: admission control module;
[0070] enable-bootstrap-token-auth: Enable TLS bootstrap mechanism;
[0071] etcd-servers: etcd cluster address;
[0072] service-node-port-range: type default assigned port range;
[0073] secure-port: secure port;
[0074] service-account-issuer: virtual IP address segment.
[0075] For the kube-controller-manager static file, you can modify at least one of the following K8S configuration parameters:
[0076] allocate-node-cidrs: whether the cidr of the Pod should be allocated and set on the cloud provider;
[0077] bind-address: listening address;
[0078] cluster-cidr: cluster cidr;
[0079] cluster-name: cluster name;
[0080] service-cluster-ip-range: virtual IP address range.
[0081] For the kube-scheduler static file, you can modify at least one of the following K8S configuration parameters:
[0082] bind-address: listening address.
[0083] For etcd static files, you can modify at least one of the following K8S configuration parameters:
[0084] advertise-client-urls: the listening address for clients to access this node;
[0085] initial-advertise-peer-urls: the peer listening address of this node;
[0086] listen-client-urls: the listening address of the proxy;
[0087] listen-peer-urls: listening address.
[0088] An example of the parameter modification instruction may be: service-node-port-range (k8s nodePort port range).
[0089] Finally, for step 106, in response to the K8S installation instruction, K8S is installed according to the modified yaml static file; the K8S installation instruction carries a skip instruction, and the skip instruction is used to indicate to skip the pre-check and yaml static file creation steps during the K8S installation process.
[0090] After modifying the yaml static file, you can execute kubeadm to initialize K8S and then enter the K8S installation process.
[0091] Since a pre-check is performed during the K8S installation process, the pre-check is used to check whether the yaml static file is cleared, which conflicts with the yaml static file pre-created in the embodiment of the present invention. Therefore, it is necessary to instruct the K8S installation process to skip the pre-check.
[0092] In addition, since the yaml static file has been created and its parameters modified before initializing K8S, in order to prevent the yaml static file from being recreated during the K8S installation process, which would overwrite the modified yaml static file, it is necessary to instruct to skip the yaml static file creation step during the K8S installation process.
[0093] The embodiment of the present invention carries a skip instruction in the K8S installation instruction to indicate to skip the pre-check and yaml static file creation steps during the K8S installation process, thereby realizing the normal progress of the K8S installation process. The K8S installation process is installed using the modified yaml static file, thereby avoiding conflicts with the installation environment of the deployment end during the installation process and ensuring the successful installation of K8S.
[0094] An example of the K8S installation instruction can be:
[0095] kubeadminit --kubernetes-version=v1.28.2 --control-plane-endpoint={{ip}} --pod-network-cidr=10.244.0.0 / 16 --cri-socket=unix: / / / run / cri-dockerd.sock--image-repository=registry.aliyuncs.com / google_containers--skip-phases=preflight,control-plane,etcd
[0096] It can be seen that the K8S installation instruction indicates to skip the pre-check (preflight) and yaml static file creation steps (control-plane, etcd).
[0097] Furthermore, after K8S is installed, you can check whether K8S is available and whether the modified configuration parameters are effective.
[0098] Please refer to Figure 2 , an embodiment of the present invention provides a K8S deployment device, the device comprising:
[0099] A component installation unit 200 is used to install a basic component for providing a command execution platform in the kubeadm deployment software on the deployment end in response to a component installation command;
[0100] A file creation unit 202 is used to create a yaml static file in response to a file creation command; the file creation command is provided by the kubeadm deployment software; the yaml static file includes K8S configuration parameters;
[0101] A parameter modification unit 204 is used to modify the configuration parameters of K8S in the yaml static file according to the installation environment of the deployment end in response to the parameter modification command;
[0102] The K8S installation unit 206 is used to respond to the K8S installation instruction and install K8S according to the modified yaml static file; the K8S installation instruction carries a skip instruction, and the skip instruction is used to indicate skipping the pre-check and yaml static file creation steps during the K8S installation process.
[0103] In one embodiment of the present invention, the basic components include at least: a kubelet proxy component, a kubectl command component and a kubeadm installation component.
[0104] In one embodiment of the present invention, the file creation command includes: a kubeadminit phase command whose command body is control-plane-endpoint;
[0105] In response to the kubeadminit phase command whose command body is control-plane-endpoint, the following YAML static files are created: kube-apiserver static file, kube-controller-manager static file, and kube-scheduler static file;
[0106] The kubeadminit phase command with the command body of control-plane-endpoint also carries the IP address and subnet segment that conform to the installation environment of the deployment end. The IP address and the subnet segment are located in the created yaml static file, which are used to instruct the K8S to configure K8S according to the IP address and the subnet segment during the K8S installation process.
[0107] In one embodiment of the present invention, the kubeadm initphase command whose command body is control-plane-endpoint also carries the image warehouse address of K8S. The image warehouse address is located in the created yaml static file, which is used to indicate that the K8S image file is obtained from the image warehouse address during the K8S installation process.
[0108] In one embodiment of the present invention, the file creation command further includes: a kubeadminit phase command whose command body is etcd local;
[0109] In response to the kubeadminit phase command whose command body is etcd local, etcd static files are created.
[0110] In one embodiment of the present invention, the command body carries the image repository address of the etcd file, and the image repository address is located in the created etcd static file, which is used to indicate that the etcd image file is obtained from the image repository address during the K8S installation process.
[0111] It should be noted that the K8S deployment device provided in the above embodiment is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the K8S deployment device provided in the above embodiment and the K8S deployment method embodiment belong to the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.
[0112] The embodiment of the present application also provides a computer device, please refer to Figure 3 The computer device includes a processor and a memory, in which at least one instruction, at least one program, a code set or an instruction set is stored, and at least one instruction, at least one program, a code set or an instruction set is loaded and executed by the processor to implement the K8S deployment method provided in the above-mentioned method embodiments.
[0113] An embodiment of the present application also provides a computer-readable storage medium, on which is stored at least one instruction, at least one program, code set or instruction set, and the at least one instruction, at least one program, code set or instruction set is loaded and executed by a processor to implement the K8S deployment method provided by the above-mentioned method embodiments.
[0114] An embodiment of the present application also provides a computer program product, which includes a computer program. A processor of a computer device reads the computer program from a computer-readable storage medium, and the processor executes the computer program, so that the computer device executes the K8S deployment method described in any of the above embodiments.
[0115] For the convenience of description, the above system or device is described by dividing it into various modules or units according to its functions. Of course, when implementing the present application, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0116] It can be known from the description of the above implementation methods that those skilled in the art can clearly understand that the present application can be implemented by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the present application can be essentially or partly contributed to the prior art in the form of a software product, which can be stored in a storage medium such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in the various embodiments of the present application or certain parts of the embodiments.
[0117] Finally, it should be noted that, in this article, relational terms such as first, second, third and fourth are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0118] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A K8S deployment method, characterized in that: The method comprises: In response to the component installation command, the basic components for providing a command execution platform in the kubeadm deployment software are installed on the deployment end; In response to a file creation command, a yaml static file is created; the file creation command is provided by the kubeadm deployment software; the yaml static file includes K8S configuration parameters; In response to the parameter modification command, modify the configuration parameters of K8S in the yaml static file according to the installation environment of the deployment end; In response to the K8S installation instruction, K8S is installed according to the modified yaml static file; the K8S installation instruction carries a skip instruction, and the skip instruction is used to indicate to skip the pre-check and yaml static file creation steps during the K8S installation process.
2. The method according to claim 1, characterized in that: The basic components include at least: a kubelet proxy component, a kubectl command component and a kubeadm installation component.
3. The method according to claim 1, characterized in that The file creation command includes: a kubeadminit phase command whose command body is control-plane-endpoint; In response to the kubeadminit phase command whose command body is control-plane-endpoint, the following YAML static files are created: kube-apiserver static file, kube-controller-manager static file, and kube-scheduler static file; The kubeadminit phase command with the command body of control-plane-endpoint also carries the IP address and subnet segment that conform to the installation environment of the deployment end. The IP address and the subnet segment are located in the created yaml static file, which are used to instruct the K8S to configure K8S according to the IP address and the subnet segment during the K8S installation process.
4. The method according to claim 3, characterized in that The kubeadminit phase command with the command body of control-plane-endpoint also carries the image warehouse address of K8S. The image warehouse address is located in the created yaml static file and is used to indicate that the K8S image file is obtained from the image warehouse address during the K8S installation process.
5. The method according to claim 3, characterized in that: The file creation command also includes: a kubeadminit phase command whose command body is etcd local; In response to the kubeadminit phase command whose command body is etcd local, etcd static files are created.
6. The method according to claim 5, characterized in that The command body carries the image warehouse address of the etcd file, which is located in the created etcd static file and is used to indicate that the etcd image file is obtained from the image warehouse address during the K8S installation process.
7. A K8S deployment device, characterized in that: The device comprises: A component installation unit, which is used to install the basic components for providing a command execution platform in the kubeadm deployment software on the deployment end in response to the component installation command; A file creation unit, configured to create a yaml static file in response to a file creation command; the file creation command is provided by the kubeadm deployment software; the yaml static file includes K8S configuration parameters; A parameter modification unit, configured to modify the configuration parameters of K8S in the yaml static file according to the installation environment of the deployment end in response to a parameter modification command; The K8S installation unit is used to respond to the K8S installation instruction and install K8S according to the modified yaml static file; the K8S installation instruction carries a skip instruction, and the skip instruction is used to indicate skipping the pre-check and yaml static file creation steps during the K8S installation process.
8. A computer device, characterized in that: The computer device includes a memory and a processor, the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory to implement the steps of any one of the methods described in claims 1-6.
9. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method described in any one of claims 1 to 6 are implemented.
10. A computer program product, characterized in that The method comprises a computer program, wherein when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
