All Products
Search
Document Center

Alibaba Cloud Service Mesh:Configure settings to allow traffic to bypass sidecar proxies

Last Updated:Aug 28, 2024

A sidecar proxy is used to improve the network security, reliability, and observability of service calls. However, in scenarios where traffic is not required to pass through sidecar proxies, you can configure settings by using different methods to allow traffic to bypass sidecar proxies. This topic describes how to configure settings to allow inbound and outbound traffic or the traffic forwarded to a specific CIDR block to bypass sidecar proxies.

Prerequisites

Configure settings to allow inbound and outbound traffic to bypass sidecar proxies

In some scenarios, high performance is required, and the security authentication such as mutual transport layer security (mTLS) authentication and tracing analysis features provided by Service Mesh (ASM) are unnecessary. In such scenarios, you can specify whether to allow the inbound and outbound traffic to bypass sidecar proxies. In this example, settings are configured to allow the inbound traffic over ports 7001, 7002, and 7005 to bypass sidecar proxies, and the outbound traffic to pass through sidecar proxies. This way, the specific inbound traffic can bypass the sidecar proxy. This reduces the resources required by the istio-proxy sidecar proxy and improves overall performance. The outbound traffic is required to pass through the sidecar proxy. Therefore, you can use the capabilities such as load balancing of ASM.

为命名空间级别配置Sidecar拦截策略

Method 1: Configure a blocking policy for sidecar proxies in the ASM console

In this example, the default namespace is used. You can configure a blocking policy for sidecar proxies in the default namespace by specifying the following parameters: Ports on Which Outbound Traffic Redirected to Sidecar Proxy and Ports on Which Inbound Traffic Not Redirected to Sidecar Proxy.

  1. Log on to the ASM console.

  2. In the left-side navigation pane, choose Service Mesh > Mesh Management.

  3. On the Mesh Management page, find the ASM instance that you want to configure. Click the name of the ASM instance or click Manage in the Actions column.

  4. On the details page of the ASM instance, choose Data Plane Component Management > Sidecar Proxy Setting in the left-side navigation pane.

  5. On the Sidecar Proxy Setting page, click the Namespace tab.

  6. Select default from the Namespace drop-down list, click the Istio代理 icon on the left side of Enable/Disable Sidecar Proxy by Ports or IP Addresses, select and configure the parameters described in the following table, and then click Update Settings.

    Parameter

    Description

    Ports on Which Outbound Traffic Redirected to Sidecar Proxy

    The ports over which you want the outbound traffic to pass through sidecar proxies. In this example, set this parameter to 7001,7002,7005.

    Ports on Which Inbound Traffic Not Redirected to Sidecar Proxy

    The ports over which you want the outbound traffic to pass through sidecar proxies. In this example, set this parameter to 7001,7002,7005.

  7. Restart a pod for the settings of sidecar proxies to take effect.

    1. Log on to the ACK console.

    2. In the left-side navigation pane of the ACK console, click Clusters.

    3. On the Clusters page, find the cluster that you want to manage and click the name of the cluster or click Details in the Actions column. The details page of the cluster appears.

    4. In the left-side navigation pane of the details page, choose Workloads > Pods.

    5. On the Pods page, find the pod that you want to delete and choose More > Delete in the Actions column.

    6. In the dialog box that appears, click OK.

      Wait until the pod restarts. The settings take effect after the pod restarts.

Method 2: Configure a blocking policy for sidecar proxies in the ACK console

A Deployment is used in this example. Annotations are added to the YAML file of a pod to configure a blocking policy for sidecar proxies. For more information, see Configure a sidecar proxy by adding resource annotations.

  1. Log on to the ACK console.

  2. In the left-side navigation pane of the ACK console, click Clusters.

  3. On the Clusters page, find the cluster that you want to manage and click the name of the cluster or click Details in the Actions column. The details page of the cluster appears.

  4. In the left-side navigation pane of the details page, choose Workloads > Deployments.

  5. On the Deployments page, find the application that you want to manage and click Details in the Actions column.

  6. In the upper-right corner of the application details page, click View in YAML.

  7. In the Edit YAML dialog box, add the following content to the spec.template.metadata parameter and click Update.

    annotations:
      traffic.sidecar.istio.io/excludeInboundPorts: '7001,7002,7005'
      traffic.sidecar.istio.io/includeOutboundPorts: '7001,7002,7005'

    Annotation

  8. Restart a pod for the settings of sidecar proxies to take effect.

    1. Log on to the ACK console.

    2. In the left-side navigation pane of the ACK console, click Clusters.

    3. On the Clusters page, find the cluster that you want to manage and click the name of the cluster or click Details in the Actions column. The details page of the cluster appears.

    4. In the left-side navigation pane of the details page, choose Workloads > Pods.

    5. On the Pods page, find the pod that you want to delete and choose More > Delete in the Actions column.

    6. In the dialog box that appears, click OK.

      Wait until the pod restarts. The settings take effect after the pod restarts.

