開發與維運

Flexvolume插件分批升级方案

Flexvolume支持在线自动升级,您可以登陆控制台实现一键升级,参考:https://help.aliyun.com/document_detail/100605.html

Flexvolume升级不会影响您的应用,但是建议您可以选择在业务低峰的时候进行升级。您也可以参考本文给出的给flexvolume执行分配升级方案:

Flexvolume分批升级原理:

Daemonset更新策略支持:OnDelete、RollingUpdate两中模式,其中:

  • OnDelete:表示对DaemonSet更新模板后,pod不会马上升级,而是等待Pod删除重建的时候升级;
  • RollingUpdate:表示更新了模板Pod就会马上执行升级操作;

默认情况下升级策略是RollingUpdate,为了实现分批升级功能,我们修改升级策略为OnDelete,然后手动升级一批节点,查看数据卷挂载状态,然后再一批一批的升级;

Flexvolume分批升级步骤:

记录升级前的Flexvolume版本:
# kubectl describe ds flexvolume -nkube-system | grep Image

给Flexvolume配置升级策略为OnDelete;
# kubectl patch ds flexvolume -p '{"spec":{"updateStrategy":{"type":"OnDelete"}}}' -nkube-system

检查Flexvolume升级策略更新是否成功;下面命令有输出即认为成功;
# kubectl get ds flexvolume -nkube-system -oyaml | grep "type: OnDelete"

部署新版本Flexvolume
# kubectl apply -f flexvolume.yaml

检查Flexvolume DaemonSet镜像已经更新,到这一步pod还没有更新;
# kubectl describe ds flexvolume -nkube-system | grep Image
Image:      registry.cn-beijing.aliyuncs.com/acs/flexvolume:v1.14.6.15-8d3b7e7-aliyun

列出所有Flexvolume Pod;
# kubectl get pod -nkube-system -nkube-system -owide | grep flexvolume

分批升级:删除那个pod,pod重启后就会使用新镜像和配置;
# kubectl delete pod ** -nkube-system

检查所有pod是否已经是最新版本;
# for podname in `kubectl get pod -nkube-system | grep flexvolume | awk '{print $1}'`; do kubectl describe pod $podname -nkube-system | grep Image: ;done

将Flexvolume的更新策略修改为RollingUpdate;完成升级;
# kubectl patch ds flexvolume -p '{"spec":{"updateStrategy":{"type":"RollingUpdate"}}}' -nkube-system

Flexvolume部署模板:

把下面模板的{{.Region}}字段换成您的集群region名。

apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: flexvolume
  namespace: kube-system
  labels:
    k8s-volume: flexvolume
spec:
  selector:
    matchLabels:
      name: acs-flexvolume
  template:
    metadata:
      labels:
        name: acs-flexvolume
    spec:
      hostPID: true
      hostNetwork: true
      tolerations:
      - operator: "Exists"
      priorityClassName: system-node-critical
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: type
                operator: NotIn
                values:
                - virtual-kubelet
      nodeSelector:
        beta.kubernetes.io/os: linux
      containers:
      - name: acs-flexvolume
        image: registry-vpc.{{.Region}}.aliyuncs.com/acs/flexvolume:v1.14.6.15-8d3b7e7-aliyun
        imagePullPolicy: Always
        securityContext:
          privileged: true
        env:
        - name: ACS_DISK
          value: "true"
        - name: ACS_NAS
          value: "true"
        - name: ACS_OSS
          value: "true"
        - name: ACS_CPFS
          value: "false"
        resources:
          limits:
            cpu: 1000m
            memory: 1000Mi
          requests:
            cpu: 100m
            memory: 100Mi
        livenessProbe:
          exec:
            command:
            - sh
            - -c
            - ps -ef |grep /acs/flexvolume | grep monitoring | grep -v grep
          failureThreshold: 8
          initialDelaySeconds: 15
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 15
        volumeMounts:
        - name: usrdir
          mountPath: /host/usr/
        - name: etcdir
          mountPath: /host/etc/
        - name: logdir
          mountPath: /var/log/alicloud/
      volumes:
      - name: usrdir
        hostPath:
          path: /usr/
      - name: etcdir
        hostPath:
          path: /etc/
      - name: logdir
        hostPath:
          path: /var/log/alicloud/
  updateStrategy:
    type: RollingUpdate

Leave a Reply

Your email address will not be published. Required fields are marked *