When your services experience traffic spikes --- such as e-commerce promotions or online education surges --- fixed gateway resources may be insufficient or wasteful during off-peak hours. If your ASM gateways run inside ACK clusters, a cluster failure can also take down the gateway and disrupt ingress traffic.
ASM serverless gateways solve both problems. They run outside your Container Service for Kubernetes (ACK) clusters in infrastructure fully managed by Service Mesh (ASM). ASM handles provisioning, scaling, and lifecycle management automatically. You do not manage gateway pods, and gateway availability does not depend on ACK clusters.
How it works
A serverless gateway is an IstioGateway custom resource with the annotation asm.alibabacloud.com/managed-by-asm: 'true'. Unlike standard ASM gateways that run as pods inside ACK clusters, ASM provisions serverless gateways in its own managed infrastructure. You do not specify an ACK cluster ID when creating the gateway.
Traffic flows from clients through the serverless gateway to backend services in your ACK clusters:
Client --> Serverless gateway (managed by ASM) --> Backend services (ACK clusters)Prerequisites
Before you begin, make sure that you have:
An ASM instance running version 1.18.0.147 or later
Create a serverless ingress gateway
Apply a YAML definition in the ASM console to create a serverless ingress gateway. The only difference from a standard ASM gateway is the asm.alibabacloud.com/managed-by-asm: 'true' annotation --- you do not specify an ACK cluster ID.
Log on to the ASM console. In the left-side navigation pane, choose Service Mesh > Mesh Management.
On the Mesh Management page, click the name of your ASM instance. In the left-side navigation pane, choose ASM Gateways > Ingress Gateway.
On the Ingress Gateway page, click Create from YAML, enter a name for the gateway, paste the following YAML, and click Create.
apiVersion: istio.alibabacloud.com/v1beta1 kind: IstioGateway metadata: annotations: asm.alibabacloud.com/managed-by-asm: 'true' # Optional: export gateway metrics to a specific ACK cluster asm.alibabacloud.com/export-metrics: '<ack-cluster-id>' name: ingressgateway namespace: istio-system spec: gatewayType: ingress dnsPolicy: ClusterFirst externalTrafficPolicy: Local hostNetwork: false ports: - name: http port: 80 protocol: TCP targetPort: 80 - name: https port: 443 protocol: TCP targetPort: 443 replicaCount: 1 resources: limits: cpu: '2' memory: 2G requests: cpu: 200m memory: 256Mi rollingMaxSurge: 100% rollingMaxUnavailable: 25% runAsRoot: true serviceType: LoadBalancerReplace the following placeholder with your actual value:
Placeholder Description Example <ack-cluster-id>ID of the ACK cluster to receive gateway metrics. This annotation is optional. c1a2b3c4d5e6f7g8h9i0j**** Note The serverless gateway supports bothLoadBalancerandClusterIPservice types. If you setserviceTypetoClusterIP, the client and gateway pods must be able to reach each other --- for example, pods in the same virtual private cloud (VPC) connected through the Terway network plugin.
Verify the gateway
After the gateway is created, it appears on the Ingress Gateway page with a status of Running. Note the external IP address assigned to the gateway --- you need it to access backend services.
Configure traffic routing
To direct traffic through the serverless gateway, create an HTTP domain, import a backend service, and define a routing rule.
Create an HTTP domain
On the Ingress Gateway page, click the gateway name. In the left-side navigation pane, click Domain/Certificate. On the Domain tab, click Create.
Configure the domain with the following settings and click Create.
Parameter Value Domain Name * Protocol HTTP Port Name http Port 80
Import the backend service
In the left-side navigation pane on the gateway overview page, click Upstream Service. Click Import service.
Select default from the Namespace drop-down list, select productpage in the service list, click the add icon to move it to the selected section, and click Submit.
Create a routing rule
In the left-side navigation pane, click Route management. Click Create.
In the set route detail step, configure the following settings and click Next.
Parameter Value route type http Namespace default Name productpage Method (under Matching Rule) Prefix Content (under Matching Rule) / In the set route destination step, set select upstream service to productpage and click Next.
In the advanced config step, click Create.
Verify traffic routing
Open a browser and go to http://<gateway-ip>/productpage, replacing <gateway-ip> with the external IP address of your serverless gateway.
To find the gateway IP address, see Obtain the IP address of the ingress gateway.
The productpage of the Bookinfo sample application loads in your browser. If you get a connection timeout, confirm that the gateway status is Running and the routing rule is configured correctly.
Configure HTTPS access
Generate a TLS certificate, upload it to ASM, and create an HTTPS domain on the gateway.
Generate a CA certificate
Run the following commands to generate a self-signed certificate:
# Generate the root CA key and certificate
openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 \
-subj '/O=myexample Inc./CN=aliyun.com' \
-keyout aliyun.root.key -out aliyun.root.crt
# Generate a certificate signing request (CSR) and private key
openssl req -out aliyun.com.csr -newkey rsa:2048 -nodes \
-keyout aliyun.com.key \
-subj "/CN=aliyun.com/O=myexample organization"
# Sign the certificate with the root CA
openssl x509 -req -days 365 -CA aliyun.root.crt -CAkey aliyun.root.key \
-set_serial 0 -in aliyun.com.csr -out aliyun.com.crtUpload the certificate
In the left-side navigation pane of the ASM instance, choose ASM Gateways > Certificate Management.
On the Certificate Management page, click Create. In the Certificate Information panel, configure the following parameters and click OK.
Parameter Description Name Enter a certificate name, for example, myexample-credentialPublic Key Certificate Paste the content of the aliyun.com.crtfilePrivate Key Paste the content of the aliyun.com.keyfile
Create an HTTPS domain
In the left-side navigation pane, click Ingress Gateway. Click the gateway name, then click Domain/Certificate. On the Domain tab, click Create.
Configure the domain with the following settings and click Create.
Parameter Value Domain Name * Protocol HTTPS Port Name https Port 443 credential myexample-credential TLS mode Secure connections with standard TLS semantics
Verify HTTPS access
Run the following curl command to verify HTTPS access:
curl -k -I -H "Host:aliyun.com" \
--resolve "aliyun.com:443:<gateway-ip>" \
https://aliyun.com/productpageReplace <gateway-ip> with the external IP address of your serverless gateway. A successful response returns HTTP status 200:
HTTP/1.1 200 OK
server: istio-envoyIf the request fails, confirm that the certificate name matches the credential value in the HTTPS domain configuration.
Collect access logs
Collect gateway access logs to Simple Log Service (SLS) for traffic analysis and troubleshooting.
Enabling access log collection restarts the gateway. Perform this operation during off-peak hours.
Add the log collection annotation
Log on to the ASM console. Navigate to Service Mesh > Mesh Management, and click your ASM instance name.
In the left-side navigation pane, choose ASM Gateways > Ingress Gateway.
On the Ingress Gateway page, find the serverless gateway and click YAML. Add the following annotation to the gateway YAML and click OK.
asm.alibabacloud.com/aliyun-logs-project: k8s-log-****Replace
k8s-log-****with the SLS project name for your mesh logs (for example,mesh-log-c4e1bbed247634d0482000d94e947****).The updated YAML looks like this:
View access logs
Log on to the Simple Log Service console.
In the Projects section, click the log project name you configured in the previous step.
In the left-side navigation pane, click the Log Storage icon. In the Logstores section, click mesh-ingress-log.
Enter a search query (for example,
productpage) in the search box and click Search & Analyze. The access logs for matching requests appear in the results.
Export gateway metrics
Export serverless gateway metrics to Managed Service for Prometheus for monitoring and alerting. This requires ASM version 1.18.0.147 or later.
Enable metrics collection in ASM
Enable metrics generation and collection for your ASM instance. Confirm that the metrics dashboard is accessible under Observability Management Center > Monitoring indicators. For details, see Collect metrics to Managed Service for Prometheus.
Add the metrics export annotation
In the serverless gateway YAML, add the following annotation:
asm.alibabacloud.com/export-metrics: '<ack-cluster-id>'Replace <ack-cluster-id> with the ID of the ACK cluster where you want to export metrics. This synchronizes the gateway's services and endpoints to the specified ACK cluster, making them available for Prometheus to scrape.
Configure Prometheus scrape targets
Log on to the ARMS console.
In the left-side navigation pane, choose Managed Service for Prometheus > Instances. Select the region of your Prometheus instance.
Click the Prometheus instance name. In the left-side navigation pane, click Settings.
On the Settings page, click Edit Prometheus.yaml. Add the following scrape configuration and click Save.
This configuration scrapes Istio service mesh metrics from the serverless gateway's Envoy proxy endpoint every 30 seconds. The relabel_configs filters target only gateway-synced endpoints, and the metric_relabel_configs drops low-level Envoy-internal metrics to reduce noise.
Troubleshooting
Cannot access a backend application through the serverless gateway
If requests to the serverless gateway fail or return errors, check the following:
1. Security group rules
The security group of the data-plane ACK cluster must allow inbound traffic from the serverless gateway's network range. To verify:
Find the vSwitch CIDR block of your ASM instance:
In the ASM console, navigate to Service Mesh > Mesh Management and click your instance name.
Choose ASM Instance > Base Information and click the link next to vSwitch to view the CIDR block.
Check the security group of the ACK cluster:
In the ACK console, click Clusters and then click the cluster name.
Click Cluster Information, then the Cluster Resources tab, and click the link next to Security Group.
Verify that the inbound rules allow traffic from the ASM vSwitch CIDR block to the backend application pod port.
2. HTTP error codes
| Error code | Possible cause | Action |
|---|---|---|
| 404 | Routing rule misconfigured or missing | Verify the routing rule matches the request path and the upstream service is imported correctly |
| 503 | Backend application unavailable | Check that the backend pods are running and healthy in the ACK cluster |
What's next
Route traffic to different versions of a service --- Implement canary deployments with Istio traffic management
Collect metrics to Managed Service for Prometheus --- Set up full observability for your service mesh
Update an ASM instance --- Keep your ASM instance on the latest version