Accessing a Service through Gateway¶
This article demonstrates how to integrate a microservice with DCE 5.0 Cloud Native Gateway and access the service through the gateway.
Prerequisite¶
- Prepare a service. In this article, we use the
my-otel-demo-adservice
service deployed in thewebstore-demo
namespace of theskoala-dev
cluster. - Accessing
/
of themy-otel-demo-adservice
service should theoretically returnadservice-springcloud: hello world!
.
Integrate Service with Gateway¶
DCE 5.0 Cloud Native Gateway supports two methods for importing services: manual integration and automatic discovery. Choose one according to your situation.
Automatic Discovery of Services¶
-
Refer to the documentation Creating a Gateway to create a gateway. Add the namespace where the service is located as the jurisdictional namespace of the gateway.
-
After the namespace where the service is located is added as a "jurisdictional namespace", all services under that namespace will be automatically integrated with the gateway without the need for manual intervention.
-
Refer to Adding Domain Names to create a domain name under the gateway, such as
adservice.virtualhost
. -
Refer to Adding APIs to create an API under the gateway. Add the service as the backend service of the API.
When adding a backend service, select the target service from the "auto-discovered" services, and click OK .
Manual Integration of Services¶
- Refer to Creating a Gateway to create a gateway.
-
Refer to the document Manual Integration to integrate the service with the gateway.
-
Refer to Adding Domain Names to create a domain name under the gateway, such as
adservice.virtualhost
. -
Refer to Adding APIs to create an API under the gateway. Add the service as the backend service of the API.
When adding a backend service, select the target service from the "manually integrated" services, and click OK .
Obtain Gateway Address¶
-
Log in to the control node of the cluster where the gateway is located, and use the command
kubectl get po -n $Namespace
to view the node where the gateway is located. The Pod starting withenvoy
is the data plane of the gateway. You can find out its location based on this Pod. -
Use the
ping
command to communicate with the node where the gateway is located, and obtain the IP address of that node based on the returned data.In this demo, the IP address of the node where the gateway is located is
10.6.222.24
. -
Use the
kubectl get svc -n $Namespace
command to view the port exposed by the gateway.The Service corresponding to the gateway starts with
envoy
and ends withgtw
. In this demo, the port of the gateway Service is30040
. -
Based on the above information, the access address of the gateway is
10.6.222.24:30040
.
Configure Local Domain¶
Use the command vim /etc/hosts
to modify the local hosts file and configure a local domain name for the gateway access address.
Accessing Services¶
After configuring the local domain name, you can use the domain name to access the gateway service through external and internal networks. You should now be able to access the root path of the service and receive the "hello world" content.
External Access¶
In this demo, you can use curl adservice.virtualhost:30040/
.
Internal Access¶
You can access the adservice
service through the gateway from any node in the cluster where the gateway is located.
In this demo, there are three worker nodes in the gateway cluster named dev-worker1
, dev-worker2
, and dev-worker3
. On these three nodes, you can use their internal