升级 DirectPV

更新自定义安装
自定义安装不支持客户端升级功能。使用 kubectl directpv migrate 将旧资源迁移到新安装中。
Pod 安全策略

Kubernetes 在 v1.21 中弃用了 PodSecurityPolicy 功能,并在 v1.25 中完全删除了该功能。按照 Kubernetes 文档 中的建议,使用 Pod 安全准入 作为替代。

DirectPV 在 4.0.x 版本中继续支持 PodSecurityPolicy。DirectPV 4.1.x 及更高版本已删除对 PodSecurityPolicy 的支持。

从 4.x.x 升级 DirectPV CSI 驱动程序到最新版本

离线升级

按照以下步骤执行离线升级

  1. 卸载 DirectPV CSI 驱动程序。

    这不会删除任何现有资源。

    kubectl directpv uninstall
    
  2. 升级 DirectPV 插件。

    kubectl krew upgrade directpv
    

    如果您使用的是二进制文件而不是 krew,请下载适用于您的操作系统和体系结构的最新二进制文件。

  3. 安装最新的 DirectPV CSI 驱动程序.

就地升级

按照以下步骤执行就地升级

  1. 使用以下命令升级 DirectPV krew 插件

    kubectl krew upgrade directpv
    

    如果您使用的是二进制文件而不是 krew,请下载适用于您的操作系统和体系结构的最新二进制文件。

  2. 使用适用于您的环境所需的适当节点选择器、容忍度和 KUBELET_DIR_PATH 环境变量运行安装脚本。

    curl -sfL https://github.com/minio/directpv/raw/master/docs/tools/install.sh | sh -s - apply
    

保留 PodSecurityPolicy 支持

如果您升级到 4.1.x 并希望保留对 PodSecurityPolicy 的支持,请完成以下步骤。

升级前

备份现有的 pspclusterrolebinding YAML 规范。

kubectl get psp directpv-min-io -o yaml > psp.yaml
kubectl get clusterrolebinding psp-directpv-min-io -o yaml > psp-crb.yaml

应用备份 YAML

完成其他升级步骤后,应用 pspclusterrolebinding YAML 备份。

kubectl apply -f psp.yaml
kubectl apply -f psp-crb.yaml

升级旧版 DirectCSI 驱动程序

对于旧版本,请先升级到 v3.2.2,然后再升级到最新版本。

在最新版本的 DirectPV 中,CSI 边车映像已更新。

  1. 如果您从 3.1.0 或更高版本升级,请卸载现有的 DirectCSI 驱动程序。

    卸载 DirectPV 不会删除任何资源。

    kubectl directcsi uninstall
    

    如果您从旧版本升级,您将在流程的后面步骤中执行此操作。

  2. 升级或安装最新版本的 DirectPV 插件。

    kubectl krew upgrade directpv
    

    如果您还没有从 Direct CSI 升级到 DirectPV,请改用以下方法

    kubectl krew install directpv
    
  3. (可选)如果您正在为调度使用自定义存储类 并且 您是从 < v4.0.0 版本升级的,您 必须 修改存储类参数。

    在相应的存储类参数部分中,将 direct.csi.min.io/access-tier: <您的访问层级值> 更改为 directpv.min.io/access-tier: <您的访问层级值>

  4. 安装更新版本的 Direct-CSI。

    kubectl directpv install
    

    有关安装流程或自定义安装方法的更多详细信息,请参阅 安装文档

  5. 如果您是从低于 3.1.0 的版本升级,请卸载 DirectCSI 驱动程序。

    kubectl directcsi uninstall
    
  6. 检查 pod 是否正在运行。

    kubectl get pods -n direct-csi-min-io -w
    
  7. 验证您是否可以访问 DirectPV 驱动器。

    kubectl directpv drives ls
    

升级后清理

旧的 CRD(directcsidrivesdirectcsivolumes)已弃用,在 v4.0.0 及更高版本中不再使用。这些可以在升级后删除。

升级到最新版本后,使用以下 Bash 脚本删除旧对象。

#!/usr/bin/env bash
#
# This file is part of MinIO DirectPV
# Copyright (c) 2023 MinIO, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://gnu.ac.cn/licenses/>.

#
# This script removes direct-csi drives and volumes after taking backup YAMLs
# to directcsidrives.yaml and directcsivolumes.yaml
#

set -e -C -o pipefail

function init() {
    if [[ $# -ne 0 ]]; then
        echo "usage: remove-directcsi.sh"
        echo
        echo "This script removes direct-csi drives and volumes after taking backup YAMLs"
        echo "to directcsidrives.yaml and directcsivolumes.yaml"
        exit 255
    fi

    if ! which kubectl >/dev/null 2>&1; then
        echo "kubectl not found; please install"
        exit 255
    fi
}

# usage: unset_object_finalizers <resource>
function unset_object_finalizers() {
    kubectl get "${1}" -o custom-columns=NAME:.metadata.name --no-headers | while read -r resource_name; do
        kubectl patch "${1}" "${resource_name}" -p '{"metadata":{"finalizers":null}}' --type=merge
    done
}

function main() {
    kubectl get directcsivolumes -o yaml > directcsivolumes.yaml
    kubectl get directcsidrives -o yaml > directcsidrives.yaml

    # unset the finalizers
    unset_object_finalizers "directcsidrives"
    unset_object_finalizers "directcsivolumes"
    
    # delete the resources
    kubectl delete directcsivolumes --all
    kubectl delete directcsidrives --all
}

init "$@"
main "$@"

从低于 v3.2.x 的版本升级

如果您使用的是低于 3.2.2 的 DirectCSI 版本,请先升级到 v3.2.2,然后再升级到最新版本。

  1. 卸载现有设置。

    卸载 DirectPV 不会删除任何资源。

    kubectl direct-csi uninstall
    
  2. 确认 CSI pod 的删除。

    kubectl get pods -n direct-csi-min-io
    

    DirectPV v4.0.0 及更高版本在创建新的驱动器或卷时不再使用 direct-cs-min-io 命名空间。但是,DirectPV 的最新版本可以继续使用该命名空间中已存在的资源。

  3. https://github.com/minio/directpv/releases/tag/v3.2.2 下载 Direct-CSI v3.2.2。

  4. 加载以下镜像

    quay.io/minio/csi-provisioner:v2.2.0-go1.18
    quay.io/minio/csi-node-driver-registrar:v2.2.0-go1.18
    quay.io/minio/livenessprobe:v2.2.0-go1.18
    

    如果您的 Kubernetes 版本低于 v1.20,也请推送 quay.io/minio/csi-provisioner:v2.2.0-go1.18

  5. 安装更新版本的 Direct-CSI。

    kubectl direct-csi install
    
  6. 检查 pod 是否正在运行。

    kubectl get pods -n direct-csi-min-io -w
    
  7. 验证您是否可以访问 DirectPV 驱动器。

    kubectl direct-csi drives ls
    

    升级 DirectPV 插件

    要使用 krew 升级插件,请使用以下命令。

    kubectl krew upgrade directpv
    

    要从二进制文件升级,请按照 二进制文件安装说明 进行操作。