Custom configuration method and device of container host name, equipment and medium

Through the collaborative work of the interface service component and the callback component, the custom host name field is added, which solves the problem of insufficient container host name configuration in the existing technology, realizes the customization of the container host name, and improves the flexibility of container management and orchestration. and efficiency.

CN118567833APending Publication Date: 2024-08-30DUXIAOMAN TECH (BEIJING) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410429814.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-10
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

In the existing technology, the host name automatically configured when the container is established cannot meet the needs of large-scale container operations, and it lacks custom configuration capabilities, making management and orchestration difficult.

Method used

Through the collaborative work of the interface service component and the callback component, it receives a container creation request, adds a custom host name field, generates a target request according to preset rules, and creates a container with a custom host name.

Benefits of technology

It realizes customized configuration of container host names to meet user needs, improves the efficiency of container management and orchestration, and facilitates users to flexibly configure and operate containers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118567833A
    Figure CN118567833A
Patent Text Reader

Abstract

The invention discloses a custom configuration method and device for a container host name, equipment and a medium. An interface service component receives a container creation initial request and calls a callback component; the callback component obtains the container creation initial request, adds a host name field in the container creation initial request according to a preset custom rule, and generates a container creation target request; the callback component returns the container creation target request to the interface service component; and the interface service component receives the container creation target request and creates a target container based on the host name field in the container creation target request, so that a user-defined easy host name strategy can be provided for the Pod container.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure generally relates to the field of computer technology, and more particularly to a method, apparatus, device, and medium for customizing a container host name. Background Art

[0002] Container application systems, such as the open-source Kubernetes system, are used to deploy and manage containerized applications. Using container application systems to support applications and application development can provide load balancing capabilities for physical server clusters and streamlined container management across servers, reducing enterprise maintenance costs.

[0003] In the related art, when a container is created, the container host name is usually automatically configured by using the container host name setting rules in the Kubernetes system. However, when the number of containers created is large, the automatically configured container host name cannot meet the needs of container operations. Summary of the Invention

[0004] In view of the above-mentioned defects or deficiencies in the prior art, it is desirable to provide a method, apparatus, device and medium for custom configuration of container hostnames, which can provide a custom hostname strategy for Pod containers.

[0005] In a first aspect, an embodiment of the present application provides a method for customizing a container host name, including:

[0006] The interface service component receives the initial request from the container to create and calls the callback component;

[0007] The callback component obtains the initial container creation request, adds a host name field to the initial container creation request according to a preset custom rule, and generates a target container creation request;

[0008] The callback component returns the container creation target request to the interface service component;

[0009] The interface service component receives the container creation target request and creates a target container based on the host name field in the container creation target request.

[0010] In some embodiments, the interface service component receives an initial container creation request, including:

[0011] The interface service component receives an initial container creation request sent by a workload resource object.

[0012] In some embodiments, before calling the callback component, the method further includes:

[0013] A callback service including the custom rule is created for the callback component, and a callback service address is registered.

[0014] In some embodiments, adding a host name field to the initial container creation request according to a preset custom rule to generate a target container creation request includes:

[0015] In the initial container creation request, a custom comment field is added to generate the target container creation request, and the custom comment field is annotated with a fixed key value as the host name of the target container.

[0016] In some embodiments, before creating the target container based on the host name field in the container creation target request, the method further includes:

[0017] The interface service component writes a target host name corresponding to the target container into the custom annotation field in the container creation target request, where the target host name is generated according to a customized host name naming rule.

[0018] In some embodiments, creating a target container based on the host name field in the container creation target request includes:

[0019] Perform a validity check on the target host name.

[0020] In some embodiments, the target host name is assigned to a Pod container host name configuration variable and a Pod sandbox container host name configuration variable.

[0021] In a second aspect, an embodiment of the present application provides a device for customizing a container host name, including an interface service component and a callback component;

[0022] The interface service component is used to receive the initial container creation request and call the callback component;

[0023] The callback component obtains the initial container creation request, adds a host name annotation to the initial container creation request according to a preset custom rule, and generates a target container creation request;

[0024] The callback component returns the container creation target request to the interface service component;

[0025] The interface service component receives the container creation target request and creates a target container based on the host name annotation in the container creation target request.

[0026] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in the embodiment of the present application when executing the program.

[0027] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium on which a computer program is stored, which, when executed by a processor, implements the method described in the embodiment of the present application.

[0028] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, characterized in that when the computer program is executed by a processor, it implements the method described in the embodiment of the present application.

[0029] The container host name customization method proposed in the embodiment of the present application can add a host name field to the container creation request through a callback component before creating the container, so that a custom host name that meets customer needs can be written into the container creation request, and a target container is generated according to the custom host name, thereby meeting the purpose of customizing the container host name and facilitating user orchestration and management of containers.

