head-less请求的例子如下:
apiVersion: apps/v1
kind: StatefulSet
metadata:
labels:
app: swm
name: swm
spec:
replicas: 2
selector:
matchLabels:
app: swm
serviceName: swm-headless
template:
metadata:
labels:
app: swm
name: swm
spec:
containers:
- env:
image: gpdb-6
imagePullPolicy: IfNotPresent
name: postgresql
ports:
- name: ssh
containerPort: 22
- name: pg
containerPort: 5432
---
apiVersion: v1
kind: Service
metadata:
labels:
app: swm
name: swm
spec:
ports:
- name: ssh
port: 22
protocol: TCP
targetPort: 22
- name: pg
port: 5432
protocol: TCP
targetPort: 5432
selector:
app: swm
type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
labels:
app: swm
name: swm-headless
spec:
clusterIP: None
ports:
- name: ssh
port: 22
protocol: TCP
targetPort: 22
- name: pg
port: 5432
protocol: TCP
targetPort: 5432
selector:
app: swm
type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
labels:
app: swm
name: swm-svc
spec:
ports:
- containerPort: 5432
hostPort: 5432
name: pg
protocol: TCP
- containerPort: 22
hostPort: 22
name: ssh
protocol: TCP
selector:
app: swm
sessionAffinity: None
type: ClusterIP
启用head-less服务之后,同一个服务的不同pod之间就可以通过head-less方式查询到对方