缩写: sts
通过 kubectl api-resources 可以查到:
NAME | SHORTNAMES | APIVERSION | NAMESPACED | KIND |
---|---|---|---|---|
statefulsets | sts | apps/v1 | true | StatefulSet |
web-sts.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
ports:
- port: 80
name: web-sts-svc
clusterIP: None
selector:
app: nginx
---
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.7.9
ports:
- containerPort: 80
name: web
创建sts
kubectl create -f web-sts.yaml
扩缩容
扩容:kubectl scale sts web --replicas=5
缩容:kubectl scale sts web --replicas=3