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