# Get pod ip as client address when serving by cluster ip

**URL:** <https://discuss.kubernetes.io/t/get-pod-ip-as-client-address-when-serving-by-cluster-ip/16063>\
**Category:** General Discussions\
**Tags:** network\
**Created:** [May 27, 2021, 3:24am UTC](https://discuss.kubernetes.io/t/get-pod-ip-as-client-address-when-serving-by-cluster-ip/16063 "2021-05-27T03:24:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pacoxu](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/pacoxu/32/7729_2.png) [@pacoxu](https://discuss.kubernetes.io/u/pacoxu)\
**Post date:** [May 27, 2021, 3:24am UTC](https://discuss.kubernetes.io/t/get-pod-ip-as-client-address-when-serving-by-cluster-ip/16063/1 "2021-05-27T03:24:59Z")

</div>

### Cluster information:

Kubernetes version: 1.20  
Cloud being used: bare-metal  
Installation method: DaoCloud installer/ kubeadm  
Host OS: centos  
CNI and version: 0.7.5  
CRI and version: docker 19.03.6

Pod c1 is the client pod.  
Pod s1 is server pod. ClusterIP for s1 is clusterip1.(service type is ClusterIP).

Run `curl clusterIP:port/test` in Pod c1.  
When c1 and s1 are scheduled in different nodes, the server can get client address(calico pod IP) successfully.

When c1 and s1 are scheduled in the same node, the server can get not client address(calico pod IP) successfully, it gets the node ip.

```
 apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: dns-test-server
spec:
  selector:
    matchLabels:
      app: dns-test-server 
  serviceName: dns-test-server
  podManagementPolicy: Parallel
  replicas: 1
  template:
    metadata:
      labels:
        app: dns-test-server 
    spec:
      restartPolicy: Always
      terminationGracePeriodSeconds: 0
      containers:
      - name: server
        image: daocloud.io/daocloud/cdp-dns-test
        ports:
        - containerPort: 8080
          name: dns-test-server
---
apiVersion: v1
kind: Service
metadata:
  name: dns-test-server
  labels:
    app: dns-test-server
spec:
  ports:
  - port: 8080
    name: dns-test-server
    targetPort: 8080
  type: ClusterIP
  externalTrafficPolicy: Local
  selector:
    app: dns-test-server
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: dns-test-client
spec:
  selector:
    matchLabels:
      app: dns-test-client 
  serviceName: dns-test-client
  podManagementPolicy: Parallel
  replicas: 3
  template:
    metadata:
      labels:
        app: dns-test-client
    spec:
      restartPolicy: Always
      terminationGracePeriodSeconds: 0
      containers:
      - name: client
        image: daocloud.io/centos
        env:
        - name: MY_POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        command:
        - bash
        - -xc
        - |
          while sleep 2; do
            curl http://dns-test-server:8080/test
          done
        ports:
        - containerPort: 80
          name: dns-test-client
---
apiVersion: v1
kind: Service
metadata:
  name: dns-test-client
  labels:
    app: dns-test-client
spec:
  ports:
  - port: 80
    name: dns-test-client
    targetPort: 80
  type: ClusterIP 
  selector:
    app: dns-test-client

```

---

<div class="post-metadata">

**Author:** ![pacoxu](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/pacoxu/32/7729_2.png) [@pacoxu](https://discuss.kubernetes.io/u/pacoxu)\
**Post date:** [May 27, 2021, 3:25am UTC](https://discuss.kubernetes.io/t/get-pod-ip-as-client-address-when-serving-by-cluster-ip/16063/2 "2021-05-27T03:25:57Z")

</div>

What we tried? I set the `--masquerade-all` for kube-proxy, but it still worked as before.

---

<div class="post-metadata">

**Author:** ![protosam](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/protosam/32/7732_2.png) [@protosam](https://discuss.kubernetes.io/u/protosam)\
**Post date:** [May 27, 2021, 12:57pm UTC](https://discuss.kubernetes.io/t/get-pod-ip-as-client-address-when-serving-by-cluster-ip/16063/3 "2021-05-27T12:57:16Z")

</div>

What happens if you use the FQDN?

Example `dns-test-server.namespace.svc.cluster.local`
