Method, device and equipment for accessing web service in K8S cluster
A reverse proxy function on a cloud management platform addresses the poor network applicability of K8S cluster access by managing user permissions and updating addresses, enhancing access security and simplifying network configurations.
Patent Information
- Application Number
- CN202411287054.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-13
- Publication Date
- 2024-12-06
AI Technical Summary
Existing methods for accessing web services in K8S clusters have poor network applicability, requiring complex proxy configurations and limiting direct network access.
Implement a reverse proxy function on a cloud management platform to manage user access requests, determining permissions and updating addresses to access web services in K8S clusters without complex network configurations.
Enables access to K8S cluster web services through a reverse proxy, improving network applicability and enhancing access security with user identity tokens.
Smart Images

Figure CN119094594A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a technology for accessing web services in a K8S cluster. Background Art
[0002] With the rapid development of cloud native technology and the promotion and use of containerization technology, more and more application services are choosing containerized deployment. K8S (Kubernetes) is an open source container cluster management tool that uses containerization technology. It uses K8S clusters to deploy application services in containers, define K8S containerized application services (services), deploy application service loads, configure access routes, provide direct access to external network IPs, or use Ingress or other routing methods that act as edge routers to ensure that users can access application services in the K8S cluster.
[0003] For containerized web services deployed in K8S clusters, in the case of complex network environments, the existing methods for accessing web services in K8S clusters have high network requirements and may require relatively cumbersome proxy configuration. There is a technical problem that the network environment needs to be relied on for corresponding configuration, resulting in poor network applicability. Summary of the invention
[0004] The purpose of the present invention is to provide a method, device and equipment for accessing web services in a K8S cluster, so as to at least partially solve the technical problem that the existing method for accessing web services in a K8S cluster has poor network applicability.
[0005] According to one aspect of the present invention, a method for accessing a web service in a K8S cluster is provided, which is applied to a cloud management platform for configuring a reverse proxy, and is characterized in that the method comprises:
[0006] Receive the first request from the user through the web client to access the target web service in the K8S cluster;
[0007] Determine whether the user has permission to access the target web service in the K8S cluster. If yes, change the user address in the first request to the reverse proxy address to obtain the second request;
[0008] The second request is sent to the address corresponding to the target web service in the K8S cluster to access the target web service in the K8S cluster.
[0009] Optionally, the determining whether the user has permission to access the target web service in the K8S cluster, if yes, changing the user address in the first request to a reverse proxy address, and obtaining the second request includes:
[0010] Determine whether the user has permission to access the target web service in the K8S cluster. If so, obtain the user identity token, change the user address in the first request to a reverse proxy address, and add the user identity token to the first request to obtain a second request.
[0011] Optionally, the obtaining of a user identity token includes:
[0012] Get the user's K8S cluster configuration file and use it as the user identity token.
[0013] Optionally, sending the second request to an address corresponding to a target web service in the K8S cluster includes:
[0014] Through the K8S cluster gateway component, the second request is sent to the address corresponding to the target web service in the K8S cluster.
[0015] Optionally, the method for accessing a web service in a K8S cluster further includes:
[0016] Receive the response returned by the address corresponding to the target web service in the K8S cluster and send it to the web client.
[0017] Optionally, if the html webpage in the response includes a base tag, before sending it to the web client, the method for accessing a web service in a K8S cluster further includes:
[0018] Correct the href attribute of the base tag.
[0019] According to another aspect of the present invention, a method for accessing a web service in a K8S cluster is provided, which is applied to a web client, and is characterized in that the method comprises:
[0020] Based on the user input information, a first request for accessing the target web service in the K8S cluster is generated and sent to the cloud management platform, wherein the cloud management platform determines whether the user has the authority to access the target web service in the K8S cluster. If so, the user address in the first request is changed to a reverse proxy address to obtain a second request, and the second request is sent to the address corresponding to the target web service in the K8S cluster to achieve access to the target web service in the K8S cluster.
[0021] Optionally, the method for accessing a web service in a K8S cluster further includes:
[0022] Receive a response sent by the cloud management platform.
[0023] According to another aspect of the present invention, there is provided a device for accessing a web service in a K8S cluster, which is deployed on a cloud management platform configured with a reverse proxy, wherein the device comprises:
[0024] The first module is used to receive a first request sent by a user through a web client to access a target web service in a K8S cluster;
[0025] The second module is used to determine whether the user has the authority to access the target web service in the K8S cluster. If so, the user address in the first request is changed to a reverse proxy address to obtain a second request;
[0026] The third module is used to send the second request to the address corresponding to the target web service in the K8S cluster to achieve access to the target web service in the K8S cluster.
[0027] Optionally, the device for accessing a web service in a K8S cluster further includes:
[0028] The fourth template is used to receive a response returned by the address corresponding to the target web service in the K8S cluster, and send it to the web client.
[0029] Compared with the prior art, the present invention provides a method, device and equipment for accessing web services in a K8S cluster. The method includes: a user sends a first request to access a target web service in a K8S cluster to a cloud management platform configured with a reverse proxy through a web client; the cloud management platform determines whether the user has the authority to access the target web service in the K8S cluster, and if so, changes the user address in the first request to a reverse proxy address to obtain a second request; the cloud management platform sends the second request to the address corresponding to the target web service in the K8S cluster to access the target web service in the K8S cluster. Optionally, the cloud management platform determines whether the user has the authority to access the target web service in the K8S cluster, and if so, obtains a user identity token, changes the user address in the first request to a reverse proxy address, and adds the user identity token to the first request to obtain a second request. Optionally, the cloud management platform receives a response returned by the address corresponding to the target web service in the K8S cluster and sends it to the web client.
[0030] The technical effects that the present invention can bring are:
[0031] There is no need to configure the network environment of the K8S cluster. Through the reverse proxy function provided by the cloud management platform, even if the authorized user cannot directly access the K8S cluster through the network, the target web service under the K8S cluster can be accessed, which improves the applicability of the network. Optionally, access control can be performed through user identity tokens to further improve access security. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0033] Figure 1 A schematic diagram of a system for accessing web services in a K8S cluster according to the present invention is shown;
[0034] Figure 2 A schematic diagram of a method for accessing a web service in a K8S cluster applied to a cloud management platform configured with a reverse proxy according to one aspect of the present invention;
[0035] Figure 3 A schematic diagram of a method for accessing a web service in a K8S cluster applied to a web client according to another aspect of the present invention is shown;
[0036] Figure 4 A schematic diagram of a device for accessing a web service in a K8S cluster deployed on a cloud management platform configured with a reverse proxy according to another aspect of the present invention is shown;
[0037] The same or similar reference numerals in the drawings represent the same or similar components. DETAILED DESCRIPTION
[0038] The present invention is further described in detail below in conjunction with the accompanying drawings.
[0039] In a typical configuration of each embodiment of the present invention, the execution subject of the method, each trusted party of the system and / or each module of the device may include one or more processors (CPU), input / output interface, network interface and memory.
[0040] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0041] Computer readable media may include permanent and non-permanent, removable and non-removable media, and may be implemented by any method or technology to store information. Information may be computer readable instructions, data structures, modules of programs, or other data. Computer storage media may include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include non-transitory media such as modulated data signals and carrier waves.
[0042] In the case of a complex K8S cluster environment, the existing method of accessing web services in the K8S cluster has high network requirements and may require relatively cumbersome proxy configuration. There is a technical problem that the network applicability is not strong, and users may not be able to directly access the application services in the K8S cluster through the network.
[0043] This application requests protection for a technical solution for accessing web services in a K8S cluster. An exemplary system diagram is shown in FIG. Figure 1 As shown. By using the management interface and functions of the cloud management platform, the reverse proxy function is configured on the cloud management platform. When a user initiates an access request to the web service in the K8S cluster through the web client, the cloud management platform receives the access request and determines the user's access rights based on the user's account information. If the user has access rights, the target address in the access request remains unchanged, and the access address is replaced with the reverse proxy address configured by the cloud management platform (which can be the web service address of the cloud management platform), and the access request is updated. The updated access request is then sent to the corresponding K8S cluster, and access to the target web service is achieved through the apiserver component of the K8S cluster.
[0044] In order to further illustrate the technical means adopted by the present invention and the effects achieved, the technical scheme of the present invention is clearly and completely described below in conjunction with the accompanying drawings and various embodiments.
[0045] Figure 2 A schematic diagram of a method for accessing a web service in a K8S cluster by a cloud management platform configured with a reverse proxy according to one aspect of the present invention is shown, wherein the method of one embodiment includes:
[0046] S201 receives a first request from a user via a web client to access a target web service in a K8S cluster;
[0047] S202 determines whether the user has permission to access the target web service in the K8S cluster. If yes, the user address in the first request is changed to a reverse proxy address to obtain a second request;
[0048] S203 sends the second request to the address corresponding to the target web service in the K8S cluster to access the target web service in the K8S cluster.
[0049] The method of this embodiment is implemented by installing a cloud management platform 100 with corresponding software and hardware, deploying a reverse proxy function in the cloud management platform 100 and performing reverse proxy configuration, configuring the web service address of the cloud management platform 100 to a reverse proxy address, and external users can access the cloud management platform 100 through a web client, and the cloud management platform 100 can access the K8S cluster through the network. The cloud management platform 100 can be a computer device and / or a cloud. The computer device includes but is not limited to a personal computer, a laptop computer, an industrial computer, a server, a network host, a single network server or a network server cluster; the cloud is composed of a large number of computers or network servers based on cloud computing (Cloud Computing), wherein cloud computing is a type of distributed computing, a virtual supercomputer composed of a group of loosely coupled computer sets.
[0050] Here, the computer device and / or cloud are only examples. Other existing or future devices and / or resource sharing platforms that are applicable to the present application should also be included in the protection scope of the present application and are incorporated herein by reference.
[0051] In this embodiment, in step S201, the cloud management platform 100 receives a first request for accessing a target web service in a K8S cluster, sent by a user through a web client.
[0052] The user can send a first request to access the target web service in the K8S cluster to the cloud management platform 100 after inputting his account information in the web client according to his needs, wherein the first request at least includes: the user address of the web client, the user account information, the address corresponding to the target web service and the access request information. The cloud management platform 100 receives the first request.
[0053] Continuing with this embodiment, in step S202, the cloud management platform 100 determines whether the user has the authority to access the target web service in the K8S cluster. If so, the user address in the first request is changed to a reverse proxy address to obtain a second request.
[0054] Among them, after receiving the first request, the cloud management platform 100 can parse the first request, obtain the user account information therein, and check the specific operation permissions of the corresponding namespace according to the user account information to determine whether the user has the permission to access the target web service in the K8S cluster. If the user has access rights, the user address in the first request is changed to the reverse proxy address configured in the cloud management platform 100 to obtain the second request. If the user does not have access rights, he cannot access resources normally through the reverse proxy of the cloud management platform 100. As an exemplary example, user permissions can be managed in the relevant functional modules of the cloud management platform, and the user account can be assigned to a namespace with specific operation permissions corresponding to a role of the K8S cluster through rolebinding, wherein the role can be specifically refined to a certain operation or a set of operations for a certain application service of the K8S cluster.
[0055] In order to further improve access security, optionally, step S202 includes:
[0056] Determine whether the user has permission to access the target web service in the K8S cluster. If so, obtain the user identity token, change the user address in the first request to a reverse proxy address, and add the user identity token to the first request to obtain a second request.
[0057] Among them, the cloud management platform 100 can check the specific operation permissions of the corresponding namespace according to the user account information, and determine whether the user has the permission to access the target web service in the K8S cluster. If the user has access permission, a token access control mechanism is adopted to obtain the user identity token, and the user identity token is added to the first request, and the user address in the first request is changed to a reverse proxy address to obtain an updated first request as the second request.
[0058] Optionally, in step S202, obtaining a user identity token includes:
[0059] Get the user's K8S cluster configuration file and use it as the user identity token.
[0060] The cloud management platform 100 can obtain the K8S cluster configuration file corresponding to the user, such as the Kubeconfig corresponding to the user, as a user identity token. The K8S cluster configuration file corresponding to the user may include user identification, private keys and certificates used to access the K8S cluster, etc. The configuration file is used as a user identity token, added to the first request, and the user address in the first request is changed to a reverse proxy address to obtain the updated first request as the second request.
[0061] Continuing with this embodiment, in step S203, the cloud management platform 100 sends the second request to the address corresponding to the target web service in the K8S cluster to access the target web service in the K8S cluster.
[0062] Among them, the cloud management platform 100 can send a second request including a reverse proxy address, access request information and other contents to the address corresponding to the target web service in the K8S cluster to achieve access to the target web service in the K8S cluster.
[0063] Optionally, in step S203, sending the second request to an address corresponding to a target web service in the K8S cluster includes:
[0064] Through the K8S cluster gateway component, the second request is sent to the address corresponding to the target web service in the K8S cluster.
[0065] Among them, the cloud management platform 100 can send the second request to the K8S cluster, and through the K8S cluster gateway component, such as the Kube-apiserver component, send the second request to the address corresponding to the target web service in the K8S cluster to achieve access to the target web service in the K8S cluster.
[0066] Through the above-mentioned embodiments and / or optional embodiments, even if the web client cannot directly access the network of the K8S cluster to which the target web service belongs, the reverse proxy function can be configured in the accessed cloud management platform 100 to access the target web service in the K8S cluster through the reverse proxy, without the need for complex proxy configuration of the network, thereby improving the network applicability.
[0067] Optionally, the method for accessing a web service in a K8S cluster by a cloud management platform for configuring a reverse proxy further includes:
[0068] S204 receives the response returned by the address corresponding to the target web service in the K8S cluster and sends it to the web client.
[0069] Among them, the address corresponding to the target web service in the K8S cluster processes the second request, generates a corresponding response, and returns the response to the cloud management platform 100 according to the reverse proxy address in the second request. The cloud management platform 100 receives the response and sends the response to the corresponding web client according to the user address in the first request.
[0070] Optionally, in step S204, if the html webpage in the response includes a base tag, before sending it to the web client, the method further includes:
[0071] Correct the href attribute of the base tag.
[0072] Among them, since the access address in the second request is changed to the address corresponding to the reverse proxy address and the target web service, the html web page static resource loading in the response is not necessarily a relative address directly corresponding to the above access address, but may be a certain base URL address, which can be identified by checking whether the html web page includes a base tag. After receiving the response, the cloud management platform 100 can first check its content. If the html web page in the response includes a base tag, it means that the html page static resource provided by the target web service may be loaded at a certain base URL address. The href attribute of the base tag needs to be corrected, and the address prefix of the href attribute is corrected back to the access address. Otherwise, the corresponding static resource may not be loaded correctly.
[0073] Figure 3 A schematic diagram of a method for accessing a web service in a K8S cluster applied to a web client according to another aspect of the present invention is shown, wherein the method of an embodiment includes:
[0074] S301 generates a first request for accessing the target web service in the K8S cluster based on the user input information, and sends it to the cloud management platform, wherein the cloud management platform determines whether the user has the authority to access the target web service in the K8S cluster. If so, the user address in the first request is changed to a reverse proxy address to obtain a second request, and the second request is sent to the address corresponding to the target web service in the K8S cluster to achieve access to the target web service in the K8S cluster.
[0075] Among them, the user can input account information and access request information through the web client according to his needs, generate a first request to access the target web service in the K8S cluster, and send it to the cloud management platform 100 to access the target web service in the K8S cluster. Among them, the operations performed by the cloud management platform 100 are the same as steps S201 to S204 in the aforementioned method embodiment and / or optional embodiment, and will not be repeated here.
[0076] Optionally, the method for accessing a web service in a K8S cluster by a web client further includes:
[0077] S302 receives a response sent by the cloud management platform.
[0078] The web client also receives a response sent by the cloud management platform 100 to display it on the web client so that the user can browse the target web service that the user requests to access.
[0079] Figure 4 A device for accessing a web service in a K8S cluster deployed on a cloud management platform configured with a reverse proxy according to another aspect of the present invention is shown, wherein the device of one embodiment includes:
[0080] The first module 410 is used to receive a first request sent by a user through a web client to access a target web service in a K8S cluster;
[0081] The second module 420 is used to determine whether the user has the authority to access the target web service in the K8S cluster. If so, the user address in the first request is changed to a reverse proxy address to obtain a second request;
[0082] The third module 430 is used to send the second request to the address corresponding to the target web service in the K8S cluster to access the target web service in the K8S cluster.
[0083] In this embodiment, the device has the same software and hardware environment as the cloud management platform 100 for executing the aforementioned method embodiment and / or optional embodiment.
[0084] In this embodiment, the user can send a first request to access the target web service in the K8S cluster to the cloud management platform 100 after inputting his account information in the web client according to his needs, wherein the first request at least includes: the user address of the web client, the user account information, the address corresponding to the target web service and the access request information. The first request is received by the first module 410 of the device in the cloud management platform 100.
[0085] Continuing in this embodiment, after the first module 410 receives the first request, the second module 420 of the device can parse the first request, obtain the user account information therein, and check the specific operation permissions of the corresponding namespace according to the user account information to determine whether the user has the permission to access the target web service in the K8S cluster. If the user has the access permission, the user address in the first request is changed to the reverse proxy address configured in the cloud management platform 100 to obtain the second request. If the user does not have the access permission, he cannot access the resource normally through the reverse proxy of the cloud management platform 100.
[0086] Continuing with this embodiment, through the third module 430 of the device, a second request including a reverse proxy address, access request information and the like can be sent to an address corresponding to a target web service in the K8S cluster to achieve access to the target web service in the K8S cluster.
[0087] Optionally, the device for accessing a web service in a K8S cluster deployed on a cloud management platform configured with a reverse proxy further includes:
[0088] The fourth template 440 is used to receive a response returned from the address corresponding to the target web service in the K8S cluster and send it to the web client.
[0089] In this optional embodiment, through the fourth module 440 of the device, a response generated after processing the second request at the address corresponding to the target web service in the K8S cluster can be received, and the response can be sent to the corresponding web client according to the user address in the first request.
[0090] In each embodiment and / or optional embodiment of the above-mentioned device, the unmentioned parts in the method steps performed by each module are the same as those in the aforementioned related method embodiments and / or optional embodiments, and will not be repeated here.
[0091] Through the method steps executed by each embodiment of the above-mentioned device and / or each module of the optional embodiment, the reverse proxy function can be configured in the accessed cloud management platform 100, and access to the target web service in the K8S cluster can be achieved through the reverse proxy, without the need for complex proxy configuration of the network, thereby improving the network applicability.
[0092] According to yet another aspect of the present invention, a computer-readable medium is provided, wherein the computer-readable medium stores computer-readable instructions, and the computer-readable instructions can be executed by a processor to implement the aforementioned method.
[0093] It should be noted that the various method embodiments of the present invention can be implemented in software and / or a combination of software and hardware. The software program involved in the present invention can be executed by a processor to implement the steps or functions of the above-mentioned various embodiments. Similarly, the software program of the present invention (including related data structures) can be stored in a computer-readable recording medium.
[0094] In addition, a part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. The program instruction for calling the method of the present invention may be stored in a fixed or removable recording medium, and / or transmitted through a data stream in a broadcast or other signal-bearing medium, and / or stored in a working memory of a computer device that operates according to the program instruction.
[0095] According to another aspect of the present invention, a device for accessing web services within a K8S cluster is also provided, the device comprising: a memory for storing computer program instructions and a processor for executing the program instructions, wherein when the computer program instructions are executed by the processor, the device is triggered to execute methods and / or technical solutions such as the aforementioned embodiments and / or optional embodiments.
[0096] It is obvious to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential features of the present invention. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-restrictive, and the scope of the present invention is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any figure mark in the claims should not be regarded as limiting the claims involved. In addition, it is obvious that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices stated in the device claim can also be implemented by one unit or device through software and / or hardware. The words first, second, etc. are used to indicate names, and do not indicate any particular order.
Claims
1. A method for accessing web services in a K8S cluster, applied to a cloud management platform for configuring a reverse proxy, characterized in that: The method comprises: Receive the first request from the user through the web client to access the target web service in the K8S cluster; Determine whether the user has permission to access the target web service in the K8S cluster. If yes, change the user address in the first request to the reverse proxy address to obtain the second request; The second request is sent to the address corresponding to the target web service in the K8S cluster to access the target web service in the K8S cluster.
2. The method according to claim 1, characterized in that: The determining whether the user has the authority to access the target web service in the K8S cluster, if yes, then changing the user address in the first request to the reverse proxy address, and obtaining the second request includes: Determine whether the user has permission to access the target web service in the K8S cluster. If so, obtain the user identity token, change the user address in the first request to a reverse proxy address, and add the user identity token to the first request to obtain a second request.
3. The method according to claim 2, characterized in that The obtaining of the user identity token comprises: Get the user's K8S cluster configuration file and use it as the user identity token.
4. The method according to claim 1, characterized in that: The sending of the second request to the address corresponding to the target web service in the K8S cluster includes: Through the K8S cluster gateway component, the second request is sent to the address corresponding to the target web service in the K8S cluster.
5. The method according to claim 1, characterized in that The method further comprises: Receive the response returned by the address corresponding to the target web service in the K8S cluster and send it to the web client.
6. The method according to claim 5, characterized in that If the HTML page in the response includes a base tag, before sending it to the web client, the method further includes: Correct the href attribute of the base tag.
7. A method for accessing web services in a K8S cluster, applied to a web client, characterized in that: The method comprises: Based on the user input information, a first request for accessing the target web service in the K8S cluster is generated and sent to the cloud management platform, wherein the cloud management platform determines whether the user has the authority to access the target web service in the K8S cluster. If so, the user address in the first request is changed to a reverse proxy address to obtain a second request, and the second request is sent to the address corresponding to the target web service in the K8S cluster to achieve access to the target web service in the K8S cluster.
8. The method according to claim 7, characterized in that The method further comprises: Receive a response sent by the cloud management platform.
9. A device for accessing web services in a K8S cluster, deployed on a cloud management platform configured with a reverse proxy, characterized in that: The device comprises: The first module is used to receive a first request sent by a user through a web client to access a target web service in a K8S cluster; The second module is used to determine whether the user has the authority to access the target web service in the K8S cluster. If so, the user address in the first request is changed to a reverse proxy address to obtain a second request; The third module is used to send the second request to the address corresponding to the target web service in the K8S cluster to achieve access to the target web service in the K8S cluster.
10. The method according to claim 1, characterized in that The device also includes: The fourth template is used to receive a response returned by the address corresponding to the target web service in the K8S cluster, and send it to the web client.
11. A computer readable medium, characterized in that Computer readable instructions are stored thereon, and the computer readable instructions are executed by a processor to implement the method according to any one of claims 1 to 6.
12. A device for accessing web services in a K8S cluster, characterized in that: The device comprises: one or more processors; and A memory storing computer readable instructions which, when executed, cause the processor to perform the operations of the method as claimed in any one of claims 1 to 6.
