Manage Services in Multi-Environments Using Gateway Group
Gateway groups are a logical grouping of one or more gateway instances that share the same configuration and behave consistently when handling API requests. Users can name the gateway groups and add labels to them to differentiate and manage different environments and clusters.
API7 Enterprise supports two types of gateway group management: API7 Gateway
and Ingress Controller
. This helps enterprises achieve environment and cluster isolation, multi-region and multi-cluster management, as well as service-level objective management based on projects.
This guide will show you how to manage service across the Test
, UAT
, and Production
environments using gateway groups.
Background
To ensure service stability, compliance, and data security, the service goes through multiple environments, including test, UAT, and production environments. Without this feature, developers should deploy three sets of API7 Enterprise and log in to the dashboard under different domains to develop, test, and deploy the same API. In the case of many business projects, this process will waste a lot of machine and management resources.
The gateway group feature of the API7 Enterprise provides developers with a unified entry point. It avoids switching between multiple dashboards, and enables simple and convenient deployment operations, thereby improving work efficiency and reducing operational errors.
Prerequisites
- Install API7 Enterprise.
- Prepare different domain names for the service in the three environments:
test.acme.com
,uat.acme.com
, andprod.acme.com
. - Refer to adding a gateway group, and create three gateway groups:
Test
,UAT
, andProduction
.
Create Service and Route in the Test Environment
Strict version control is not required in the test environment due to frequent changes. Only the final stable configuration will be synchronized to higher environments and marked as an official version. Only official versions can be rolled back and traced.
- Select Published Services under the
Test
gateway group from the side navigation bar and then click Add Service. - Select Add Manually.
- In the dialog box, do the following:
- In the Name field of Service Basics, enter
httpbin
. - In the Service Type field, choose
HTTP(Layer 7 protocol)
. - In the Name field of Upstream Basics, enter
default
. - Click + Add Node.
- In the dialog box, do the following:
- In the Host field, enter
test.api7.org
. - In the Port field, enter
80
. - Click Add.
- In the Host field, enter
- In the Upstream Scheme field, choose
HTTP
. - (Optional) Click View More Connection Configuration.
- (Optional) In the The host HTTP header passed to upstream field, choose
Specified in the Upstream's Host
. - In the Hosts field of Request URL, enter
test.acme.com
. - Turn on the Add First Route switch, then do the following:
- In the Name field, enter
get-headers
. - In the Path field, enter
headers
. - In the Methods field, choose
GET
.
- In the Name field, enter
- Click Add.
- In the Name field of Service Basics, enter
- A new service
httpbin
in the 'No Version' state is created.
Note: In this test case, the The host HTTP header passed to upstream parameter must be changed to
Specified in the Upstream's Host
to ensure a successful handshake with the demo upstream. Adjust accordingly per your use case.
- Simulate real user scenarios to perform functional testing, performance testing, and security testing.
Validate the Service
After testing, send a request to validate the httpbin service in the test gateway group.
curl "http://localhost:9080/headers" -v -H "Host: test.acme.com"
You will receive a 200 OK
response.
Deploy Services to the UAT Environment
Version numbers serve as unique identifiers across all gateway groups. Using the synchronization process instead of manually copying configurations to critical environments provides a more convenient way to track versions, prevent accidental modifications, and ensure thorough testing before UAT and production.
- Select Published Services under the
Test
gateway group from the side navigation bar. - Click ... button on the page header, then click Sync to Other Gateway Group.
- From the dialog box, do the following:
- In the Gateway Group field, choose
UAT
. - In the Version field, enter
1.0.0
. - Click Sync.
- After synchronization, you will be redirected to the published service
httpbin 1.0.0
on theUAT
gateway group. - Select Routes from the side navigation bar.
- In the Request URL field, click the edit button.
- From the dialog box, do the following:
- In the Hosts field, click Add, then enter
uat.acme.com
. - Click Save.
- Select Upstreams from the side navigation bar.
- Click Add Node.
- From the dialog box, do the following:
- In the Host and Port fields, enter
uat.api7.org
as the host and80
as the port. - In the Weight field, use the default value
100
. - Click Add.
- (Optional) In the Connection Configuration module, click the Edit icon.
- (Optional) From the dialog box, do the following:
- In the The host HTTP header passed to upstream field, choose
Specified in the Upstream's Host
. - Click Save.
Note: In this test case, the The host HTTP header passed to upstream parameter must be changed to
Specified in the Upstream's Host
to ensure a successful handshake with the demo upstream. Adjust accordingly per your use case.
- (Optional) In the
UAT
gateway group, configure the gateway group's security policies and compliance check functions, such as conducting log auditing.
Validate the Service
After testing, send a request to validate the httpbin service in the test gateway group.
curl "http://localhost:9080/headers" -v -H "Host: uat.acme.com"
You will receive a 200 OK
response.
Deploy Services to the Production Environment
- Select Published Services under the
UAT
gateway group from the side navigation bar. - Click ... besides the
httpbin
service, then click Sync to Other Gateway Group. - From the dialog box, do the following:
- In the Gateway Group field, choose
Production
. - In the Version field, enter
1.0.0
. - Click Sync.
- After synchronization, you will be redirected to the published service
httpbin 1.0.0
on theProduction
gateway group. - Select Routes from the side navigation bar.
- In the Request URL field, click the edit button.
- From the dialog box, do the following:
- In the Hosts field, click Add, then enter
production.acme.com
. - Click Save.
- Select Upstreams from the side navigation bar.
- Click Add Node.
- From the dialog box, do the following:
- In the Host and Port fields, enter
prod.api7.org
as the host and80
as the port. - In the Weight field, use the default value
100
. - Click Add.
- (Optional) In the Connection Configuration module, click the Edit icon.
- (Optional) In the Edit Connection Configuration dialog box, do the following:
- In the The host HTTP header passed to upstream field, choose
Specified in the Upstream's Host
. - Click Save.
- In the The host HTTP header passed to upstream field, choose
Note: In this test case, the The host HTTP header passed to upstream parameter must be changed to
Specified in the Upstream's Host
to ensure a successful handshake with the demo upstream. Adjust accordingly per your use case.
- Regularly review and analyze the logs of the
httpbin
, perform log management, and identify potential issues for improvement. - Develop a detailed rollback plan, including rollback steps, required time, and responsible personnel, and roll back the published services when necessary.
Validate the Service
After testing, send a request to validate the httpbin service in the test gateway group.
curl "http://localhost:9080/headers" -v -H "Host: production.acme.com"
You will receive a 200 OK
response.
Conclusion
Test, UAT, and production environments are essential components of the software development lifecycle. By leveraging gateway groups of API7 Enterprise, you can achieve physical and logical isolation, enhancing security, controllability, and efficiency. Additionally, the ability to adjust route rules and manage service versions flexibly ensures smooth and agile version management of your applications.
Additional Resources
- Key Concepts
- Best Practices