更新时间:2024-04-11 GMT+08:00
分享

异常排查及解决

无法备份HostPath类型存储卷

HostPath与Local均为本地存储卷,但由于Velero集成的Restic工具无法对HostPath类型的PV进行备份,只支持Local类型,因此需要在原集群中将HostPath类型存储卷替换为Local类型。

Local volume类型的存储建议在Kubernetes v1.10及以上的版本中使用,且只能静态创建,详情请参考local

  1. 创建Local volume的StorageClass。

    YAML文件如下:
    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: local
    provisioner: kubernetes.io/no-provisioner
    volumeBindingMode: WaitForFirstConsumer

  2. 需要修改hostPath字段为local字段,指定宿主机原有的本地磁盘路径,并添加nodeAffinity字段。

    YAML文件示例如下:
    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: mysql-pv
      labels: 
        app: mysql
    spec:
      accessModes:
      - ReadWriteOnce
      capacity:
        storage: 5Gi
      storageClassName: local     #指定上一步创建的StorageClass
      persistentVolumeReclaimPolicy: Delete
      local:
        path: "/mnt/data"     #指定挂载的本地磁盘路径
      nodeAffinity:
        required:
          nodeSelectorTerms:
          - matchExpressions:
            - key: kubernetes.io/hostname
              operator: Exists

  3. 执行以下命令验证创建结果。

    kubectl get pv

    回显如下:

    NAME       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM               STORAGECLASS   REASON   AGE
    mysql-pv   5Gi        RWO            Delete           Available                       local                   3s

备份工具资源分配不足

在生产环境中,当备份资源较多时,如备份工具资源大小使用默认值,可能会出现资源分配不足的情况,请参考以下步骤调整分配给Velero和Restic的CPU和内存大小。

安装Velero前:

您可在安装Velero时指定Velero和Restic使用的资源大小。

安装参数示例如下:

velero install \
   --velero-pod-cpu-request 500m \
   --velero-pod-mem-request 1Gi \
   --velero-pod-cpu-limit 1000m \
   --velero-pod-mem-limit 1Gi \
   --use-node-agent \
   --node-agent-pod-cpu-request 500m \
   --node-agent-pod-mem-request 1Gi \
   --node-agent-pod-cpu-limit 1000m \
   --node-agent-pod-mem-limit 1Gi

安装Velero后:

  1. 编辑命名空间velero下Velero和node-agent工作负载的YAML文件。

    kubectl edit deploy velero -n velero
    kubectl edit ds node-agent -n velero

  2. 修改resources字段下分配的资源大小,Velero和Restic工作负载的修改内容一致,如下所示。

    resources:
      limits:
        cpu: "1"
        memory: 1Gi
      requests:
        cpu: 500m
        memory: 1Gi

分享:

    相关文档

    相关产品