<p>I have a Kubernetes cluster of 3 nodes.</p>
<p>A sample deployment</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
</code></pre>
<p>I do not have ingress, but I do have external load balancer that round-robins the traffic at <code>80.11.12.10</code>, <code>80.11.12.11</code>, <code>80.11.12.12</code>. So I set my service like this.</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
  externalIPs:
    - 80.11.12.10
    - 80.11.12.11
    - 80.11.12.12
</code></pre>
<p>The problem is that due to existing kubernetes service load balancer the traffic get load balancing twice. Aside that it is unnecessary it is spoils the connection persistence. Is there a way to force Kubernetes to forward traffic on local machine pod for each node?</p>

Yuki
<p>If you set <code>service.spec.externalTrafficPolicy</code> to the value <code>Local</code>, kube-proxy only proxies proxy requests to local endpoints, and does not forward traffic to other nodes.</p>
<pre><code>kubectl patch svc servicename -p '{&quot;spec&quot;:{&quot;externalTrafficPolicy&quot;:&quot;Local&quot;}}'
</code></pre>
<p>If there are no local endpoints, packets sent to the node are dropped.</p>
<p>For <code>clusterIP</code> type service you need to use <a href="https://kubernetes.io/docs/concepts/services-networking/service-topology/" rel="nofollow noreferrer">Service Topology</a></p>
<blockquote>
<p>Service Topology enables a service to route traffic based upon the
Node topology of the cluster. For example, a service can specify that
traffic be preferentially routed to endpoints that are on the same
Node as the client, or in the same availability zone.</p>
</blockquote>
<p>It's an alpha feature available from kubernetes 1.17 which needs to be turned on by <a href="https://kubernetes.io/docs/tasks/administer-cluster/enabling-service-topology/" rel="nofollow noreferrer">enabling the feature flag</a></p>
