<p>I have a few services running that require the Source IP to be preserved to perform authentication properly. I am running a Kubernetes environment in AKS using Nginx as my Ingress controller and am having problems understanding how I can implement this properly.</p>
<p>I read through this</p>
<p><a href="https://kubernetes.io/docs/tutorials/services/source-ip/#source-ip-for-services-with-typeloadbalancer" rel="nofollow noreferrer">https://kubernetes.io/docs/tutorials/services/source-ip/#source-ip-for-services-with-typeloadbalancer</a></p>
<p>as well as this</p>
<p><a href="https://github.com/kubernetes/ingress-nginx/issues/1067" rel="nofollow noreferrer">https://github.com/kubernetes/ingress-nginx/issues/1067</a></p>
<p>And read that setting this service.spec.externalTrafficPolicy to Local should resolve my problem, but I am having a hard time understanding which Service I should apply this to. It almost sounds like this needs to be added to the nginx deployment and it would effect all deployments which is going to be undesirable.</p>
<p>My question is, is there a way to apply this to my Service manifests for just the services that need it and not blanket add this to everything either with Nginx annotations or adjusting the Service manifest for the services I am deploying?</p>
<p>For reference, here is my Service manifest I am deploying with helm:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: {{ template &quot;service.fullname&quot; . }}
  labels:
    app: {{ template &quot;service.name&quot; . }}
    chart: {{ template &quot;service.chart&quot; . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  type: {{ .Values.service.type }}. #ClusterIP
  ports:
    - port: {{ .Values.service.port }}
      targetPort: {{ .Values.service.targetPort }}
      protocol: TCP
      name: http
  selector:
    app: {{ template &quot;service.name&quot; . }}
    release: {{ .Release.Name }}

</code></pre>

<p>You clearly need to add that setting to the <code>nginx ingress controller</code> service, the one with <code>type</code> = <code>LoadBalancer</code>.</p>
<p>If you think about it, there is no other option. <code>Nginx ingress controller</code> is the entry point in your cluster, so if you don't keep the source IP address there, there is no way you can have it in the services that come after that.</p>
