Retaining the Original IP Address of a Pod

SNAT Overview

In a CCE cluster that uses a VPC network, to enable pods to communicate with external systems, the system automatically translates the source IP addresses of the pods into the IP addresses of the nodes that are running them. This allows pods to communicate with external systems using the node IP addresses. This process is known as pod IP address masquerading or Source Network Address Translation (SNAT).

Prerequisites

You have a cluster that uses the VPC network and whose version is v1.23.14-r0, v1.25.9-r0, v1.27.6-r0, v1.28.4-r0, or later.

Default Non-Masqueraded CIDR Block Settings in a CCE Cluster

By default, CCE uses the following well-known private CIDR blocks as non-masqueraded CIDR blocks in each cluster:

Additionally, in a CCE cluster that uses a secondary VPC CIDR block, adding or resetting a node will automatically include the secondary CIDR block in the non-masqueraded CIDR blocks.

This means that when a pod initiates communication from these CIDR blocks with external resources, its source IP address of the data packet remains unchanged, and it will not be replaced with the IP address of the node running the pod.

Scenarios Where the Default Non-Masqueraded CIDR Blocks Does Not Fit

The default non-masqueraded CIDR block settings in CCE clusters apply to typical scenarios, but in certain specific scenarios, these default settings may not be sufficient to meet user requirements. The following shows typical examples:

Precautions

If you have set up a security group or ACL for a cloud service that only allows access from IP addresses of nodes running pods, there is no need to perform pod IP address masquerading and configure the nonMasqueradeCIDRs parameter.

The default setting of pod IP address masquerading (SNAT) is usually sufficient. However, if you need to retain the original IP addresses of pods in specific scenarios, you can configure the nonMasqueradeCIDRs parameter.

Before doing so, make sure you have evaluated your application scenario and understood the potential risks of improper configuration, because it may block access within clusters. If you are unsure whether to configure this parameter, it is recommended that you keep the default settings and adjust the configuration later once the requirement is clarified.

Procedure

To reserve the source IP address of a pod when the pod accesses a CIDR block, you can configure nonMasqueradeCIDRs to specify the CIDR block that does not need to be masqueraded.

  1. Log in to the CCE console and click the name of the target cluster to access the cluster console.
  2. In the navigation pane, choose Settings and click the Network tab.
  3. Modify the parameters under Retain the non-spoofed CIDR block of the original pod IP address. Make sure the parameter configuration complies with the following rules:

    • Each CIDR block must comply with the CIDR format and must be a valid IPv4 CIDR block.

      Example of a correct CIDR block: 192.168.1.0/24

      Example of an incorrect CIDR block: 192.168.1.1/24 (incompliant with the CIDR format)

    • The CIDR blocks you configured do not overlap with each other.

      Example of correct CIDR blocks: 192.168.1.0/24 and 192.168.2.0/24

      Example of incorrect CIDR blocks: 192.168.1.0/24 and 192.168.1.128/25 (The two CIDR blocks overlap.)

    • The nonMasqueradeCIDRs parameter must contain all destination CIDR blocks that you want them to use the original pod IP addresses for communications.

  4. After the modification, click Confirm configuration. The setting takes effect within 1 minute.