Search code examples
azureazure-aksazure-load-balancer

source IP using AKS azure internal load balancer


I am creating internal load balancer like below

---
kind: Service
apiVersion: v1
metadata:
  name: nginx
  namespace: alts
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-internal: "true"
  labels:
    k8s-app: nginx
spec:
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
  selector:
    k8s-app: nginx
  type: LoadBalancer

enter image description here

But the issue is my app (APP in image) is not able to get the private IP of VM (Original source) it is getting the source as a load balancer.

Pls suggest an answer or workaround.


Solution

  • I suggest two approaches. In one of my clusters, I used exernalTrafficPolicy=Local but as explained in this article, doing this just happened to keep the source IP. Alternatively, you may look at the X-Forwarded-For header in your app.

    More info: https://medium.com/pablo-perez/k8s-externaltrafficpolicy-local-or-cluster-40b259a19404