This tutorial shows you how to expose an application running in Container Service for Kubernetes (ACK) to the internet. You will learn how to create an HTTP API and configure a route in Cloud-native API Gateway to allow external access to your microservice.
Prerequisites
-
You have created a container cluster. For more information, see Create an ACK managed cluster or Create an ACK Swarm cluster.
-
You have deployed a sample microservice to your ACK cluster.
Solution overview
This solution involves creating a Cloud-native API Gateway instance and associating it with your ACK cluster. You will then configure routes in the gateway to direct traffic to your containerized application, allowing clients to access it through the API gateway.
-
Create a Cloud-native API Gateway instance.
Create a Cloud-native API Gateway instance based on your existing microservice environment.
-
Create an HTTP API.
-
Add and publish a route for the service.
-
Create a service source.
Add a service source in Cloud-native API Gateway and select ACK as the source type.
-
Add a service.
Cloud-native API Gateway can retrieve the namespace of the service from the ACK source and add the existing service as a backend service.
-
-
Test the route for the microservice.
Step 1: Create a Cloud-native API Gateway instance
-
Log on to the Cloud-native API Gateway console. If you are using Cloud-native API Gateway for the first time, perform the following steps:
NoteThe first time you access Cloud-native API Gateway, the system prompts you to authorize it to create a service-linked role.
-
Click Authorize Now. In the dialog box that appears, click OK.
-
Click Experience Cloud-native API Gateway Now to go to the console.
-
-
In the navigation pane on the left, choose Instance. In the top menu bar, select a region, and then click Create Instance.
ImportantThe Cloud-native API Gateway instance must be in the same region as your ACK cluster.
-
On the Cloud-native API Gateway buy page, configure the parameters for your instance, and then click Buy Now.
Configure key parameters, including Region, Gateway Name, Gateway Specification, VPC, and VSwitch.
-
On the Confirm Order page, select the I have read and agree to the Cloud-native API Gateway (Pay-As-You-Go) Terms of Service checkbox, and then click Activate Now.
NoteInstance creation may take 2 to 3 minutes.
-
Click Management Console and return to the Instance page to view the information and status of the gateway.
The gateway is created successfully if its Status is Running.
Step 2: Create an HTTP API
-
In the navigation pane on the left, choose APIs and click Create API.
-
On the HTTP API card, click Create. In the Create HTTP API panel, enter an API Name and click Create.
Step 3: Create a route
-
In the navigation pane on the left, navigate to the APIs page and click the name of your API.
Click Create Route. In the Create Route panel, configure the parameters.
Basic route information
On the Basic Information & Match Rules page, set Route Name to httpbin-demo. Select httpbin.com for Domain. For the Path, select Prefix as the matching method, enter / for the path, and select the Case Sensitive checkbox.
-
Domain: You can click Add Domain on the right to create a domain name in the Add Domain panel.
-
Path: Matches HTTP requests where the path starts with
/.
Instance and backend service
When you create a gateway instance, a default environment is automatically created and associated with the instance.
-
From the Instance drop-down list, select the instance that you created in Step 1.
In the Backend Service section, configure the Service Name, Service Port, and Protocol.
-
Scenarios: From the Scenario list, select Single Service.
-
In the Backend Services section, click Associated Service from the Service Name drop-down list.
-
Create a service source and a service.
-
For Source Type, select ACK.
-
Click Add Source and select the cluster that you created in the Prerequisites section.
-
From the Services, select the
httpbinservice and click OK. -
In the Backend Services section, select the httpbin service that you added from the Service Name drop-down list.
-
-
Click Save and Publish.
Step 4: Debug the route
-
In the navigation pane on the left, navigate to the APIs page and click the name of your API.
-
In the route list, find the
httpbin-demoroute and click Debug in the Actions column. -
Enter version as the request parameter and click Send to view the service response.
The response includes
version: v1andhostname: httpbin-xxx, where xxx is the suffix of the actual Pod name.
Related documents
-
To learn how to manage multiple ACK clusters, see Use Cloud-native API Gateway to manage multiple ACK clusters.
-
If you encounter issues when you use Cloud-native API Gateway, see FAQ.