9、kubernetes之statefulset控制器

匿名 (未验证) 提交于 2019-12-02 23:57:01
  • 必要的三个组件:headless service、StatefulSet、volumeClaimTemplate
  • 准备pv
apiVersion: v1 kind: PersistentVolume metadata:   name: pv001   labels:     name: pv001 spec:   nfs:     path: /data/volumes/v1     server: 192.168.100.1   accessModes: ["ReadWriteOnce"]   capacity:     storage: 5Gi --- apiVersion: v1 kind: PersistentVolume metadata:   name: pv002   labels:     name: pv002 spec:   nfs:     path: /data/volumes/v2     server: 192.168.100.1   accessModes: ["ReadWriteOnce"]   capacity:     storage: 5Gi --- apiVersion: v1 kind: PersistentVolume metadata:   name: pv003   labels:     name: pv003 spec:   nfs:     path: /data/volumes/v3     server: 192.168.100.1   accessModes: ["ReadWriteOnce"]   capacity:     storage: 5Gi --- apiVersion: v1 kind: PersistentVolume metadata:   name: pv004   labels:     name: pv004 spec:   nfs:     path: /data/volumes/v4     server: 192.168.100.1   accessModes: ["ReadWriteOnce"]   capacity:     storage: 5Gi --- apiVersion: v1 kind: PersistentVolume metadata:   name: pv005   labels:     name: pv005 spec:   nfs:     path: /data/volumes/v5     server: 192.168.100.1   accessModes: ["ReadWriteOnce"]   capacity:     storage: 5Gi
  • 创建3个有状态副本(使用nginx模拟)
apiVersion: v1 kind: Service metadata:   name: myapp   labels:     app: myapp spec:   ports:   - port: 80     name: web   clusterIP: None   selector:     app: myapp-pod --- apiVersion: apps/v1 kind: StatefulSet metadata:   name: myapp spec:   serviceName: myapp   replicas: 3   selector:     matchLabels:       app: myapp-pod   template:     metadata:       labels:         app: myapp-pod     spec:       containers:       - name: myapp         image: dongfeimg/myapp:v1         ports:         - containerPort: 80           name: web         volumeMounts:         - name: myappdata           mountPath: /usr/share/nginx/html   volumeClaimTemplates:   - metadata:       name: myappdata     spec:       accessModes: ["ReadWriteOnce"]       resources:         requests:           storage: 5Gi
  • 扩容/缩容
# kubectl scale sts myapp --replicas=5
# kubectl patch sts myapp -p '{"spec":{"replicas":2}}'
  • 更新
# kubectl patch sts myapp -p '{"spec":{"updateStrategy":{"rollingUpdate":{partition":4}}}}'  #修改更新分区; # kubectl set image sts/myapp myapp=dongfeimg/myapp:v2  

更新分区:"partition":4

代表pod序号大于等于4的pod做滚动更新,更新时倒序更新

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!