Skip to content

How to expose client public ip address in k8s ingress nginx

Last updated on April 21, 2023

To expose the public IP in Ingress Nginx, you can use the ‘externalTrafficPolicy’ configuration. This allows you to route traffic to the node’s public IP address instead of the cluster IP address.

Here are the steps to configure ‘externalTrafficPolicy’ in Ingress Nginx:

1. Add the annotation ‘nginx.ingress.kubernetes.io/external-traffic-policy: “Local”‘ to the Ingress resource. This tells Ingress Nginx to use the node’s public IP address for traffic routing.

2. Set the ‘externalTrafficPolicy’ field in the Service definition to ‘Local’. This ensures that traffic is routed to the node’s public IP address instead of the cluster IP address.

3. Apply the changes to your Kubernetes cluster using the ‘kubectl apply’ command.

Once the changes have been applied, traffic should be routed to the node’s public IP address instead of the cluster IP address. This can be useful for scenarios where you need to expose a service to external users or services.

Or you can set the externalTrafficPolicy field in the Ingress nginx Service definition to Local. This ensures that only nodes running the application pods will receive traffic.

Published inKubernetesLinuxNginx