A method, system, device and storage medium for clock source management in a kubernetes cluster
By extending the kubectl command and providing NTP client management tools, the problem of clock synchronization configuration management in kubernetes cluster is solved, and the consistency and management of clock synchronization within the cluster is achieved.
Patent Information
- Application Number
- CN202211702621.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-28
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2042-12-28
AI Technical Summary
The existing technology is difficult to uniformly manage the clock synchronization configuration of nodes in the kubernetes cluster, resulting in inconsistent clocks and affecting the normal operation of the cluster.
By extending the kubectl command, NTP client management tools are provided, allowing administrators to directly configure and manage the cluster's clock source through the kubectl command, including viewing, checking and setting the clock source, and performing clock synchronization configuration on each node through the chrony daemonset.
It realizes unified configuration of clock synchronization within the kubernetes cluster, simplifies cluster management, improves management efficiency, and ensures the consistency of cluster node time.
Smart Images

Figure CN115826679B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software application operation control, and more specifically, to a method, system, device and storage medium for clock source management in a Kubernetes cluster. Background Art
[0002] The kubernetes cluster requires that the node time in the cluster must be accurately consistent, otherwise the cluster will not be able to operate normally. In order to ensure the normal operation of the cluster, it is necessary to configure the NTP clock source on all nodes in the cluster and configure a reliable clock synchronization strategy to prevent problems such as unreliable clock sources and clock jumps. The existing time synchronization method is to set up time synchronization tools and configurations on each node in the cluster. In the Kubernetes cluster, administrators generally use kubectl commands to manage the cluster and various components and services in the cluster. To this end, the kubectl command needs to be extended so that the kubectl command can manage the NTP configuration of the cluster. Summary of the invention
[0003] The technical problem to be solved by the present invention is to address the above-mentioned deficiencies in the prior art. One purpose of the present invention is to provide a method for clock source management in a Kubernetes cluster.
[0004] The second objective of the present invention is to provide a system for clock source management in a Kubernetes cluster.
[0005] A third object of the present invention is to provide a computer device.
[0006] A fourth objective of the present invention is to provide a computer-readable storage medium.
[0007] In order to achieve the above-mentioned objective 1, the present invention provides a method for managing a clock source in a Kubernetes cluster, which specifically comprises the following steps:
[0008] Step S1. Configure the time service component chrony in each node of the kubernetes cluster, and the time service component chrony corresponds to a pre-configured time service configuration;
[0009] Step S2. Set two different chrony configuration files in a cluster, namely, master node configuration and node node configuration. The path of the chrony configuration file is / etc / chrony.conf;
[0010] Step S3. Call the NTP client management command tool. The NTP client tool enhances the cluster management function by extending kubectl. The administrator can directly view the current clock source, check the external clock source, set the clock source and other management operations through the kubectl command; according to the requirements of the kubectl extension plug-in, name the executable file of the ntp client tool plug-in "kubectl-ntp" and copy it to a directory in $PATH;
[0011] Step S4. When executing the NTP setting subcommand, 0 to 3 external clock sources are allowed to be set. The external clock sources need to pass the NTP verification. External clock sources with too large time deviations and non-cluster nodes are rejected.
[0012] Step S5. When receiving the setting instruction, the command line tool program generates a chrony configuration template according to the configured external clock source information and saves it in configmap; the configuration template includes the master node configuration template and the node node configuration template; and adds a label of the chrony running flag to each cluster node, and then creates a chronydaemonset to execute chrony configuration updates on each node. If the daemonset already exists, the daemonset is updated. The chrony daemonset contains the chrony management program.
[0013] As a further improvement, in step S1, chrony includes a daemon program chronyd running in the background and a command line user tool chronyc. chronyd is used to adjust the system clock running in the kernel and synchronize with the clock server, and chronyc is used to monitor performance and perform various configurations.
[0014] Furthermore, in step S2, the chrony preconfiguration on the cluster nodes is as follows:
[0015] The master node of the kubernetes cluster serves as the time server for other working nodes;
[0016] In the chrony configuration of the master node, multiple masters are configured as peer servers, and local is enabled to allow local timing services to be provided;
[0017] In addition to the master node, a maximum of three external clock sources can be added. When no external clock source is added, the clock in the cluster is synchronized with the master node.
[0018] Set the time synchronization policy.
[0019] Furthermore, the time synchronization strategy includes allowing step adjustment once when a threshold is exceeded, and disabling step adjustment to prevent random jumps.
[0020] Furthermore, step S5 specifically includes:
[0021] Mount the host directory into the container by mounting a volume, and set hostPID:true to use the host PID namespace, allowing systemctl in the container to communicate with systemd on the host so that systemctl commands can be executed in the container;
[0022] Mount the chronyd configuration file / etc / chrony.conf into the container by mounting the volume. Also mount the configmap that stores the chrony configuration template into the container so that the host chronyd configuration can be modified in the container.
[0023] The chrony daemonset sets the node selector to select the label of the run flag added in each node, so that the chrony daemonset will run on each node after it is created;
[0024] The chrony daemonset container overwrites the generated chrony configuration template file to the host directory file / etc / chrony.conf, and then executes the "systemctl restart chronyd" and "systemctl enable chronyd" commands to restart the chronyd service to make the new configuration effective; when the configuration is successful, delete the label of the chrony running flag added to the node where the container is located. After the label is deleted, the chrony daemonset container of the node will be automatically destroyed, which will not affect other running chrony daemonset containers. Until all node daemonset containers run chronyd configurations are effective, the labels of the running flags of all nodes are cleared; when the chrony configuration fails, the chrony daemonset running program will set the node label running flag to the failed state. At this time, due to the mismatch of the node selector value, the chrony daemonset container of the current node will also be destroyed;
[0025] Execute the NTP view subcommand to query the labels of all nodes with the chronyd running flag, and obtain the nodes where chrony execution failed; obtain the current NTP configuration by obtaining configmap data; associate the chrony command "chronyc-nsources-v" to query the time synchronization server list and synchronization status of the current execution node;
[0026] The NTP verification subcommand can be used to check whether the external clock source is legal. By associating "ntpdate -q<server_ip> " command to check whether the external clock source server_ip is legal, and reject the external clock source with too large time deviation and non-cluster node;
[0027] Provides a cleanup command. When the operation fails, you can re-execute the setting command. You can also manually repair the chrony configuration of the node and then execute the cleanup command to delete the chrony daemonset resource and the chrony label on the node. Deleting the daemonset will delete the daemonset containers on all nodes. In addition, this command also serves as a supplement to the cleanup of chrony daemonset resources after the chrony configuration task is successful.
[0028] In order to achieve the above-mentioned second objective, the present invention provides a system for managing clock sources in a Kubernetes cluster, comprising:
[0029] Configuration module, used to configure the time service component chrony in each node of the kubernetes cluster. The time service component corresponds to a pre-configured time service configuration, and is used to set two different chrony configuration files in a cluster, namely the master node configuration and the node node configuration. The path of the chrony configuration file is / etc / chrony.conf;
[0030] The calling module is used to call the NTP client management command tool. The NTP client tool enhances the cluster management function by extending kubectl. Administrators can directly view the current clock source, check the external clock source, set the clock source, and perform other management operations through the kubectl command. According to the requirements of the kubectl extension plug-in, the executable file name of the ntp client tool plug-in is named "kubectl-ntp" and copied to a directory in $PATH.
[0031] The execution module is used to execute the NTP setting subcommand, allowing 0 to 3 external clock sources to be set. The external clock sources need to pass the NTP verification, and the external clock sources with too large time deviation and non-cluster nodes are rejected; and when receiving the setting instruction, the command line tool program generates a chrony configuration template according to the configured external clock source information and saves it to the configmap; the configuration template includes the master node configuration template and the node node configuration template; and adds a label of the chrony running flag to each cluster node, and then creates a chrony daemonset to execute the chrony configuration update on each node. If the daemonset already exists, the daemonset is updated, and the chrony daemonset contains the chrony management program.
[0032] In order to achieve the third objective above, the present invention provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the above-mentioned method for clock source management in a Kubernetes cluster when executing the computer program.
[0033] In order to achieve the above-mentioned fourth objective, the present invention provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the method for managing a clock source in a Kubernetes cluster is implemented.
[0034] Beneficial Effects
[0035] Compared with the prior art, the present invention has the following advantages:
[0036] The present invention extends kubectl in a way that the clock synchronization configuration of all nodes in the Kubernetes cluster is uniformly configured through the kubectl command in the Kubernetes cluster, which can simplify cluster management and improve management efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 A flowchart of the cluster NTP external clock source setting in the present invention;
[0038] Figure 2 It is a schematic diagram of allowing configuration of three external clock sources in the present invention. DETAILED DESCRIPTION
[0039] The present invention will be further described below with reference to the specific embodiments in the accompanying drawings.
[0040] See also Figure 1-2 , a method for clock source management in a kubernetes cluster, specifically comprising the following steps:
[0041] Step S1. Configure the time service component chrony in each node of the kubernetes cluster. The time service component chrony corresponds to a pre-configured time service configuration. chrony includes the chronyd background daemon and the chronyc command line user tool. chronyd is used to adjust the system clock running in the kernel and the clock server synchronization. chronyc is used to monitor performance and perform various configurations.
[0042] Step S2. Set up two different chrony configuration files in a cluster, one for the master node (management node) and one for the node (worker node). The path of the chrony configuration file is / etc / chrony.conf. The chrony pre-configuration on the cluster node is as follows:
[0043] 1. The master node of the kubernetes cluster serves as the time server for other working nodes.
[0044] 2. In the chrony configuration of the master node, multiple masters are configured as peer servers, and local is enabled to allow local timing services to be provided.
[0045] 3. In addition to the master node, add up to 3 external clock sources. You do not need to add external clock sources. When no external clock sources are added, the cluster is synchronized with the master node clock. Figure 2 As shown in the figure, three external clock sources can be configured. Within the cluster, the master node is configured as the time server node, and the master nodes are peer servers to each other. Other node nodes are time client nodes that synchronize the time server nodes.
[0046] 4. Set the time synchronization policy. The time synchronization policy includes allowing step adjustment once when a threshold is exceeded, and disabling step adjustment to prevent random jumps.
[0047] Step S3. Call the NTP client management command tool. The NTP client tool enhances the cluster management function by extending kubectl. The administrator can directly view the current clock source, check the external clock source, set the clock source and other management operations through the kubectl command; according to the requirements of the kubectl extension plug-in, the executable file name of the ntp client tool plug-in is named "kubectl-ntp" and copied to a directory in $PATH (such as / usr / local / bin).
[0048] The NTP tool enhances cluster management capabilities by extending kubectl. The kubectl extension command supports the following operations:
[0049] / / Query the current cluster NTP configuration
[0050] kubectl ntp get
[0051] / / Check external clock source
[0052] kubectl ntp check<server_ip>
[0053] / / Set cluster NTP. When the ntp parameter list is empty, delete the NTP configuration.
[0054] kubectl ntp set --ntp"<server_ip1> ,<server_ip2> ,<server_ip3> "
[0055] / / ntp task cleanup
[0056] kubectl ntp cleanup
[0057] Step S4. When executing the NTP setting subcommand, it is allowed to set 0 to 3 external clock sources. The external clock source needs to pass the NTP verification, that is, pass the health check, and reject the external clock source with too large time deviation, and the non-cluster node, that is, the set external clock source server IP is not the IP of the node in the cluster, such as rejecting the external clock source with a time deviation greater than 2 minutes.
[0058] Step S5. When receiving the setting instruction, the command line tool generates a chrony configuration template according to the configured external clock source information and saves it in configmap; the configuration template includes the master node configuration template and the node node configuration template, and the content of the configuration template conforms to the rules in the chrony pre-configuration described in step 2; and adds a chrony running label to each cluster node: chrony-config=running, and then creates a chrony daemonset to execute chrony configuration updates on each node. If the daemonset already exists, the daemonset is updated, and the chrony daemonset contains the chrony management program. Step S5 specifically includes:
[0059] 1. Mount the host directory to the container by mounting a volume, and set hostPID:true to use the host PID namespace, allowing the systemctl in the container to communicate with the host's systemd so that the systemctl command can be executed in the container. As shown below:
[0060]
[0061]
[0062]
[0063] 2. Mount the chronyd configuration file / etc / chrony.conf into the container by mounting the volume; also mount the configmap that saves the chrony configuration template into the container so that the host chronyd configuration can be modified in the container.
[0064] 3. The chrony daemonset sets the node selector to select the label of the run flag added in each node, so that the chrony daemonset will run on each node after it is created.
[0065] 4. The chrony daemonset container overwrites the generated chrony configuration template file to the host directory file / etc / chrony.conf, and then executes the "systemctl restart chronyd" and "systemctl enablechronyd" commands to restart the chronyd service to make the new configuration take effect.
[0066] When the configuration is successful, delete the label of the chrony running flag added to the node where the container is located. After the label is deleted, the chrony daemonset container of the node will be automatically destroyed. This will not affect other running chronydaemonset containers. Until all node daemonset containers run chronyd configurations, all the labels of the running flags of all nodes are cleared.
[0067] When the chrony configuration fails, the chrony daemonset runner will set the node label run flag to a failed state. At this time, the chrony daemonset container of the current node will also be destroyed because the node selector value does not match.
[0068] 5. Execute the NTP view subcommand to query the labels of all nodes with the chronyd running flag, and obtain the nodes where chrony execution fails; obtain the current NTP configuration by obtaining configmap data; associate the chrony command "chronyc-nsources-v" to query the time synchronization server list and synchronization status of the current execution node.
[0069] 6. Execute the NTP verification subcommand to check whether the external clock source is legal. By associating "ntpdate-q<server_ip> " command to check whether the external clock source server_ip is legal, and reject the external clock source with too large time deviation, and it is not a node in the cluster, that is, the set external clock source server IP is not the IP of a node in the cluster.
[0070] 7. Provides a cleanup command. When the operation fails, you can re-execute the setting command, or you can manually repair the chrony configuration of the node and then execute the cleanup command to delete the chrony daemonset resources and the chrony label on the node. Deleting the daemonset will delete the daemonset containers on all nodes. In addition, this command also serves as a supplement to the cleanup of chrony daemonset resources after the chrony configuration task is successful.
[0071] A system for managing clock sources in a kubernetes cluster, comprising:
[0072] Configuration module, used to configure the time service component chrony in each node of the kubernetes cluster. The time service component corresponds to a pre-configured time service configuration, and is used to set two different chrony configuration files in a cluster, namely the master node configuration and the node node configuration. The path of the chrony configuration file is / etc / chrony.conf;
[0073] The calling module is used to call the NTP client management command tool. The NTP client tool enhances the cluster management function by extending kubectl. Administrators can directly view the current clock source, check the external clock source, set the clock source, and perform other management operations through the kubectl command. According to the requirements of the kubectl extension plug-in, the executable file name of the ntp client tool plug-in is named "kubectl-ntp" and copied to a directory in $PATH.
[0074] The execution module is used to execute the NTP setting subcommand, allowing 0 to 3 external clock sources to be set. The external clock sources need to pass the NTP verification, and the external clock sources with too large time deviation are rejected, and the external clock sources are not in the cluster. That is, the set external clock source server IP is not the IP of the cluster node; and when receiving the setting instruction, the command line tool program generates a chrony configuration template according to the configured external clock source information and saves it to the configmap; the configuration template includes the master node configuration template and the node node configuration template; and adds a label of the chrony running flag to each cluster node, and then creates a chrony daemonset to execute the chrony configuration update on each node. If the daemonset already exists, it will update the daemonset. The chrony daemonset contains the chrony management program.
[0075] A computer device includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the method for managing a clock source in a Kubernetes cluster is implemented.
[0076] A computer-readable storage medium stores a computer program, which implements the above-mentioned method for managing clock sources in a Kubernetes cluster when executed by a processor.
[0077] The above are only preferred embodiments of the present invention. It should be pointed out that for those skilled in the art, several modifications and improvements can be made without departing from the structure of the present invention, which will not affect the effect of the implementation of the present invention and the practicality of the patent.
Claims
1. A method for clock source management in a kubernetes cluster, characterized in that: The specific steps include: Step S1. Configure the time service component chrony in each node of the kubernetes cluster, and the time service component chrony corresponds to a pre-configured time service configuration; Step S2. Set two different chrony configuration files in a cluster, namely, master node configuration and node node configuration. The path of the chrony configuration file is / etc / chrony.conf; Step S3. Call the NTP client management command tool. The NTP client tool enhances the cluster management function by extending kubectl. The administrator can directly view the current clock source, check the external clock source, set the clock source and other management operations through the kubectl command; according to the requirements of the kubectl extension plug-in, name the executable file of the NTP client tool plug-in "kubectl-ntp" and copy it to a directory in $PATH; Step S4. When executing the NTP setting subcommand, 0 to 3 external clock sources are allowed to be set. The external clock sources need to pass the NTP verification. External clock sources with too large time deviations and non-cluster nodes are rejected. Step S5. When receiving the setting instruction, the command line tool program generates a chrony configuration template according to the configured external clock source information and saves it in configmap; the configuration template includes the master node configuration template and the node node configuration template; and adds a label of the chrony running flag to each cluster node, and then creates a chrony daemonset to execute chrony configuration updates on each node. If the chrony daemonset already exists, the chrony daemonset is updated, and the chrony daemonset contains the chrony management program.
2. According to claim 1, a method for managing clock sources in a kubernetes cluster is characterized in that: In step S1, chrony includes the chronyd background daemon and the chronyc command line user tool. chronyd is used to adjust the system clock running in the kernel and synchronize with the clock server. chronyc is used to monitor performance and perform various configurations.
3. According to claim 1, a method for managing clock sources in a kubernetes cluster is characterized in that: In step S2, the chrony preconfiguration on the cluster nodes is as follows: The master node of the kubernetes cluster serves as the time server for other working nodes; In the chrony configuration of the master node, multiple masters are configured as peer servers, and local is enabled to allow local timing services to be provided; In addition to the master node, a maximum of three external clock sources can be added. When no external clock source is added, the clock in the cluster is synchronized with the master node. Set the time synchronization policy.
4. According to claim 3, a method for managing clock sources in a kubernetes cluster is characterized in that: The time synchronization strategy includes allowing step adjustment once when a threshold is exceeded, and disabling step adjustment to prevent random jumps.
5. The method for managing clock sources in a kubernetes cluster according to claim 2, characterized in that: Step S5 specifically includes: Mount the host directory into the container by mounting a volume, and set hostPID: true to use the host PID namespace, allowing systemctl in the container to communicate with systemd on the host so that systemctl commands can be executed in the container; Mount the chronyd configuration file / etc / chrony.conf into the container by mounting the volume. Also mount the configmap that stores the chrony configuration template into the container so that the host chronyd configuration can be modified in the container. The chrony daemonset sets the node selector to select the label of the run flag added in each node, so that the chrony daemonset will run on each node after it is created; The chrony daemonset container overwrites the generated chrony configuration file to the host directory file / etc / chrony.conf, and then executes the "systemctl restart chronyd" and "systemctl enable chronyd" commands to restart the chronyd service to make the new configuration effective; when the configuration is successful, delete the label of the chrony running flag added to the node where the container is located. After the label is deleted, the chrony daemonset container of the node will be automatically destroyed, which will not affect other running chrony daemonset containers. Until all the chrony daemonset containers on all nodes run chronyd configurations that take effect, the labels of the running flags of all nodes are cleared; when the chrony configuration fails, the chronydaemonset running program will set the node label running flag to the failed state. At this time, due to the mismatch of the node selector value, the chrony daemonset container of the current node will also be destroyed; Execute the NTP view subcommand to query the labels of all nodes with the chronyd running flag, and obtain the nodes where chrony execution failed; obtain the current NTP configuration by obtaining configmap data; associate the chrony command "chronyc -n sources -v" to query the time synchronization server list and synchronization status of the current execution node; Executing the NTP verification subcommand can be used to check whether the external clock source is legal, by associating "ntpdate -q<server_ip> " command to check whether the external clock source server_ip is legal, and reject the external clock source with too large time deviation and non-cluster node; Provides a cleanup command. When the operation fails, you can re-execute the setting command. You can also manually repair the chrony configuration of the node and execute the cleanup command to delete the chrony daemonset resources and the chrony label on the node. Deleting the chrony daemonset will delete the chrony daemonset containers on all nodes. In addition, this command also serves as a supplement to the cleanup of chrony daemonset resources after the chrony configuration task is successful.
6. A system for clock source management in a kubernetes cluster, characterized in that: include: Configuration module, used to configure the time service component chrony in each node of the kubernetes cluster. The time service component corresponds to a pre-configured time service configuration, and is used to set two different chrony configuration files in a cluster, namely the master node configuration and the node node configuration. The path of the chrony configuration file is / etc / chrony.conf; The calling module is used to call the NTP client management command tool. The NTP client tool enhances the cluster management function by extending kubectl. Administrators can directly view the current clock source, check the external clock source, set the clock source, and perform other management operations through the kubectl command. According to the requirements of the kubectl extension plug-in, the executable file name of the ntp client tool plug-in is named "kubectl-ntp" and copied to a directory in $PATH. The execution module is used to execute the NTP setting subcommand, allowing 0 to 3 external clock sources to be set. The external clock sources need to pass the NTP verification, and the external clock sources with too large time deviation and non-cluster nodes are rejected; and when receiving the setting instruction, the command line tool program generates a chrony configuration template according to the configured external clock source information and saves it in the configmap; the configuration template includes the master node configuration template and the node node configuration template; and adds a label of the chrony running flag to each cluster node, and then creates a chrony daemonset to execute the chrony configuration update on each node. If the chrony daemonset already exists, the chrony daemonset is updated, and the chrony daemonset contains the chrony management program.
7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the method for managing clock sources in a Kubernetes cluster according to any one of claims 1 to 5 is implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, a method for managing clock sources in a Kubernetes cluster according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Cluster time synchronization method, device, system and apparatus and readable storage medium
CN112181049A
Method and device for managing Kubernetes cluster
CN112395039A