<p>I have an application based on Python-Flask. I would like to get Clients Public Ip when they are hits my ingress endpoint. </p>

<p>I have already tried to change externalTrafficPolicy to Local and Cluster.</p>

<p>My Pod YAML file</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  labels:
    run: webplatform
  name: webplatform-deployment-6d68c99fc7-xlb8j
  namespace: prod
spec:
  containers:
  - command:
    - python
    - /app/app.py
    envFrom:
    - secretRef:
        name: webplatform-secret
        optional: false
    image: docker.fuchicorp.com/webplatform-prod:0.5
    imagePullPolicy: Always
    name: webplatform-container
  imagePullSecrets:
  - name: nexus-creds
  serviceAccount: webplatform-service-account
  serviceAccountName: webplatform-service-account
</code></pre>

<p>My Service YAML file </p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: webplatform-service
  namespace: prod
spec:
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 32744
    port: 7101
    protocol: TCP
    targetPort: 5000
  selector:
    run: webplatform
  sessionAffinity: None
  type: NodePort

</code></pre>

<p>My Ingress recourses YAML file </p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    certmanager.k8s.io/cluster-issuer: letsencrypt-fuchicorp-prod
    kubernetes.io/ingress.class: nginx
  generation: 2
  name: ingress-webplaform
  namespace: prod
spec:
  rules:
  - host: academy.fuchicorp.com
    http:
      paths:
      - backend:
          serviceName: webplatform-service
          servicePort: 7101
  tls:
  - hosts:
    - academy.fuchicorp.com
    secretName: letsencrypt-sec-webplatform-prod

</code></pre>

<p>When I see the logs I see that Ingress-Controllers IP on the logs </p>

<pre><code>INFO: 10.16.0.16 - - [28/Sep/2019 20:06:12] "GET / HTTP/1.1" 200 -
</code></pre>

Farkhod Sadykov
<h3>TL;DR</h3>

<p>client IP should be available via the <code>X-Forwarded-For</code> HTTP header</p>

<hr>

<p>It should be provided by the load balancer (the ingress controller). Assuming your cluster is running on the cloud (aws, gcp, etc.), you get the client IP via the <code>X-Forwarded-For</code> HTTP header.</p>

<p>If its an on-prem k8s cluster (you run it on your own private cloud/ local machine), configure your load-balancer to do that-
<a href="http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream" rel="nofollow noreferrer">http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream</a></p>
