Enabling a LoadBalancer Service to Obtain the Client IP Address
When creating a LoadBalancer Service using a shared load balancer, you can configure annotations for the load balancer listeners to obtain the client IP address.
- If a dedicated load balancer is used, the function of obtaining the client IP address is enabled by default.
- After the function of obtaining the client IP address is enabled, if you delete the target annotation from the YAML file, the configuration on the ELB will be retained.
Prerequisites
- A Kubernetes cluster is available and the cluster version meets the following requirements:
- v1.23: v1.23.17-r0 or later
- v1.25: v1.25.12-r0 or later
- v1.27: v1.27.9-r0 or later
- v1.28: v1.28.7-r0 or later
- v1.29: v1.29.3-r0 or later
- Other clusters of later versions
- The cluster can be accessed using kubectl. For details, see Connecting to a Cluster Using kubectl.
Notes and Constraints
In CCE standard clusters, this setting takes effect only when Service affinity is set to the node level affinity (with externalTrafficPolicy set to Local).
In CCE Turbo clusters, this setting cannot take effect, because Service affinity cannot be set to the node level affinity and externalTrafficPolicy cannot be set to Local.
Using kubectl
apiVersion: v1
kind: Service
metadata:
name: nginx
annotations:
kubernetes.io/elb.id: <your_elb_id> # Load balancer ID. Replace it with the actual value.
kubernetes.io/elb.class: union # Load balancer type
kubernetes.io/elb.transparent-client-ip: 'true' # Enable the function of obtaining the client source IP address.
spec:
selector:
app: nginx
externalTrafficPolicy: Local
ports:
- name: service0
port: 80
protocol: TCP
targetPort: 80
type: LoadBalancer
Parameter |
Type |
Description |
---|---|---|
kubernetes.io/elb.transparent-client-ip |
String |
This parameter can be configured only for TCP/UDP Services.
|
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot