<p>I have created Nginx pod with Load balancer service in GKE. When it receive requests from external user, in Nginx log it is showing the request is received from an Internal IP (and this is happening randomly).</p>
<p>Sample Request</p>
<pre><code>&quot;@timestamp&quot;: &quot;03/Sep/2022:16:25:38 +0530&quot;, &quot;@fields&quot;: { &quot;remote_addr&quot;: &quot;10.160.0.30&quot;, &quot;remote_user&quot;: &quot;-&quot;, &quot;body_bytes_sent&quot;: &quot;3767&quot;, &quot;gzip_ratio&quot;: &quot;3.52&quot;,&quot;request_time&quot;: &quot;0.113&quot;, &quot;connection_requests&quot;: &quot;7&quot;,&quot;status&quot;: &quot;200&quot;, &quot;request&quot;: &quot;GET /admin HTTP/2.0&quot;, &quot;request_method&quot;: &quot;GET&quot;
</code></pre>
<p>YAML files</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: image_name
        ports:
        - containerPort: 80
        - containerPort: 443
        resources:
          requests:
            cpu: 2000m
            memory: 2Gi
          limits:
            cpu: 2000m
            memory: 2Gi
</code></pre>
<p>==========</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: dev-nginx-lb-service
spec:
  loadBalancerIP: IP_address
  type: LoadBalancer
  selector:
    app: nginx
  ports:
  - name: https
    protocol: TCP
    port: 443
    targetPort: 443
  - name: http
    protocol: TCP
    port: 80
    targetPort: 80
</code></pre>

karan525
<p>Not sure why it would be random.  By default, GKE nodes perform SNAT on packets received via load balancing. If you want to pass the client address directly to the backend pods, you can set <code>externalTrafficPolicy: Local</code> in your Service spec:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: dev-nginx-lb-service
spec:
  loadBalancerIP: IP_address
  type: LoadBalancer
  externalTrafficPolicy: Local
  selector:
    app: nginx
  ports:
  - name: https
    protocol: TCP
    port: 443
    targetPort: 443
  - name: http
    protocol: TCP
    port: 80
    targetPort: 80
</code></pre>