[0030] Additional aspects and advantages of the present invention will be set forth in part in the description which follows and, in part, will be obvious from the description which follows, or may be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] Other features, objects and advantages of the present application will become more apparent upon reading the detailed description of non-limiting embodiments made with reference to the following drawings:

[0032] Figure 1 A schematic diagram illustrating a process of customizing a container host name configuration method according to an embodiment of the present application is shown;

[0033] Figure 2 A schematic diagram illustrating a method for customizing a container host name according to an embodiment of the present application is shown;

[0034] Figure 3 A schematic diagram of the structure of a computer system of an electronic device or server suitable for implementing an embodiment of the present application is shown. DETAILED DESCRIPTION

[0035] The present application will be further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are merely for the purpose of explaining the relevant invention and are not intended to limit the invention. It should also be noted that, for ease of description, only portions relevant to the invention are shown in the accompanying drawings.

[0036] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments in this application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0037] Kubernetes, or K8s for short, is an open-source container orchestration engine developed by Google that supports automated deployment, massive scalability, and containerized application management. Kubernetes' goal is to make deploying containerized applications simple and efficient. Kubernetes provides a series of mechanisms for application deployment, planning, updating, and maintenance. When deploying an application in a production environment, you typically deploy multiple instances of the application to load balance application requests. In Kubernetes, you can create multiple containers, each running an application instance, and then manage, discover, and access this group of application instances using built-in load balancing strategies.

[0038] In the existing technology, when deploying a container, the container host name is set according to the built-in rules of K8s:

[0039] 1. If pod.spec.hostname is set and pod.spec.subdomain is not set, [pod.spec.hostname] is used as the container hostname;

[0040] 2. If pod.spec.hostname and pod.spec.subdomain are set, use [pod.spec.hostname] and [pod.spec.subdomain] as the container hostname;

[0041] 3. If pod.spec.hostname is not set, [pod.metadata.name], i.e. pod name, is used as the container hostname.

[0042] However, as the number of application instances deployed increases, users hope to be able to customize the container host name so that they can manage the containers more efficiently during orchestration and management.

[0043] Based on this, the present application proposes a method, apparatus, device and medium for custom configuration of container hostnames to provide a more flexible method for configuring container hostnames to meet the user's customization needs.

[0044] In order to further illustrate the technical solutions provided by the embodiments of the present application, this is described in detail below with reference to the accompanying drawings and specific implementation methods. Although the embodiments of the present application provide the method operation instruction steps shown in the following embodiments or drawings, more or fewer operation instruction steps may be included in the method based on conventional or no creative labor. In the steps where there is no necessary causal relationship logically, the execution order of these steps is not limited to the execution order provided by the embodiments of the present application. The method may be executed in the order of the methods shown in the embodiments or drawings or in parallel during the actual processing process or when the device is executed.

[0045] Please refer to Figure 1 and Figure 2 , Figure 1 The following is a flow chart showing a method for customizing the container host name according to an embodiment of the present application. Figure 1 As shown, the method includes:

[0046] Step 101: The interface service component receives a container creation initial request and calls a callback component.

[0047] It's important to note that the interface service component is the kube-apiserver, or API interface service. The kube-apiserver is a component of the Kubernetes control plane that exposes the Kubernetes API. A container is a portable, executable, lightweight image that contains the software and its dependencies. Containers run in pods. A pod is an atomic object in Kubernetes that represents a group of running containers in a cluster.

[0048] In a feasible embodiment, the interface service component receives an initial container creation request sent by a workload resource object.

[0049] It should be noted that workload resource objects include but are not limited to warehouse management resource objects such as Deployments, replica set resource objects such as ReplicaSet, and service state resource objects such as StatefulSet.

[0050] It should be understood that since workload resource objects generate Pod containers using Pod container configuration templates, and the same Pod container configuration template cannot define different container hostname configurations, it is not possible to customize the hostname configuration for Pod containers generated by workload resources such as Deployments, ReplicaSets, and StatefulSets. Specifically, since the templates used to generate Pod containers are the same, the configuration of several Pod containers generated by the workload resource objects will be the same, that is, the container hostname will be the same. However, different Pod containers should have different, customized container hostnames according to expected requirements.

[0051] Therefore, the custom configuration method of the container host name provided in the embodiment of the present application can provide a custom container host name strategy for the Pod container created by the workload resource object after the interface service component receives the initial container request sent by the workload resource object, making it convenient for users to customize and manage the host names of the containers in the system.

[0052] Furthermore, after receiving the initial container creation request, the interface service component may call the callback component through the callback service address.

[0053] The callback component Webhook is a callback component reserved for users in K8s. It is a custom extensible mechanism that allows users to implement custom operations through HTTP callbacks.

[0054] In an embodiment of the present application, a callback service address is registered for the callback service when creating the callback component Webhook, so that the interface service component calls the callback service component according to the callback service address when receiving the initial container creation request.

