Search

CN-115827216-B - Cluster service high availability method, device, computer equipment and storage medium

CN115827216BCN 115827216 BCN115827216 BCN 115827216BCN-115827216-B

Abstract

The application provides a cluster service high availability method, a cluster service high availability device, computer equipment and a storage medium. The method comprises the steps of judging whether the target cluster service is executed by more than two pod, generating more than two pod to execute the target cluster service simultaneously if the target cluster service is not executed by more than two pod, judging whether the corresponding eliminating means exists in the compatible risk if the target cluster service is not executed by more than two pod, adopting the corresponding eliminating means in the compatible risk if the corresponding eliminating means exists in the compatible risk, generating more than two pod to execute the target cluster service simultaneously, and generating more than two pod if the corresponding eliminating means does not exist in the compatible risk, and selecting one pod from the two pods to execute the target cluster service by utilizing a selected mode. The method effectively realizes high availability of cluster services in the Kubernetes, improves the number of copies of a single service, ensures the stability of the clusters, and reduces the time of service interruption.

Inventors

  • Zhou Runpo

Assignees

  • 广州文远知行科技有限公司

Dates

Publication Date
20260508
Application Date
20221024

Claims (11)

  1. 1. A method for high availability of cluster services, comprising: Judging whether compatibility risks exist when more than two pod execute target cluster service; if the compatibility risk does not exist, generating more than two pod to execute the target cluster service at the same time; If the compatibility risk exists, judging whether the compatibility risk exists a corresponding elimination means or not; If the corresponding elimination means exist in the compatible risks, adopting the elimination means corresponding to the compatible risks, and generating more than two pod to execute the target cluster service simultaneously; if the compatible risk does not have the corresponding elimination means, generating more than two pod, and selecting one pod from the two pods to execute the target cluster service by using a selected mode.
  2. 2. The method of claim 1, comprising exposing the target cluster service to an external interface to receive a service access request before the selecting one pod from among the plurality of pods to execute the target cluster service using the selected dominant mode; the selecting one pod from the selected modes to execute the target cluster service comprises the following steps: selecting one pod from the generated pods as a master pod by using the master selection mode, and the rest pods as slave pods; And draining the service access request to the main pod.
  3. 3. The method of claim 2, wherein any one pod, after being selected as the master pod, sets its own identifier to a first identifier and, after being selected as the slave pod, sets its own identifier to a second identifier; the streaming the service access request to the primary pod comprises: The selection identifier of Kubernetes Service is set to the first identifier so that the service access request is assigned to the primary pod.
  4. 4. The method of claim 1, wherein the compatibility risk comprises a first risk, and wherein the determining whether the compatibility risk exists when the target cluster service is performed by more than two pod comprises: determining whether a fixed-point periodic task exists according to the code logic of the target cluster service, wherein the fixed-point periodic task is a task executed at a fixed time point of each execution period; And if the fixed-point periodic task exists, determining that the first risk exists.
  5. 5. The method of claim 4, wherein the eliminating means corresponding to the first risk comprises: And modifying the code logic of the target cluster service to modify the fixed-point periodic task into a random periodic task, wherein the random periodic task is a task executed at a random time point of each execution period.
  6. 6. The method of claim 1, wherein the compatibility risk comprises a second risk, and wherein the determining whether the compatibility risk exists when the target cluster service is performed by more than two pod comprises: determining whether a statement for reading the local cache exists according to the code logic of the target cluster service; And if the statement for reading the local cache exists, determining that the second risk exists.
  7. 7. The method of claim 6, wherein the means for eliminating the second risk correspondence comprises: And modifying the code logic of the target cluster service to modify the statement read from the local cache into a statement read from the remote shared cache.
  8. 8. The method of claim 1, wherein the generating more than two pod simultaneously performs the target cluster service comprises: and performing redundancy configuration on the ReplicaSet to generate more than two pod and simultaneously executing the target cluster service.
  9. 9. A cluster service high availability apparatus, comprising: the risk judging module is used for judging whether a compatible risk exists when more than two pod execute target cluster service; the first execution module is used for generating more than two pod to execute the target cluster service simultaneously when the compatibility risk does not exist; The means judging module is used for judging whether a corresponding eliminating means exists in the compatible risk or not when the compatible risk exists; the second execution module is used for taking the elimination means corresponding to the compatibility risk when the elimination means corresponding to the compatibility risk exists, generating more than two pod and executing the target cluster service simultaneously; And the third execution module is used for generating more than two pod when the corresponding elimination means does not exist in the compatibility risk, and selecting one pod from the two pod to execute the target cluster service by utilizing a selected main mode.
  10. 10. A computer device comprising one or more processors and a memory having stored therein computer readable instructions which, when executed by the one or more processors, perform the steps of the cluster service high availability method of any of claims 1 to 8.
  11. 11. A storage medium having stored therein computer readable instructions which, when executed by one or more processors, cause the one or more processors to perform the steps of the cluster service high availability method of any of claims 1 to 8.