Configure settings to allow the traffic forwarded to a specific CIDR block to bypass sidecar proxies

In this example, the traffic forwarded to the CIDR block 47.XX.XX.144/32 is allowed to bypass sidecar proxies. You can use the following methods as needed:

Method 1: Configure a blocking policy for sidecar proxies in the ASM console

  1. Log on to the ASM console.

  2. In the left-side navigation pane, choose Service Mesh > Mesh Management.

  3. On the Mesh Management page, find the ASM instance that you want to configure. Click the name of the ASM instance or click Manage in the Actions column.

  4. On the details page of the ASM instance, choose Data Plane Component Management > Sidecar Proxy Setting in the left-side navigation pane.

  5. Configure a blocking policy for sidecar proxies at the global or namespace level.

    • Global level

      1. On the Sidecar Proxy Setting page, click the global tab.

      2. Click the Istio代理 icon on the left side of Enable/Disable Sidecar Proxy by Ports or IP Addresses, set the Addresses to Which External Access Is Not Redirected to Sidecar Proxy parameter to 47.XX.XX.144/32, and then click Update Settings.

    • Namespace level

      1. On the Sidecar Proxy Setting page, click the Namespace tab.

      2. On the Namespace tab, select default from the Namespace drop-down list. Click the Istio代理 icon on the left side of Enable/Disable Sidecar Proxy by Ports or IP Addresses, set the Addresses to Which External Access Is Not Redirected to Sidecar Proxy parameter to 47.XX.XX.144/32, and then click Update Settings.

  6. Restart a pod for the settings of sidecar proxies to take effect.

    1. Log on to the ACK console.

    2. In the left-side navigation pane of the ACK console, click Clusters.

    3. On the Clusters page, find the cluster that you want to manage and click the name of the cluster or click Details in the Actions column. The details page of the cluster appears.

    4. In the left-side navigation pane of the details page, choose Workloads > Pods.

    5. On the Pods page, find the pod that you want to delete and choose More > Delete in the Actions column.

    6. In the dialog box that appears, click OK.

      Wait until the pod restarts. The settings take effect after the pod restarts.

Method 2: Configure a blocking policy for sidecar proxies in the ACK console

A Deployment is used in this example. Annotations are added to the YAML file of a pod to configure a blocking policy for sidecar proxies. For more information, see Configure a sidecar proxy by adding resource annotations.

  1. Log on to the ACK console.

  2. In the left-side navigation pane of the ACK console, click Clusters.

  3. On the Clusters page, find the cluster that you want to manage and click the name of the cluster or click Details in the Actions column. The details page of the cluster appears.

  4. In the left-side navigation pane of the details page, choose Workloads > Deployments.

  5. On the Deployments page, click the name of the application that you want to manage.

  6. In the upper-right corner of the application details page, click View in YAML.

  7. In the Edit YAML dialog box, add the following content to the spec.template.metadata parameter and click Update.

    annotations:
      traffic.sidecar.istio.io/excludeOutboundIPRanges: 47.XX.XX.144/32

    设置特定目标地址免于经过Sidecar代理

  8. Restart a pod for the settings of sidecar proxies to take effect.

    1. Log on to the ACK console.

    2. In the left-side navigation pane of the ACK console, click Clusters.

    3. On the Clusters page, find the cluster that you want to manage and click the name of the cluster or click Details in the Actions column. The details page of the cluster appears.

    4. In the left-side navigation pane of the details page, choose Workloads > Pods.

    5. On the Pods page, find the pod that you want to delete and choose More > Delete in the Actions column.

    6. In the dialog box that appears, click OK.

      Wait until the pod restarts. The settings take effect after the pod restarts.

Verify the result

You can select REGISTRY_ONLY as Outbound Traffic Policy on the Sidecar Proxy Setting page. This way, you can check whether the traffic passes through sidecar proxies. In REGISTRY_ONLY mode, if the traffic passes through sidecar proxies, the access to the destination CIDR block is blocked. If the traffic bypasses sidecar proxies, the access is successful.

  1. Log on to the ASM console. Go to the Sidecar Proxy Setting page and click the global tab.

  2. Click the Istio代理 icon on the left side of Outbound Traffic Policy, select REGISTRY_ONLY as Outbound Traffic Policy, and then click Update Settings.

  3. Run the following command to access the http://47.XX.XX.144/productpage URL:

    curl -I http://47.XX.XX.144/productpage

    Expected output: 配置Sidecar拦截策略After you configure settings to allow the traffic forwarded to the CIDR block 47.XX.XX.144/32 to bypass sidecar proxies, the access to the http://47.XX.XX.144/productpage URL is successful. You can specify a CIDR block to which the traffic is forwarded to bypass sidecar proxies based on your business requirements.