[0055] Optionally, an interception function can be configured for the callback component Webhook. Specifically, after receiving the initial container creation request, the interface service component needs to send the initial container creation request to the database. Therefore, in an embodiment of the present application, the callback component Webhook can also be set between the interface service component and the database to intercept the interface component sending the initial container creation request to the database, thereby achieving the purpose of the interface service component calling the callback component.

[0056] That is to say, the embodiment of the present application also defines the function of the callback component Webhook, which can be used to intercept and modify the control signaling sent by the interface service component kube-apiserver to the database, such as Pod container creation.

[0057] In step 102, the callback component obtains the initial container creation request, adds the host name field to the initial container creation request according to a preset custom rule, and generates a target container creation request.

[0058] It should be noted that the callback component Webhook obtains the initial container creation request from the interface service component through interception or passive call.

[0059] In a feasible embodiment, in the initial container creation request, a custom comment field is added to generate a target container creation request.

[0060] That is, the callback component rewrites the received initial request for creating a container, adds a field with a custom annotation, and annotates the field with the host name of the target container using a fixed part-time number.

[0061] For example, the callback component adds the field pod.metadata.annotations["fec2 / container-hostname"] to the initial container creation request, where "fec2 / container-hostname" is a fixed key value used to identify the annotation as the Pod container hostname.

[0062] In specific applications, the interface service component only needs to write the target host name into this field during the specific creation process, and the target container can be generated according to the target host name written in this field, thereby achieving the purpose of customizing the container host name.

[0063] Step 103: The callback component returns a container creation target request to the interface service component.

[0064] Step 104: The interface service component receives a container creation target request and creates a target container based on a host name field in the container creation target request.

[0065] Specifically, the interface service component writes the target host name corresponding to the target container into the custom comment field in the container creation target request.

[0066] It should be noted that the interface service component can generate the target host name according to the customized host name naming rules set in advance by the user. The specific generation rules are not specifically limited in this application.

[0067] For example, the interface service component may write "redis-01.redis.fec.xd01.zzjg.dxm-int.com" as the target host name into the pod.metadata.annotations["fec2 / container-hostname"] field, recorded as pod.metadata.annotations["fec2 / container-hostname"] = "redis-01.redis.fec.xd01.zzjg.dxm-int.com".

[0068] Among them, "redis-01.redis.fec.xd01.zzjg.dxm-int.com" can be generated by the interface service component according to the host name naming rule customized in advance by the user.

[0069] Furthermore, after the interface service component writes the target host name corresponding to the target container in the custom comment field in the container creation target request, a complete container creation target request can be obtained, and the target container can be created based on the container creation target request.

[0070] Therefore, the custom configuration method of the container host name proposed in the embodiment of the present application can add a host name field to the container creation request through a callback component before creating the container, so that a custom host name that meets customer needs can be written for the container creation request, and the target container is generated according to the custom host name, thereby meeting the purpose of customizing the container host name and making it easier for users to orchestrate and manage containers.

[0071] In a feasible embodiment, creating a target container based on a host name field in a container creation target request includes: performing a validity check on the target host name.

[0072] Among them, the legitimacy check of the host name refers to the check of the host name string of the Pod container. The legitimacy check items can be customized according to needs, including but not limited to host name duplication check, string length limit, whether there are special characters, whether it ends with "xxx.com", etc. This application does not make specific restrictions.

[0073] In a feasible embodiment, the proxy component Kubelet can be used to perform validity checks.

[0074] Among them, Kubelet is the agent component on the Kubernetes worker node, running on each node, mainly used to create, manage and monitor containers.

[0075] Specifically, when the Kubelet component creates a target container based on the container creation target request provided by the interface service component, it first determines whether the container creation target request contains the pod.metadata.annotations field. If it does, it performs a validity check on it. If it does not, the Pod container host name is generated according to the native logic of Kubernetes.

[0076] Furthermore, in the logic of setting the Pod container host name when creating the target container, the Kubelet component assigns the target host name to the Pod container host name configuration variable kubecontainer.RunContainerOptions.Hostname and the Pod sandbox container host name configuration variable runtimeapi.PodSandboxConfig.Hostname, completing the configuration of the custom host name of the target container.

[0077] The Pod sandbox container, also known as the sandbox container, is created by Kubelet when creating a pod. It then creates user-defined containers. The sandbox container is used to initialize network resources, among other things.

[0078] It should be noted that although the operations of the present method are described in a particular order in the drawings, this does not require or imply that the operations must be performed in this particular order, or that all illustrated operations must be performed to achieve desirable results.

[0079] In summary, the custom configuration method for the container host name proposed in the embodiment of the present application can add a host name field to the container creation request through a callback component before creating the container, so that a custom host name that meets customer needs can be written to the container creation request, and the target container is generated according to the custom host name, thereby meeting the purpose of customizing the container host name and facilitating the user to orchestrate and manage the container.