Description

Cluster service high availability method, device, computer equipment and storage medium Technical Field The present application relates to the field of container technologies, and in particular, to a method, an apparatus, a computer device, and a storage medium for cluster service high availability. Background With the rapid development of the open source platform Kubernetes (K8 s), many service providers began to deploy services into Kubernetes clusters to provide services externally. However, the clusters are at risk of service interruption due to the possibility of software and hardware failures and human misoperation. The cluster service in the conventional technology does not have the characteristic of high availability, so that the service cannot be provided for the user during the fault period, and the user relying on the cluster service is negatively influenced. Disclosure of Invention The present application aims to solve at least one of the above technical drawbacks, especially the technical drawbacks of the prior art, such as the poor availability of cluster services. In a first aspect, the application provides a high availability method of cluster service, which comprises the steps of judging whether more than two pod execute target cluster service, if not, generating more than two pod execute target cluster service at the same time, if so, judging whether a corresponding elimination means exists, if so, adopting the corresponding elimination means of the compatible risk, generating more than two pod execute target cluster service at the same time, and if not, generating more than two pod, and selecting one pod from the two to execute target cluster service by using a main selection mode. In one embodiment, before the target cluster service is executed by selecting one pod from the generated pods by using the master mode, the method comprises exposing an interface to the outside by the target cluster service to receive a service access request, selecting one pod from the generated pods by using the master mode to execute the target cluster service, selecting one pod from the generated pods by using the master mode as a master pod, and the rest pods as slave pods, and streaming the service access request to the master pod. In one embodiment, any of the pod sets its own identifier to a first identifier after being selected as a master pod and to a second identifier after being selected as a slave pod, and the draining of service access requests to the master pod includes setting Kubernetes Service the selected identifier to the first identifier to cause the service access request to be assigned to the master pod. In one embodiment, the compatibility risk comprises a first risk, and judging whether the compatibility risk exists when the target cluster service is executed by more than two pod comprises determining whether a fixed-point periodic task exists according to code logic of the target cluster service, wherein the fixed-point periodic task is executed at a fixed time point of each execution period, and determining that the first risk exists if the fixed-point periodic task exists. In one embodiment, the first risk corresponding elimination means includes modifying code logic of the target cluster service to modify the fixed-point periodic task into a random periodic task, wherein the random periodic task is a task executed at a random time point of each execution period. In one embodiment, the compatibility risk comprises a second risk, and judging whether the compatibility risk exists when the target cluster service is executed by more than two pod comprises determining whether a statement for reading the local cache exists according to code logic of the target cluster service, and if the statement for reading the local cache exists, determining that the second risk exists. In one embodiment, the second risk corresponding elimination means includes modifying code logic of the target cluster service to modify the statement reading the local cache to a statement reading the remote shared cache. In one embodiment, generating more than two pod to simultaneously execute the target cluster service includes configuring redundancy set to generate more than two pod to simultaneously execute the target cluster service. The embodiment of the application provides a cluster service high-availability device, which comprises a risk judging module, a first executing module, a means judging module, a second executing module and a third executing module, wherein the risk judging module is used for judging whether more than two pos are compatible in executing target cluster service, the first executing module is used for generating more than two pos and executing target cluster service simultaneously if the more than two pos are not compatible in executing the target cluster service, the means judging module is used for judging whether the compatible risks are corresponding eliminating means if the compatible