Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
Software Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Application Service Mesh/ Best Practices/ Reserving Source IP Address for Gateway Access

Reserving Source IP Address for Gateway Access

Updated on 2024-09-24 GMT+08:00
CAUTION:

If node affinity is configured, the ELB address cannot be used to access workloads in some scenarios. For details, see Why the ELB Address Cannot Be Used to Access Workloads in a Cluster?

Scenario

When a service is accessed through a gateway, the source IP address displayed in the target container is not the source IP address of the client by default. To retain the source IP address, perform the operations described in this section.

Configuration

Log in to the CCE console. On the Networking page, select the istio-system namespace, update the gateway service associated with the service, and change Service Affinity to Node-level. The prerequisite is that the function of obtaining the client IP address of the ELB has been enabled (this function is enabled by default).

externalTrafficPolicy: indicates whether the Service wants to route external traffic to the local nodes or cluster-wide endpoints. Two options are available: Cluster (default) and Local. Cluster hides the client IP address, which may cause the second hop to another node, but has a good overall load distribution. Local retains the source IP address of the client and avoids the second hop of LoadBalancer and NodePort services. However, there is a potential risk of unbalanced traffic transmission.

Authentication Method

The x-forward-for field of the httpbin image displays the source IP address. The httpbin service is an HTTP Request & Response Service that can send requests to the httpbin image. The httpbin image will return the requests based on the specified rules. You can search for the httpbin image in SWR. Before using the httpbin image for verification, ensure that the mesh function has been enabled for the cluster.

  1. Log in to the ASM console and click the name of an available test mesh to go to its details page.
  2. In the navigation pane, choose Mesh Configuration. Then, view the associated cluster.

  3. Click the cluster name to go to the cluster console. In the navigation pane, choose Workloads. On the Deployments tab, click Create Workload in the upper right corner.
  4. Configure workload information.

    Basic Information

    • Workload Type: Select Deployment.
    • Workload Name: Enter httpbin.
    • Namespace: Select the namespace of the workload. The default value is default.
    • Retain the default values of other parameters.

    Container Configuration

    • Basic Information
      • Container Name: Customize a name.
      • Image Name: Click Select Image, search for the httpbin image, select the image, and click OK.
      • Image Tag: Select an image tag.
      • Retain the default values of other parameters.

    Service Settings

    A Service solves the pod access problems. With a fixed IP address, a Service forwards access traffic to pods and performs load balancing for these pods.

    Click + under the service configuration parameter to go to the Create Service page.
    • Service Name: Enter the workload name.
    • Service Type: Select ClusterIP.
    • Port parameters:
      • Protocol: Select TCP.
      • Container Port: 80 (Use the actual port number.)
      • Service Port: 80 (Use the actual port number.)

  5. Click OK in the lower right corner.
  6. Click Create Workload in the lower right corner.
  7. On the cluster console, click Networking in the navigation pane. The created httpbin service is displayed in the service list.

  8. Return to the ASM console and click Service Management. The Configuration Diagnosis Result of the httpbin service is Abnormal.

  9. Click Fix. In Configuration Diagnosis Result, rectify the fault by following the solution.

    Take "The Service port name complies with the Istio specifications" as an example. Select http and click Auto Fix.

  10. In the navigation pane, choose Gateway Management. Then, click Add Gateway in the upper right corner. Configure the parameters in the window that slides out from the right.
    Configuration Information
    • Gateway Name: Enter httpbin.
    • Cluster: Select the cluster associated with the mesh.
    • Load Balancer: Select Public network and select a load balancer.
    • External Protocol: Select HTTP.
    • External Port: Specify a port.
    • External Access Address: Enter the public IP address of the load balancer selected for the Load Balancer.

    • Click + under Routing. In the Add Route dialog box displayed, add a route.
      • URL: Select Full match and enter a mapping.
      • Namespace: Select the namespace to which the service belongs.
      • Target Service: Retain the default value.

    When the configuration is complete, click OK.

  11. Click OK.
  12. Click Service Management on the left. You can view the external access address of the created route in the Access Address column.

  13. Add ?show_env=1 to the mapped external access address, for example, http://xxx.xxx.xxx:80/get?show_env=1. You can view the value of the x-forward-for field. The IP address obtained by the gateway is the container IP address.
    ...
    ...
    ...
    x-forward-for: xxxx
  14. Return to the cluster console, click Networking in the navigation pane, and modify the configuration of the gateway service associated with the service as follows:

    Select the istio-system namespace.

    Click More > Update in the Operation column. On the Update Service page displayed, change Service Affinity to Node-level, select I have read Notes on Using Load Balancers, and click OK.

  15. Return and refresh the external IP address accessed in 13. If the IP address obtained by the gateway in the x-forward-for field is the source IP address of the local host, the verification is complete.
    ...
    ...
    ...
    x-forward-for: xxxx

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback