Container state detection method, device, equipment and medium
Through the timed tasks that periodically initiate requests to the container and the coordination service component connection, the problem that the Kubernetes platform survival probe mechanism cannot provide container error category information in real time is solved, real-time detection and operation and maintenance of container status is realized, and operation and maintenance processing is improved, and operation and operation convenience is improved. and real-time.
Patent Information
- Application Number
- CN202411206660.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-29
- Publication Date
- 2024-12-06
AI Technical Summary
The survival probe mechanism of the Kubernetes platform cannot provide container specific error categories information in real time, making it difficult for operation and maintenance personnel to handle targeted processing, and is less real-time and operational.
By obtaining the coordination service component address and reporting configuration files, performing timed tasks that periodically initiate requests to the container, storing and updating dictionary instances, connecting to the coordination service component, obtaining container status notifications in real time, and real-time operation and maintenance processing.
It improves the real-time and operational convenience of container status detection, reduces the workload of operation and maintenance personnel, and can handle it in a timely manner according to the container status.
Smart Images

Figure CN119088643A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of container management technology, and in particular to a container status detection method, device, equipment and medium. Background Art
[0002] The Kubernetes platform monitors the container status through the liveness probe mechanism. The liveness probe mechanism is implemented based on HTTP interface inspection. The kubelet component sends an HTTP GET request to the service running in the container according to the specified path to perform detection. If the service running in the container under the path returns a success code, it means that the container status is normal. If the service running in the container under the path returns an error code, it means that the container status is abnormal. The kubelet component will kill the abnormal container and restart the container. However, this return code is not exposed to the outside world. The operation and maintenance personnel cannot know the specific return code of the container, and cannot judge the specific error category of the container based on the specific return code, which makes it difficult to handle exceptions based on the specific error category of the container. In addition, the container status monitored by the liveness probe can only be known by viewing the container events or container logs through the command line tool of the kubectl component, which leads to low real-time performance and cumbersome operations. Summary of the invention
[0003] The main purpose of the embodiments of the present application is to provide a container status detection method, device, equipment and medium, which can facilitate the acquisition of container status information with high real-time performance.
[0004] To achieve the above-mentioned purpose, a first aspect of an embodiment of the present application proposes a container status detection method, comprising:
[0005] Get the address of the coordination service component and the reporting configuration file;
[0006] executing a scheduled task of periodically initiating a request to a container according to the configuration information of the reported configuration file, storing an instance of the scheduled task in a first dictionary to obtain a first instance, and updating the first dictionary when the current first instance is different from the previous first instance;
[0007] connecting to the coordination service component according to the address of the coordination service component;
[0008] The first instance in the first dictionary is stored in the second dictionary to obtain a second instance. When the current second instance is different from the previous second instance, the second dictionary is updated according to the fixed parameters of the reported configuration file, and the updated second dictionary is uploaded to the coordination service component.
[0009] In some embodiments, obtaining the address of the coordination service component includes:
[0010] Get the environment name based on the environment variables of the container cluster;
[0011] Obtain a local configuration file of the configuration center of the container cluster, and obtain the address of the configuration center and configuration information of the configuration center from the local configuration file according to the environment name;
[0012] Connecting to the configuration center according to the address of the configuration center and the configuration information of the configuration center;
[0013] The address of the coordination service component is obtained from the configuration center.
[0014] In some embodiments, the obtaining and reporting configuration file includes:
[0015] Get the name of the reported configuration file based on the environment variables of the container cluster;
[0016] The reporting configuration file is obtained from the configuration center according to the name of the reporting configuration file.
[0017] In some embodiments, storing the instance of the scheduled task in a first dictionary to obtain a first instance includes:
[0018] Using the request name of the configuration information of the reporting configuration file as a key, the instance of the scheduled task is stored in a first dictionary to obtain a first instance.
[0019] In some embodiments, updating the first dictionary when the current first instance is different from the previous first instance includes:
[0020] When the request name associated with the current first instance is different from the request name associated with the previous first instance, stop the scheduled task corresponding to the request name associated with the previous first instance, remove the previous first instance and the request name associated with the previous first instance in the first dictionary, and update them to the current first instance and the request name of the current first instance.
[0021] In some embodiments, storing the first instance in the first dictionary into the second dictionary to obtain the second instance includes:
[0022] Using the request name of the first instance in the first dictionary as a key, the first instance in the first dictionary is stored in a second dictionary to obtain a second instance.
[0023] In some embodiments, when the current second instance is different from the previous second instance, updating the second dictionary according to the fixed parameters of the reported configuration file includes:
[0024] When the request name associated with the current second instance is different from the request name associated with the previous second instance, remove the previous second instance and the request name associated with the previous second instance in the second dictionary, and update the second dictionary according to the fixed parameters of the reporting configuration file.
[0025] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application provides a container state detection device, comprising:
[0026] A pre-preparation module is used to obtain the address of the coordination service component and obtain the reporting configuration file;
[0027] A scheduled task management module, configured to execute a scheduled task of periodically initiating a request to a container according to the configuration information of the reported configuration file, store an instance of the scheduled task in a first dictionary to obtain a first instance, and update the first dictionary when the current first instance is different from the previous first instance;
[0028] A connection module, used for connecting to the coordination service component according to the address of the coordination service component;
[0029] A reporting module is used to store the first instance in the first dictionary into a second dictionary to obtain a second instance. When the current second instance is different from the previous second instance, the second dictionary is updated according to the fixed parameters of the reporting configuration file, and the updated second dictionary is uploaded to the coordination service component.
[0030] To achieve the above-mentioned purpose, the third aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, it implements the container status detection method as described in the first aspect of the embodiment of the present application.
[0031] To achieve the above-mentioned purpose, the fourth aspect of the embodiments of the present application proposes a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the container status detection method as described in the first aspect of the embodiments of the present application.
[0032] The container status detection method, apparatus, device and medium proposed in the present application perform a timed task of periodically initiating a request to the container according to the configuration information of a reported configuration file, store the instance of the timed task in a first dictionary to obtain a first instance, and update the first dictionary when the current first instance is different from the previous first instance; connect the coordination service component according to the address of the coordination service component; store the first instance in the first dictionary in a second dictionary to obtain a second instance, and when the current second instance is different from the previous second instance, update the second dictionary according to the fixed parameters of the reported configuration file, and upload the updated second dictionary to the coordination service component; so that the deployment container status notification can be obtained in real time by subscribing to the coordination service component, which is conducive to real-time operation and maintenance processing according to the container status, and has the advantages of high real-time performance and convenient operation. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 is a step diagram of a container status detection method provided in an embodiment of the present application;
[0034] Figure 2 It is a sub-step diagram of obtaining the address of the coordination service component provided by an embodiment of the present application;
[0035] Figure 3 It is a sub-step diagram of obtaining a reporting configuration file provided in an embodiment of the present application;
[0036] Figure 4 It is a sub-step diagram of storing an instance of a scheduled task in a first dictionary to obtain a first instance provided by an embodiment of the present application;
[0037] Figure 5 is a sub-step diagram of updating the first dictionary provided by an embodiment of the present application;
[0038] Figure 6 It is a sub-step diagram of storing a first instance in a first dictionary into a second dictionary to obtain a second instance provided by an embodiment of the present application;
[0039] Figure 7 is a sub-step diagram of updating the second dictionary provided by an embodiment of the present application;
[0040] Figure 8 It is a structural diagram of the Kubernetes platform provided in an embodiment of the present application;
[0041] Fig. 9 is a structural diagram of a container status detection device provided in an embodiment of the present application;
[0042] Fig.10 It is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0043] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0044] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0045] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0046] The Kubernetes platform monitors the container status through the liveness probe mechanism. The liveness probe mechanism is implemented based on HTTP interface inspection. The kubelet component sends an HTTP GET request to the service running in the container according to the specified path to perform detection. If the service running in the container under the path returns a success code, it means that the container status is normal. If the service running in the container under the path returns an error code, it means that the container status is abnormal. The kubelet component will kill the abnormal container and restart the container. However, this return code is not exposed to the outside world. The operation and maintenance personnel cannot know the specific return code of the container, and cannot judge the specific error category of the container based on the specific return code, which makes it difficult to handle exceptions based on the specific error category of the container. In addition, the container status monitored by the liveness probe can only be known by viewing the container events or container logs through the command line tool of the kubectl component, which leads to low real-time performance and cumbersome operations.
[0047] In order to solve the above problems, the embodiments of the present application provide a container status detection method, device, equipment and medium, which have the advantages of high real-time performance and easy operation.
[0048] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0049] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0050] The container status detection method, device, equipment and medium provided in the embodiments of the present application relate to the field of artificial intelligence technology. The container status detection method provided in the embodiments of the present application can be applied to a terminal, can be applied to a server side, or can be software running in a terminal or a server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the container status detection method, etc., but is not limited to the above forms.
[0051] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0052] It should be noted that in each specific implementation of the present application, when it comes to the need to perform relevant processing based on data related to user identity or characteristics such as user information, user behavior data, user historical data, and user location information, the user's permission or consent will be obtained first, and the collection, use, and processing of these data will comply with relevant regulations. In addition, when the embodiment of the present application needs to obtain the user's sensitive personal information, the user's separate permission or consent will be obtained through a pop-up window or jump to a confirmation page. After clearly obtaining the user's separate permission or consent, the necessary user-related data for the normal operation of the embodiment of the present application will be obtained.
[0053] The container status detection method, device, equipment and medium provided in the embodiments of the present application are specifically described through the following embodiments. First, the container status detection method in the embodiments of the present application is described.
[0054] An embodiment of the present application provides a container status detection method.
[0055] Reference Figure 8 , the container status detection method is mainly used in the Kubernetes platform (abbreviated as K8S). The Kubernetes platform is an open source container orchestration platform for automating the deployment, expansion and management of containerized applications. The Kubernetes platform provides a framework for running distributed systems, supporting automated deployment, large-scale scalability, and application containerization management, making the deployment, expansion and management of containerized applications easier and more efficient. In Kubernetes, you can create multiple containers, each of which runs an application instance, and then use the built-in load balancing strategy to manage, discover and access this group of application instances.
[0056] A Pod is a collection of containers and is the basic deployment unit in a Kubernetes cluster. It can contain one or more containers. Containers within a Pod share network and storage resources and are usually deployed, scaled, and deleted together.
[0057] The Master Node is the control center of the Kubernetes cluster, responsible for maintaining the cluster state and performing various tasks, such as scheduling Pods, managing service discovery and expansion, etc. Several key control plane components run on the Master Node, including API Server, Scheduler, Controller Manager, etcd, etc.
[0058] Worker nodes are working machines in the Kubernetes cluster that run containerized applications. Kubelet and Container Runtime (such as Docker) run on each node. Sidecar is an auxiliary container that is deployed in a Kubernetes pod with the business container. Config center is a configuration center, specifically a configuration file registration center. Zookeeper is a coordination service component that provides distributed coordination services and implements data subscription.
[0059] Specifically, ZooKeeper is a component that provides consistency services for distributed applications. Its functions include configuration maintenance, domain name services, distributed synchronization, group services, etc. ZooKeeper provides interfaces for distributed exclusive locks, elections, and queues. Its goal is to encapsulate complex and error-prone key services and provide users with simple and easy-to-use interfaces and efficient, stable systems.
[0060] In a Kubernetes cluster, app is a business container in a Pod.
[0061] Reference Figure 1 , a container status detection method includes the following steps:
[0062] Step S100, obtaining the address of the coordination service component and obtaining the reporting configuration file;
[0063] Step S200, executing a scheduled task of periodically initiating a request to a container according to the configuration information of the reported configuration file, storing an instance of the scheduled task in a first dictionary to obtain a first instance, and updating the first dictionary when the current first instance is different from the previous first instance;
[0064] Step S300, connecting to the coordination service component according to the address of the coordination service component;
[0065] Step S400, storing the first instance in the first dictionary into the second dictionary to obtain the second instance, when the current second instance is different from the previous second instance, updating the second dictionary according to the fixed parameters of the reported configuration file, and uploading the updated second dictionary to the coordination service component.
[0066] The following is a detailed description of steps S100 to S400 in the container status detection method.
[0067] Reference Figure 2 In step S100 of some embodiments, obtaining the address of the coordination service component includes the following steps:
[0068] Step S111, obtaining an environment name according to the environment variables of the container cluster;
[0069] Step S112, obtaining a local configuration file of the configuration center of the container cluster, and obtaining the address of the configuration center and configuration information of the configuration center from the local configuration file according to the environment name;
[0070] Step S113, connecting to the configuration center according to the address of the configuration center and the configuration information of the configuration center;
[0071] Step S114, obtaining the address of the coordination service component from the configuration center.
[0072] In this embodiment, in a K8S cluster, environment variables are usually set through ConfigMap or Secrets and referenced through environment variable configuration in the Pod's spec. For example, when configuring through ConfigMap, config-map-name is the name of the ConfigMap resource, and config-file-name is the key for storing the configuration file name in ConfigMap. The environment name ENV_NAME of the environment variable can be defined in the Pod's configuration file, and its value is set through command line parameters or configuration management tools during deployment. The environment name is used to distinguish different deployment environments, such as development, testing, production, etc.
[0073] Read the local configuration file a of Apollo, the configuration center of the container cluster, in a fixed path locally. The local configuration file a can be mounted to the specified path of the Pod as ConfigMap or Secret.
[0074] Extract the address and configuration information of the configuration center Apollo from the local configuration file a according to the environment name. This information includes the URL, port number, access key, etc. of the configuration center Apollo.
[0075] Use the address and configuration information of the configuration center Apollo extracted from the local configuration file a, initialize the connection with the configuration center Apollo according to the address of the configuration center Apollo, and then configure it according to the configuration information of the configuration center Apollo to achieve the connection. This usually involves creating an Apollo client instance, configuring authentication information, and establishing a network connection. In the K8S cluster, service discovery also needs to be processed to ensure that the connection is to the Apollo service inside the cluster.
[0076] After connecting to the configuration center Apollo, you can request the configuration information of a specific environment, including the address of the coordination service component, that is, the Zookeeper address. This can be achieved through the API provided by Apollo. The application needs to query the address of the coordination service component based on the current environment name. Alternatively, use the Kubernetes Service name and port to determine the access address of the Zookeeper service.
[0077] Reference Figure 3 , obtain the reporting configuration file, including the following steps:
[0078] Step S121, obtaining the name of the reporting configuration file according to the environment variables of the container cluster;
[0079] Step S122: Obtain the reporting configuration file from the configuration center according to the name of the reporting configuration file.
[0080] In this embodiment, in a K8S cluster, environment variables are usually set through ConfigMap or Secrets, and referenced through environment variable configuration in the Pod spec. The name of the reported configuration file is obtained according to the environment variables of the container cluster.
[0081] Use the address and configuration information of the configuration center Apollo extracted from the local configuration file a, initialize the connection with the configuration center Apollo according to the address of the configuration center Apollo, and then configure according to the configuration information of the configuration center Apollo to achieve the connection. This usually involves creating an Apollo client instance, configuring authentication information, and establishing a network connection.
[0082] After connecting to the configuration center Apollo, query and load the configuration information in the configuration center Apollo according to the name of the reported configuration file, and find the reported configuration file b. This usually involves creating an Apollo client instance, setting the corresponding environment and cluster name, and then calling the client method to obtain the content of the reported configuration file b. The content of the reported configuration file b stores the custom key-value pairs that need to be reported, the configuration information of the http request, etc.
[0083] It should be noted that the local configuration file a usually contains the basic configuration information required by the application or service in a specific environment, such as database connection string, service address, environment-specific parameters, etc.; it is used to initialize application settings to ensure that the application can load the correct configuration according to different environments (such as development, testing, and production); it contains the connection information of the configuration center (such as Apollo), so that the application can dynamically obtain or update the configuration from the remote configuration center.
[0084] The reporting configuration file b contains custom configuration information for monitoring, reporting, logging, etc. This information includes the reporting frequency, target server address, and a list of indicators or events that need to be collected and reported. It is used to define how the application interacts with its monitoring system, logging system, or other external systems. For example, configuration file b defines indicators that need to be collected and sent to the monitoring service at regular intervals. The content in the reporting configuration file b needs to be updated according to business needs to adjust the reported information or logic.
[0085] In step S200 of some embodiments, a scheduled task of periodically initiating a request to a container is executed according to configuration information of a reported configuration file, an instance of the scheduled task is stored in a first dictionary to obtain a first instance, and the first dictionary is updated when the current first instance is different from the previous first instance.
[0086] Exemplarily, the content of the reported configuration file b stores the configuration information of the http request, interprets the configuration information, and obtains the URL, method, header information, etc. of the http request in the configuration information. According to the configuration information of the http request in the reported configuration file b, start the scheduled task, and periodically initiate http requests to the URL in the container, for example, use a mechanism such as Scheduled ExecutorService to periodically initiate HTTP requests to the specified URL.
[0087] Reference Figure 4 , storing the instance of the scheduled task in the first dictionary to obtain the first instance, including the following steps: Step S210, using the request name of the configuration information of the reported configuration file as a key, storing the instance of the scheduled task in the first dictionary to obtain the first instance.
[0088] Exemplarily, a key-value pair is constructed with the request name name of the configuration information of the reported configuration file as the key key and the instance of the scheduled task as the value value, and the instance of the scheduled task is stored in the first dictionary dict1; this makes it convenient to find the instance of the scheduled task and also to monitor whether the scheduled task has changed.
[0089] Traverse the configuration information of the reporting configuration file b, start the scheduled task according to the configuration information of the reporting configuration file, periodically initiate http requests to the URL in the container, use the request name of the configuration information of the reporting configuration file as the key, and the instance of the scheduled task as the value to build a key-value pair, and store the instance of the scheduled task in the first dictionary dict1. Each time the configuration information of a reporting configuration file b is traversed, the scheduled task is started once, an http request is initiated to the URL in the container, and the instance of the scheduled task is stored in the first dictionary dict1, and this cycle is repeated.
[0090] Reference Figure 5, updating the first dictionary when the current first instance is different from the previous first instance, including the following steps: step S220, when the request name associated with the current first instance is different from the request name associated with the previous first instance, stopping the scheduled task corresponding to the request name associated with the previous first instance, removing the previous first instance and the request name associated with the previous first instance in the first dictionary, and updating them to the current first instance and the request name of the current first instance.
[0091] Exemplarily, during the loop, the changes in the reporting configuration file b are monitored. When it is detected that the request name name(k) associated with the current first instance is different from the request name name(k-1) associated with the previous first instance, that is, the name value in the first dictionary dict1 key is different from the previous time, it means that the reporting configuration file b has been updated. Stop the scheduled task task(k-1) corresponding to the request name name(k-1) associated with the previous first instance, remove the key-value pair of the previous first instance value(k-1) and the request name key(k-1) associated with the previous first instance in the first dictionary dict1, and update it to the current first instance and the request name name(k) of the current first instance.
[0092] In step S300 of some embodiments, the coordination service component is connected according to the address of the coordination service component.
[0093] Exemplarily, after connecting to the configuration center Apollo and reading the address of the coordination service component Zookeeper from the configuration center Apollo, configure the Zookeeper client to ensure that the client configuration is correct, including the correct server list and necessary authentication information. In the Kubernetes environment, connection information can be managed through ConfigMap or Secrets, and the connection information includes the address and port of the Zookeeper service, authentication information, etc. Deploy the Zookeeper client and deploy the Zookeeper client in the Kubernetes cluster. This can be achieved by creating a Pod that uses the Zookeeper client image and mounts the ConfigMap or Secrets containing the configuration information. Use Zookeeper client tools, such as zkCli.sh, to connect to the Zookeeper service. Inside the Kubernetes cluster, the Zookeeper service can be accessed by the Service name, for example, using the command zkCli.sh-server zookeeper-client:2181.
[0094] In step S400 of some embodiments, the first instance in the first dictionary is stored in the second dictionary to obtain the second instance. When the current second instance is different from the previous second instance, the second dictionary is updated according to the fixed parameters of the reported configuration file, and the updated second dictionary is uploaded to the coordination service component.
[0095] Reference Figure 6 , wherein storing the first instance in the first dictionary into the second dictionary to obtain the second instance includes the following steps: Step S410, using the request name of the first instance in the first dictionary as a key, storing the first instance in the first dictionary into the second dictionary to obtain the second instance.
[0096] Exemplarily, a key-value pair is constructed with the request name name of the first instance in the first dictionary as the key key and the instance of the scheduled task as the value value, and the instance of the scheduled task is stored in the second dictionary dict2 to obtain the second instance.
[0097] Traverse the http request information in each configuration information of the first dictionary, including name, URL, status, etc., use the request name of the first instance in the first dictionary as the key, and the instance of the scheduled task as the value, to build a key-value pair, and store the instance of the scheduled task in the second dictionary dict2. Each time a http request information of the first dictionary is traversed, the instance of the scheduled task is stored in the second dictionary dict2, and the cycle continues.
[0098] Reference Figure 7 , when the current second instance is different from the previous second instance, updating the second dictionary according to the fixed parameters of the reported configuration file, including the following steps: step S420, when the request name associated with the current second instance is different from the request name associated with the previous second instance, remove the previous second instance and the request name associated with the previous second instance in the second dictionary, and update the second dictionary according to the fixed parameters of the reported configuration file.
[0099] Exemplarily, during the loop, the changes of the reporting configuration file b are monitored. When it is detected that the request name name1(k) associated with the current second instance is different from the request name name1(k-1) associated with the previous second instance, that is, the name value in the second dictionary dict2 key is different from the previous time, it means that the reporting configuration file b has been updated. Remove the key-value pair of the previous second instance value1(k-1) and the request name key1(k-1) associated with the previous second instance in the second dictionary dict2, and update the second dictionary according to the fixed parameters of the reporting configuration file.
[0100] It should be noted that fixed parameters are a set of predefined parameters that do not change frequently. These parameters are critical to the operation of the container and are consistent in multiple environments or services. Fixed parameters include service name, version information, environment identifier, performance indicator list, security settings, resource limits, dependent service list, reporting frequency, alarm threshold, and custom parameters. The service name is used to identify the unique name of the service for logging, monitoring, and troubleshooting; the version information is the current version number of the application or service, which helps to track and trace back problems; the environment identifier is used to identify the environment in which the current application runs; the performance indicator list includes CPU usage, memory usage, response time, etc.; security settings include encryption keys, security protocol versions, access control lists, etc.; resource limits include the upper limit of resources that the container can use, such as memory limits, thread pool size, etc.; the dependent service list is a list of other services that the container depends on, including service names and access addresses; the reporting frequency is the frequency or time interval for reporting data to the monitoring system; the alarm threshold is the condition and threshold setting for triggering an alarm; and custom parameters are other fixed parameters defined according to specific business needs.
[0101] Upload the updated second dictionary to the coordination service component, and the reported information includes the specific HTTP return code. Regularly report the container health status, request status, specified value and key-value pair to the coordination service component Zookeeper.
[0102] After the report is completed, close the scheduled task and delete the relevant nodes corresponding to the coordination service component Zookeeper.
[0103] It should be noted that the use of the first dictionary dict1 and the second dictionary dict2 to store scheduled task instances and other related information is mainly to achieve the following purposes. Separation of concerns: The first dictionary is used to store information directly related to scheduled tasks, such as task instances, request names, URLs, and the status of scheduled tasks. This helps manage and track the execution of scheduled tasks. Configuration change detection: If the name values in the first and second dictionaries are found to be different from the previous ones in the next cycle, this indicates that the reporting configuration file has been updated, and the old scheduled task needs to be stopped and a new scheduled task needs to be started accordingly. Data aggregation and reporting preparation: The second dictionary dict2 is used to summarize the information reported to the coordination service component Zookeeper, including the real-time data obtained from the first dictionary dict1 and the fixed parameter list in the reporting configuration file b; this helps to build the reported data structure and perform final verification and update before reporting. Status and metadata management: The second dictionary is also used to store the status and other metadata of each task. Real-time synchronization and update: the first dictionary dict1 can be updated in real time according to the changes in the reported configuration file b, and the second dictionary dict2 can be updated in real time according to the changes in the first dictionary dict1, ensuring that the information reported to the coordination service component Zookeeper is the latest. Avoid data overwriting: if you modify the same dictionary directly before reporting, some important data may be accidentally overwritten during the update process; using two dictionaries can avoid this situation, because the second dictionary dict2 can be updated after the first dictionary dict1 is updated. Improve efficiency: the first dictionary dict1 can quickly respond to configuration changes and update scheduled tasks, while the second dictionary dict2 can focus on building the reported data structure. The two can work in parallel to improve the efficiency of the overall process.
[0104] Through the above container status detection method, the configuration center and local configuration files are used to achieve high customization and portability. You only need to modify the configuration file to run in different k8s clusters, and it is convenient to manage the monitored service containers. The URL request information reported to the coordination service component zookeeper contains a specific HTTP return code, which can have more customized operation and maintenance of the status of the deployed container. By subscribing to the coordination service component zookeeper, you can get the status notification of the deployed container in real time. There is no need to view the container status through the kubectl command line tool, which reduces the workload of the operation and maintenance personnel. In addition, other services or monitoring tools can also query the coordination service component zookeeper to view the container status information to determine the available containers, so as to achieve customization and meet the specific needs of developers.
[0105] The embodiments of the present application also provide a container status detection device.
[0106] Reference Fig. 9 The container status detection device includes: a pre-preparation module 801, a scheduled task management module 802, a connection module 803 and a reporting module 804.
[0107] Among them, the pre-preparation module 801 is used to obtain the address of the coordination service component and obtain the reporting configuration file; the scheduled task management module 802 is used to execute the scheduled task of periodically initiating requests to the container according to the configuration information of the reporting configuration file, store the instance of the scheduled task in the first dictionary to obtain the first instance, and update the first dictionary when the current first instance is different from the previous first instance; the connection module 803 is used to connect the coordination service component according to the address of the coordination service component; the reporting module 804 is used to store the first instance in the first dictionary to the second dictionary to obtain the second instance, and when the current second instance is different from the previous second instance, update the second dictionary according to the fixed parameters of the reporting configuration file, and upload the updated second dictionary to the coordination service component.
[0108] The pre-preparation module 801 obtains the name of the reporting configuration file according to the environment variables of the container cluster; and obtains the reporting configuration file from the configuration center according to the name of the reporting configuration file.
[0109] In this embodiment, in a K8S cluster, environment variables are usually set through ConfigMap or Secrets, and referenced through environment variable configuration in the Pod spec. The name of the reported configuration file is obtained according to the environment variables of the container cluster.
[0110] Use the address and configuration information of the configuration center Apollo extracted from the local configuration file a, initialize the connection with the configuration center Apollo according to the address of the configuration center Apollo, and then configure according to the configuration information of the configuration center Apollo to achieve the connection. This usually involves creating an Apollo client instance, configuring authentication information, and establishing a network connection.
[0111] After connecting to the configuration center Apollo, query and load the configuration information in the configuration center Apollo according to the name of the reported configuration file, and find the reported configuration file b. This usually involves creating an Apollo client instance, setting the corresponding environment and cluster name, and then calling the client method to obtain the content of the reported configuration file b. The content of the reported configuration file b stores the custom key-value pairs that need to be reported, the configuration information of the http request, etc.
[0112] It should be noted that the local configuration file a usually contains the basic configuration information required by the application or service in a specific environment, such as database connection string, service address, environment-specific parameters, etc.; it is used to initialize application settings to ensure that the application can load the correct configuration according to different environments (such as development, testing, and production); it contains the connection information of the configuration center (such as Apollo), so that the application can dynamically obtain or update the configuration from the remote configuration center.
[0113] The reporting configuration file b contains custom configuration information for monitoring, reporting, logging, etc. This information includes the reporting frequency, target server address, and a list of indicators or events that need to be collected and reported. It is used to define how the application interacts with its monitoring system, logging system, or other external systems. For example, configuration file b defines indicators that need to be collected and sent to the monitoring service at regular intervals. The content in the reporting configuration file b needs to be updated according to business needs to adjust the reported information or logic.
[0114] The scheduled task management module 802 executes a scheduled task that periodically initiates a request to the container according to the configuration information of the reported configuration file, stores the instance of the scheduled task in the first dictionary to obtain a first instance, and updates the first dictionary when the current first instance is different from the previous first instance.
[0115] Exemplarily, the content of the reported configuration file b stores the configuration information of the http request, interprets the configuration information, and obtains the URL, method, header information, etc. of the http request in the configuration information. According to the configuration information of the http request in the reported configuration file b, start the scheduled task, and periodically initiate http requests to the URL in the container, for example, use a mechanism such as Scheduled ExecutorService to periodically initiate HTTP requests to the specified URL.
[0116] The instance of the scheduled task is stored in the first dictionary to obtain the first instance, including the following steps: using the request name of the configuration information of the reported configuration file as a key, storing the instance of the scheduled task in the first dictionary to obtain the first instance
[0117] Exemplarily, a key-value pair is constructed with the request name name of the configuration information of the reported configuration file as the key key and the instance of the scheduled task as the value value, and the instance of the scheduled task is stored in the first dictionary dict1; this makes it convenient to find the instance of the scheduled task and also to monitor whether the scheduled task has changed.
[0118] Traverse the configuration information of the reporting configuration file b, start the scheduled task according to the configuration information of the reporting configuration file, periodically initiate http requests to the URL in the container, use the request name of the configuration information of the reporting configuration file as the key, and the instance of the scheduled task as the value to build a key-value pair, and store the instance of the scheduled task in the first dictionary dict1. Each time the configuration information of a reporting configuration file b is traversed, the scheduled task is started once, an http request is initiated to the URL in the container, and the instance of the scheduled task is stored in the first dictionary dict1, and this cycle is repeated.
[0119] When the current first instance is different from the previous first instance, updating the first dictionary includes the following steps: when the request name associated with the current first instance is different from the request name associated with the previous first instance, stopping the scheduled task corresponding to the request name associated with the previous first instance, removing the previous first instance and the request name associated with the previous first instance in the first dictionary, and updating to the current first instance and the request name of the current first instance.
[0120] Exemplarily, during the loop, the changes in the reporting configuration file b are monitored. When it is detected that the request name name(k) associated with the current first instance is different from the request name name(k-1) associated with the previous first instance, that is, the name value in the first dictionary dict1 key is different from the previous time, it means that the reporting configuration file b has been updated. Stop the scheduled task task(k-1) corresponding to the request name name(k-1) associated with the previous first instance, remove the key-value pair of the previous first instance value(k-1) and the request name key(k-1) associated with the previous first instance in the first dictionary dict1, and update it to the current first instance and the request name name(k) of the current first instance.
[0121] The connection module 803 connects to the coordination service component according to the address of the coordination service component.
[0122] Exemplarily, after connecting to the configuration center Apollo and reading the address of the coordination service component Zookeeper from the configuration center Apollo, configure the Zookeeper client to ensure that the client configuration is correct, including the correct server list and necessary authentication information. In the Kubernetes environment, connection information can be managed through ConfigMap or Secrets, and the connection information includes the address and port of the Zookeeper service, authentication information, etc. Deploy the Zookeeper client and deploy the Zookeeper client in the Kubernetes cluster. This can be achieved by creating a Pod that uses the Zookeeper client image and mounts the ConfigMap or Secrets containing the configuration information. Use Zookeeper client tools, such as zkCli.sh, to connect to the Zookeeper service. Inside the Kubernetes cluster, the Zookeeper service can be accessed by the Service name, for example, using the command zkCli.sh-server zookeeper-client:2181.
[0123] The reporting module 804 stores the first instance in the first dictionary into the second dictionary to obtain the second instance. When the current second instance is different from the previous second instance, the second dictionary is updated according to the fixed parameters of the reporting configuration file, and the updated second dictionary is uploaded to the coordination service component.
[0124] The step of storing the first instance in the first dictionary into the second dictionary to obtain the second instance includes the following steps: using the request name of the first instance in the first dictionary as a key, storing the first instance in the first dictionary into the second dictionary to obtain the second instance.
[0125] Exemplarily, a key-value pair is constructed with the request name name of the first instance in the first dictionary as the key key and the instance of the scheduled task as the value value, and the instance of the scheduled task is stored in the second dictionary dict2 to obtain the second instance.
[0126] Traverse the http request information in each configuration information of the first dictionary, including name, URL, status, etc., use the request name of the first instance in the first dictionary as the key, and the instance of the scheduled task as the value, to build a key-value pair, and store the instance of the scheduled task in the second dictionary dict2. Each time a http request information of the first dictionary is traversed, the instance of the scheduled task is stored in the second dictionary dict2, and the cycle continues.
[0127] When the current second instance is different from the previous second instance, updating the second dictionary according to the fixed parameters of the reported configuration file includes the following steps: when the request name associated with the current second instance is different from the request name associated with the previous second instance, removing the previous second instance and the request name associated with the previous second instance in the second dictionary, and updating the second dictionary according to the fixed parameters of the reported configuration file.
[0128] Exemplarily, during the loop, the changes of the reporting configuration file b are monitored. When it is detected that the request name name1(k) associated with the current second instance is different from the request name name1(k-1) associated with the previous second instance, that is, the name value in the second dictionary dict2 key is different from the previous time, it means that the reporting configuration file b has been updated. Remove the key-value pair of the previous second instance value1(k-1) and the request name key1(k-1) associated with the previous second instance in the second dictionary dict2, and update the second dictionary according to the fixed parameters of the reporting configuration file.
[0129] It should be noted that fixed parameters are a set of predefined parameters that do not change frequently. These parameters are critical to the operation of the container and are consistent in multiple environments or services. Fixed parameters include service name, version information, environment identifier, performance indicator list, security settings, resource limits, dependent service list, reporting frequency, alarm threshold, and custom parameters. The service name is used to identify the unique name of the service for logging, monitoring, and troubleshooting; the version information is the current version number of the application or service, which helps to track and trace back problems; the environment identifier is used to identify the environment in which the current application runs; the performance indicator list includes CPU usage, memory usage, response time, etc.; security settings include encryption keys, security protocol versions, access control lists, etc.; resource limits include the upper limit of resources that the container can use, such as memory limits, thread pool size, etc.; the dependent service list is a list of other services that the container depends on, including service names and access addresses; the reporting frequency is the frequency or time interval for reporting data to the monitoring system; the alarm threshold is the condition and threshold setting for triggering an alarm; and custom parameters are other fixed parameters defined according to specific business needs.
[0130] Upload the updated second dictionary to the coordination service component. Regularly report the container health status, request status, specified value, and key-value pair to the coordination service component Zookeeper.
[0131] After the report is completed, close the scheduled task and delete the relevant nodes corresponding to the coordination service component Zookeeper.
[0132] Through the above container status detection device, the configuration center and local configuration files are used to achieve high customization and portability. You only need to modify the configuration file to run in different k8s clusters, and it is convenient to manage the monitored service containers. The URL request information reported to the coordination service component zookeeper contains a specific HTTP return code, which can have more customized operation and maintenance of the status of the deployed container. By subscribing to the coordination service component zookeeper, you can get the status notification of the deployed container in real time. There is no need to view the container status through the kubectl command line tool, which reduces the workload of the operation and maintenance personnel. In addition, other services or monitoring tools can also query the coordination service component zookeeper to view the container status information to determine the available containers, so as to achieve customization and meet the specific needs of developers.
[0133] The present application also provides an electronic device. Fig.10 The electronic device includes a memory 902 and a processor 901. The memory 902 stores a computer program. When the processor 901 executes the computer program, the container status detection method is implemented. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.
[0134] The processor 901 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits, etc., and is used to execute relevant programs to implement the technical solution provided in the embodiment of the present application; the memory 902 can be implemented in the form of a read-only memory (Read Only Memory, ROM), a static storage device, a dynamic storage device or a random access memory (Random Access Memory, RAM), etc. The memory 902 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 902, and the processor 901 is called to execute the container status detection method of the embodiment of the present application.
[0135] The input / output interface 903 is used to realize information input and output; the communication interface 904 is used to realize communication interaction between this device and other devices, and communication can be realized through wired methods (such as USB, network cable, etc.) or wireless methods (such as mobile network, WIFI, Bluetooth, etc.); the bus 905 transmits information between the various components of the device (such as the processor 901, the memory 902, the input / output interface 903 and the communication interface 904); wherein the processor 901, the memory 902, the input / output interface 903 and the communication interface 904 realize communication connection with each other within the device through the bus 905.
[0136] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the above container status detection method is implemented.
[0137] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0138] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0139] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.
[0140] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0141] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.
[0142] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0143] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0144] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0145] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0146] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0147] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.
[0148] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.
Claims
1. A container status detection method, characterized in that: include: Get the address of the coordination service component and the reporting configuration file; executing a scheduled task of periodically initiating a request to a container according to the configuration information of the reported configuration file, storing an instance of the scheduled task in a first dictionary to obtain a first instance, and updating the first dictionary when the current first instance is different from the previous first instance; connecting to the coordination service component according to the address of the coordination service component; The first instance in the first dictionary is stored in the second dictionary to obtain a second instance. When the current second instance is different from the previous second instance, the second dictionary is updated according to the fixed parameters of the reported configuration file, and the updated second dictionary is uploaded to the coordination service component.
2. The container status detection method according to claim 1, characterized in that: The obtaining the address of the coordination service component includes: Get the environment name based on the environment variables of the container cluster; Obtain a local configuration file of the configuration center of the container cluster, and obtain the address of the configuration center and configuration information of the configuration center from the local configuration file according to the environment name; Connecting to the configuration center according to the address of the configuration center and the configuration information of the configuration center; The address of the coordination service component is obtained from the configuration center.
3. The container status detection method according to claim 2, characterized in that: The obtaining and reporting configuration file comprises: Get the name of the reported configuration file based on the environment variables of the container cluster; The reporting configuration file is obtained from the configuration center according to the name of the reporting configuration file.
4. The container status detection method according to claim 1, characterized in that: The step of storing the instance of the scheduled task in a first dictionary to obtain a first instance includes: Using the request name of the configuration information of the reporting configuration file as a key, the instance of the scheduled task is stored in a first dictionary to obtain a first instance.
5. The container status detection method according to claim 4, characterized in that: The updating of the first dictionary when the current first instance is different from the previous first instance includes: When the request name associated with the current first instance is different from the request name associated with the previous first instance, stop the scheduled task corresponding to the request name associated with the previous first instance, remove the previous first instance and the request name associated with the previous first instance in the first dictionary, and update them to the current first instance and the request name of the current first instance.
6. The container status detection method according to claim 4, characterized in that: The step of storing the first instance in the first dictionary into the second dictionary to obtain the second instance includes: Using the request name of the first instance in the first dictionary as a key, the first instance in the first dictionary is stored in a second dictionary to obtain a second instance.
7. The container status detection method according to claim 6, characterized in that: When the current second instance is different from the previous second instance, updating the second dictionary according to the fixed parameters of the reported configuration file includes: When the request name associated with the current second instance is different from the request name associated with the previous second instance, remove the previous second instance and the request name associated with the previous second instance in the second dictionary, and update the second dictionary according to the fixed parameters of the reporting configuration file.
8. A container status detection device, characterized in that: include: A pre-preparation module is used to obtain the address of the coordination service component and obtain the reporting configuration file; A scheduled task management module, configured to execute a scheduled task of periodically initiating a request to a container according to the configuration information of the reported configuration file, store an instance of the scheduled task in a first dictionary to obtain a first instance, and update the first dictionary when the current first instance is different from the previous first instance; A connection module, used for connecting to the coordination service component according to the address of the coordination service component; A reporting module is used to store the first instance in the first dictionary into a second dictionary to obtain a second instance. When the current second instance is different from the previous second instance, the second dictionary is updated according to the fixed parameters of the reporting configuration file, and the updated second dictionary is uploaded to the coordination service component.
9. An electronic device, characterized in that: The electronic device comprises a memory and a processor, the memory stores a computer program, and the processor implements the container status detection method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the container status detection method according to any one of claims 1 to 7 is implemented.
