ApigConfig is a Custom Resource Definition (CRD) provided by the APIG Controller. You can use ApigConfig to manage the lifecycle of APIG gateway instances, configure Ingress listener options, and set global configurations. ApigConfig also lets you implement instance-level global IP access control using blacklists and whitelists, log collection, and Tracing Analysis.
ApigConfig description
Configuration description
ApigConfig is a CRD that the APIG Controller uses to manage the lifecycle and global configurations of APIG gateway instances.
One ApigConfig corresponds to one APIG gateway instance. To use multiple APIG gateway instances, you must create multiple ApigConfigs.
Except in reuse scenarios, deleting an ApigConfig will cascade delete the corresponding APIG gateway instance.
The following sample code shows a complete ApigConfig configuration.
apiVersion: apig.alibabacloud.com/v1alpha1
kind: ApigConfig
metadata:
name: apig-ingress
spec:
name: apig-ingress
common:
pay:
payType: POSTPAY
instance:
spec: apigw.small.x1
network:
vSwitches:
- "vsw-1"
- "vsw-2"
networkType: Internet
securityGroupType: enterprise
global:
tls:
enableHardwareAcceleration: true
ipAccessControl:
whitelist:
- 1.1.XX.XX
- 2.2.XX.XX
monitor:
logging:
sls:
reuseProject: "xxx" # An empty value indicates that the default project is used.
tracing:
openTelemetry:
sampleRate: "100"
ingress:
local:
ingressClass: apig
watchNamespace: "" # "" indicates Ingress resources in all namespaces.Parameter | Description | Default value |
| The name of the gateway. | apig-ingress |
| The billing method. Currently, only pay-as-you-go is supported. If you do not configure this parameter, pay-as-you-go is used by default. | POSTPAY |
| The instance type of the gateway. Valid values:
| apigw.small.x1 |
| The primary and secondary vSwitches. The primary vSwitch is listed first, followed by the secondary one. Specify at least one and at most two vSwitches. If you leave this empty, the vSwitches are obtained from the node where the Controller pod runs. | None |
| The type of the Internet-facing SLB instance that is purchased for the gateway. Valid values:
| Internet |
| The type of the security group. Valid values:
| normal |
| Enables or disables TLS hardware acceleration. Enabling this feature can significantly improve the performance of HTTPS traffic. | Enabled |
| The global IP whitelist for access control. | Not configured |
| The global IP blacklist for access control. | Not configured |
| Enables or disables Simple Log Service (SLS). To enable this feature, grant the Controller the required SLS permissions. | shutdown |
| The destination project in SLS to which access logs are delivered. Valid values:
| Empty |
| Sample rate for OpenTelemetry Tracing Analysis | 0 |
| Enables or disables OpenTelemetry Tracing Analysis. | This option is disabled by default and is mutually exclusive with OpenTelemetry. |
| The sample rate for OpenTelemetry Tracing Analysis. | 100 |
| The Ingress resources under a specific IngressClass in the cluster that the APIG gateway listens to. Valid values:
Note This configuration has a lower priority than associating ApigConfig through an IngressClass resource. | Not configured |
| The namespaces in the cluster whose Ingress resources the APIG gateway listens to. Valid values:
| Empty |
Status description
After you create an ApigConfig resource, you can run the kubectl get ApigConfig command to view its status. The status of ApigConfig changes in the following order: Pending > Running > Listening. The statuses are described as follows:
Pending: The APIG gateway is being created. This process takes about 3 minutes.Running: The APIG gateway is created and running.Listening: The APIG gateway is running and listening for Ingress resources in the cluster.Failed: The APIG gateway is in an invalid state. For more information, see the message in the Status field.
Tag description
APIG gateway instances that are created or reused through ApigConfig are assigned resource tags. You can view the tags of the target gateway in the basic information section of the APIG console.
Do not edit the tags in the following table from the APIG gateway console. This action can affect your gateway instance.
Tag name | Description |
ack.aliyun.com | Manages the inbound traffic of the container service cluster for the APIG gateway. |
ingress.k8s.alibaba/ApigConfig | Associates the APIG gateway with ApigConfig. |
kubernetes.reused.by.user | Indicates whether the APIG gateway is reused. If it is a reuse scenario, the APIG gateway instance is not deleted when the associated ApigConfig is deleted. |
Create an APIG gateway instance
Configure ApigConfig.
The following sample code creates an APIG gateway instance named apig-ingress with the instance type `apigw.small.x1`. You can modify other ApigConfig settings as needed.
apiVersion: apig.alibabacloud.com/v1alpha1 kind: ApigConfig metadata: name: apig-ingress spec: name: apig-ingress common: instance: spec: apigw.small.x1Create an IngressClass resource in the container service cluster and associate it with ApigConfig through spec.parameters to declare an Ingress processor in the cluster.
After you complete the configuration, Ingress resources in the cluster that are associated with this IngressClass are processed by the APIG gateway instance that is associated with the ApigConfig.
apiVersion: networking.k8s.io/v1 kind: IngressClass metadata: name: apig spec: controller: apig.alibabacloud.com/ingress parameters: apiGroup: apig.alibabacloud.com kind: ApigConfig name: apig-ingress
Reuse an existing APIG gateway instance
To reuse an existing APIG gateway instance, specify the unique ID of the APIG gateway instance (in the gw-xxx format) in spec.id when you create the ApigConfig. Use the spec.override parameter to control whether to overwrite the configurations of the reused APIG gateway instance with the settings from the ApigConfig.
The following sample code reuses an existing APIG gateway instance through ApigConfig. It associates the gateway instance with a container cluster and sets it to listen for Ingress resources in the cluster that have an ingressClass of apig.
In the following configuration,
spec.overrideis set tofalse. This setting prevents the existing Ingress listener options and global configurations of the APIG gateway from being overwritten. If the gateway instance is not already associated with the container cluster, it is automatically associated. The Ingress listener is then configured to listen for Ingress resources in the cluster whose ingressClass matches the value ofspec.ingress.local.ingressClass, which is apig in this example. If the gateway instance is already associated with the container cluster, its original Ingress listener options are retained.To overwrite the existing Ingress listener options and global configurations of the APIG gateway, you must first ensure that all required gateway parameters, such as Ingress listener options, hardware acceleration, global blacklists and whitelists, and observability, are correctly configured in your ApigConfig. Then, set
spec.overrideto `true`. If you setspec.overrideto `true` without specifying these configurations in the ApigConfig, the original gateway parameters are overwritten, which may negatively affect traffic.
apiVersion: apig.alibabacloud.com/v1alpha1
kind: ApigConfig
metadata:
name: reuse
spec:
id: gw-xxxx
override: false
ingress:
local:
ingressClass: apigParameter | Description |
| The ID of the target APIG gateway instance to reuse. The format is `gw-xxx`. |
| Specifies whether to overwrite the configurations of the reused APIG gateway instance based on the ApigConfig.
|
Delete an APIG gateway instance
One ApigConfig corresponds to one APIG gateway instance. Except in reuse scenarios, deleting an ApigConfig will cascade delete the corresponding APIG gateway instance.
The deletion policies are shown in the following table.
Gateway billing method | Automatic creation by APIG Controller | Reuse of a gateway purchased in the console |
Pay-as-you-go | Delete the ApigConfig to automatically delete the gateway instance. | Delete the ApigConfig, but the gateway instance is retained. |
Run the following command to delete the ApigConfig.
kubectl delete ApigConfig your-config-nameConfigure global, instance-level IP access control
Configure an IP whitelist
You can configure a global, instance-level IP whitelist to allow only specific source IPs to access the APIG Ingress.
The following sample code configures the APIG Ingress gateway instance to allow access only from the source IP address 1.1.XX.XX or the CIDR block 2.0.XX.XX/8.
apiVersion: apig.alibabacloud.com/v1alpha1
kind: ApigConfig
metadata:
name: apig-ingress
spec:
...
global:
ipAccessControl:
whitelist:
- 1.1.XX.XX
- 2.0.XX.XX/8
...Configure an IP blacklist
You can configure a global, instance-level IP blacklist to deny access from specific source IPs to the APIG Ingress.
The following sample code configures the APIG Ingress gateway instance to deny access from the source IP address 1.1.XX.XX or the CIDR block 2.0.XX.XX/8.
apiVersion: apig.alibabacloud.com/v1alpha1
kind: ApigConfig
metadata:
name: apig-ingress
spec:
...
global:
ipAccessControl:
blacklist:
- 1.1.XX.XX
- 2.0.XX.XX/8
...Enable SLS logs
Before you enable SLS logs, make sure you have granted the required SLS permissions to the APIG Controller.
The following sample code configures the APIG Ingress gateway to deliver access logs to a project named demo.
apiVersion: apig.alibabacloud.com/v1alpha1
kind: ApigConfig
metadata:
name: apig-ingress
spec:
...
monitor:
logging:
sls:
# Configure reuseProject to enable SLS. To use the default project, leave this empty.
reuseProject: "demo"
...Enable OpenTelemetry Tracing Analysis
After you configure Alibaba Cloud OpenTelemetry Tracing Analysis for the gateway, you can build an end-to-end tracing and monitoring system to quickly diagnose and locate online issues.
The following sample code configures OpenTelemetry Tracing Analysis for the APIG Ingress gateway with a sample rate (sampleRate) of 100%.
apiVersion: apig.alibabacloud.com/v1alpha1
kind: ApigConfig
metadata:
name: apig-ingress
spec:
...
monitor:
tracing:
openTelemetry:
sampleRate: "100"
...More configurations
The gateway instance used by APIG Ingress supports additional configurations.
To apply these configurations, log on to the Cloud-native API Gateway console. In the menu, find the gateway instance used or automatically created by the APIG Controller. Click the instance ID, and click Parameter Settings in the navigation pane on the left.
Configuration item | Type | Description |
| Bool | Applies to the request scope. Generates a request ID in the request header for request tracing. |
| Bool | Applies to the request and response stages. Enabling gzip compresses requests and responses. This reduces gateway traffic but increases gateway CPU consumption. |
| Bool | Specifies whether to merge redundant |
| Int | Applies to gateway connections. The buffer size for a single connection. This setting affects throughput and gateway memory usage. Value range: [0, 2147483647]. |
| Int | Applies to the request stage. The number of trusted proxies in front of the gateway. This affects whether the gateway uses client-generated request headers such as Value range: [0, 10]. Unit: proxies. |
| Int | Applies to the request stage. The maximum number of concurrent streams on a single connection when the client uses HTTP/2. Value range: [0, 2147483647]. Unit: byte. |
| Int | Applies to the request stage. The initial Value range: [65535, 2147483647]. Unit: byte. |
| Int | Applies to the request stage. The initial connection-level window size when the gateway and client use HTTP/2. Value range: [65535, 2147483647]. Unit: byte. |
| Bool | Specifies whether to support the HTTP/3 protocol. HTTP/3 is not compatible with the hardware acceleration feature. Disable hardware acceleration before you enable HTTP/3 support. |
| String | Determines the action for requests whose URI paths contain escaped characters such as %2F, %2f, %5C, or %5c. The default value is Valid values: |
| List<String> | The compression algorithm that is used after compression is enabled. If Valid values: |
| Bool | Specifies whether to enable the PROXY protocol. If the gateway's inbound traffic is accessed through an NLB, you must enable this to obtain the originating IP address of the client. Enabling this does not affect non-PROXY protocol requests. |
| Bool | Applies to scenarios where a self-built authorization service is used. When enabled, changes to authorization rules do not cause connection interruptions. This is suitable for WebSocket and online business scenarios. |
| Int | Generates a Keep-Alive response header to inform the client about the connection keepalive time. For example, if set to 10, the response header Value range: [0, 600]. Unit: s. |
| Int | The keepalive time maintained for WebSocket connections when the gateway instance needs to close connections, such as during an upgrade or restart. Value range: [20, 900]. Unit: s. |
EnableGzipHardwareAccelerate | Bool | Performs Gzip compression based on dedicated hardware. When enabled, it compresses requests and responses, significantly reducing gateway traffic. It offers higher performance and lower CPU consumption compared to software-based Gzip. This feature cannot be enabled in unsupported regions or if Gzip hardware acceleration was not specified at the time of purchase. After this is enabled, |
EnableK8sSourceWorkloadFilter | Bool | Filters Ingress, Service, and pod resources based on specified tags when adding a service source. Inverse filtering is supported. |