k8s StatefulSet 有状态应用编排
官方文档:
https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/
参考文档:
http://docs.kubernetes.org.cn/732.html
https://edu.aliyun.com/lesson_1651_13093?spm=5176.10731542.0.0.6cd020beIZmqB5#_13093
创建 StatefulSet
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: web
spec:
serviceName: "nginx"
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: gcr.io/google_containers/nginx-slim:0.8
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
查看
kubectl get statefulset (sts)
灰度扩容
kubectl patch statefulset web -p '{"spec":{"updateStrategy":{"type":"RollingUpdate","rollingUpdate":{"partition":2}}}}'
spec:
updateStrategy:
rollingUpdate:
partition: 2 #这里是要保留旧版本的数量
更新回滚镜像
记录历史 --record
kubectl apply -f **** --record
查看当前状态
kubectl rollout status deployment/demo -w
查看历史
kubectl rollout history deployment/demo
回滚到指定版本
kubectl rollout undo deployment/demo --to-revision=2
更新镜像
kubectl set image deployment demo demoname=image:ver