1.statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
serviceName: "nginx"
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.9.1
ports:
- containerPort: 80
name: web
这个yaml文件,跟deployment文件的唯一区别:多了serviceName: "nginx" 字段,这个字段的作用就是为了跟Nginx这个 headless service建立联系
headless service.yaml -- 用户访问服务(my-svc.my-namespace.svc.cluster.local) -- {直接(pod的一个ip) <--> (<pod-name>.<svc-name>.<namespace>.svc.cluster.local)}
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
ports:
- port: 80
name: web
clusterIP: None
selector:
app: nginx
原文地址:https://www.cnblogs.com/hixiaowei/p/9783560.html