How to get source IP from a Pod in kubernetes?

1/9/2018

I have set up a working k8s cluster.

Each node of the cluster is inside network 10.11.12.0/24 (physical network). Over this network is running a flanneld (canal) cni.

Each node has another network interface (not managed by k8s) with cidr 192.168.0.0/24

When I deploy a service like:

kind: Service
apiVersion: v1
metadata:
  name: my-awesome-webapp
spec:
  selector:
    server: serverA
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
  externalTrafficPolicy: Local
  type: LoadBalancer
  externalIPs:
    - 192.168.0.163

The service is accessible at http://192.168.0.163, but the Pod receives source ip: 192.168.0.163 eth0 address of the server: not my source ip (192.168.0.94).

Deployment consists of 2 pods with the same spec.

Is possible to Pods to view my source ip m? Anyone knows how to manage it? externalTrafficPolicy: Local seems not working.

-- indiketa
kubernetes
networking

1 Answer

1/11/2018

Kubernetes change the source IP with the cluster/node IPs for which the details information can be found on this document. Kubernetes has a feature to preserve the client source IP which I believe you already are already aware. Seems like a this is a bug in Kubernetes and there is already an open bug for this issue of below command not working properly.

externalTrafficPolicy: Local

I suggest to post on the bug to get more attention on the issue.

-- Taher
Source: StackOverflow