zoukankan      html  css  js  c++  java
  • 9、kubernetes之statefulset控制器

    一、StatefulSet 有状态副本集

    • 必要的三个组件: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做滚动更新,更新时倒序更新

  • 相关阅读:
    d is undefined错误
    $ is not defined错误类型
    jsonp从服务器读取数据并且予以显示
    jquery来跨域提交表单
    json和jsonp的使用格式
    Compaction介绍
    mysql操作
    DNS安装配置
    FLUSH TABLES WITH READ LOCK 和 LOCK TABLES 之种种
    执行安装redis报错undefined reference to `__sync_add_and_fetch_4'
  • 原文地址:https://www.cnblogs.com/L-dongf/p/11442253.html
Copyright © 2011-2022 走看看