Less than 1 minute
apiVersion: v1
kind: Service
metadata:
name: service-hellok8s-clusterip-headless
spec:
type: ClusterIP # 这行是默认的,可省略
# sessionAffinity: ClientIP # or None, 设置会话亲和性(ClientIP表示同一客户端ip的请求会路由到同个Pod)
# sessionAffinityConfig:
# clientIP:
# timeoutSeconds: 3600 # 范围 0~86400,默认10800(3h)
clusterIP: None # None 表示不分配集群IP
selector:
app: hellok8s # 通过selector 选择映射的pod
ports: # 可选字段。若不配置,则 kube-proxy 转发时不做任何处理,请求直达DNS解析后的某个Pod
- port: 3000 # service端口
targetPort: 3000 # 后端pod端口