[0080] Reference below Figure 3 , Figure 3 A schematic diagram of the structure of a computer system of an electronic device or server suitable for implementing the embodiments of the present application is shown.

[0081] like Figure 3As shown, the computer system includes a central processing unit (CPU) 301, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 302 or the program loaded from the storage part 308 into the random access memory (RAM) 303. Various programs and data required for the operation instructions of the system are also stored in the RAM 303. The CPU 301, ROM 302 and RAM 303 are connected to each other via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.

[0082] The following components are connected to the I / O interface 305: an input section 306 including a keyboard, a mouse, and the like; an output section 307 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and a speaker; a storage section 308 including devices such as a hard disk; and a communication section 309 including a network interface card such as a LAN card or a modem. The communication section 309 performs communication processing via a network such as the Internet. A drive 310 is also connected to the I / O interface 305 as needed. A removable medium 311, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 310 as needed, so that computer programs read therefrom can be installed into the storage section 308 as needed.

[0083] In particular, according to the embodiment of the present application, the above reference flow chart Figure 2 The described process can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 309, and / or installed from a removable medium 311. When the computer program is executed by the central processing unit (CPU) 301, the above-mentioned functions defined in the system of the present application are executed.

[0084] It should be noted that the computer-readable medium shown in this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this application, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, device, or device. In this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. This propagated data signal can take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transfer a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wire, optical cable, RF, or any suitable combination thereof.

[0085] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operating instructions of the systems, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the aforementioned module, program segment, or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than the order marked in the accompanying drawings. For example, the boxes represented by two connections can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of the boxes in the block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or operating instruction, or can be implemented using a combination of dedicated hardware and computer instructions.

[0086] The units or modules involved in the embodiments described in this application may be implemented in software or hardware, and may also be provided in a processor.

[0087] As another aspect, the present application further provides a computer-readable storage medium, which may be included in the electronic device described in the above embodiments, or may exist independently and not be incorporated into the electronic device. The computer-readable storage medium stores one or more programs, which, when used by one or more processors, execute the method for customizing the container hostname described in the present application.

[0088] The above description is merely a preferred embodiment of the present application and an illustration of the technical principles employed. Those skilled in the art should understand that the scope of disclosure in this application is not limited to the technical solutions formed by a specific combination of the above-mentioned technical features, but also encompasses other technical solutions formed by any combination of the above-mentioned technical features or their equivalents without departing from the aforementioned disclosed concepts. For example, a technical solution formed by replacing the above-mentioned features with (but not limited to) technical features with similar functions disclosed in this application.

Claims

1. A method for customizing a container host name, characterized in that: include: The interface service component receives the container's initial creation request and calls the callback component; The callback component obtains the initial container creation request, adds a host name field to the initial container creation request according to a preset custom rule, and generates a target container creation request; The callback component returns the container creation target request to the interface service component; The interface service component receives the container creation target request and creates a target container based on the host name field in the container creation target request.

2. The method for customizing the container host name according to claim 1, characterized in that: The interface service component receives an initial container creation request, including: The interface service component receives an initial container creation request sent by a workload resource object.

3. The method for customizing the container host name according to claim 1, characterized in that: Before calling the callback component, it also includes: A callback service including the custom rule is created for the callback component, and a callback service address is registered.

4. The method for customizing the container host name according to claim 2, characterized in that: The adding a host name field in the initial container creation request according to a preset custom rule to generate a target container creation request includes: In the container creation initial request, a custom annotation field is added to generate the container creation target request, and the custom annotation field is annotated with a host name of the target container using a fixed key value.

5. The method for customizing the container host name according to claim 4, characterized in that: Before creating the target container based on the host name field in the container creation target request, the method further includes: The interface service component writes a target host name corresponding to the target container into the custom annotation field in the container creation target request, where the target host name is generated according to a customized host name naming rule.

6. The method for customizing the container host name according to claim 5, characterized in that: The step of creating a target container based on the host name field in the container creation target request includes: A validity check is performed on the target host name.

7. The method for customizing the container host name according to claim 5, characterized in that: Also includes: Assign the target host name to the Pod container host name configuration variable and the Pod sandbox container host name configuration variable.

8. A device for customizing a container host name, characterized in that: Includes interface service components and callback components; The interface service component is used to receive an initial request for container creation and call a callback component; The callback component obtains the initial container creation request, adds a host name annotation to the initial container creation request according to a preset custom rule, and generates a target container creation request; The callback component returns the container creation target request to the interface service component; The interface service component receives the container creation target request and creates a target container based on the host name annotation in the container creation target request.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method for customizing the container host name as described in any one of claims 1 to 7 is implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method for customizing the container host name as described in any one of claims 1 to 7 is implemented.