add nerdctl install updata
This commit is contained in:
@@ -4,15 +4,38 @@
|
||||
CURRENT_USER=$(whoami)
|
||||
|
||||
# 生成默认的 config.toml 配置文件(覆盖可能存在的失败配置)
|
||||
echo "生成默认的 config.toml 配置..."
|
||||
sudo containerd config default | sudo tee /etc/containerd/config.toml > /dev/null
|
||||
# echo "生成默认的 config.toml 配置..."
|
||||
# sudo containerd config default | sudo tee /etc/containerd/config.toml > /dev/null
|
||||
# sudo containerd config default | sed 's/version = "3"/version = "2"/' | sudo tee /etc/containerd/config.toml > /dev/null
|
||||
|
||||
# 配置路径
|
||||
#
|
||||
CONFIG_PATH="/etc/containerd/certs.d"
|
||||
NEW_STORAGE_PATH="/data/containerd"
|
||||
OLD_STORAGE_PATH="/var/lib/containerd"
|
||||
OLD_STATE_PATH="/run/containerd" # 旧的 state 目录
|
||||
|
||||
# 查找 [plugins.'io.containerd.grpc.v1.cri'.registry] 的位置并修改或添加 config_path 配置
|
||||
echo '配置 containerd 的 config.toml...'
|
||||
|
||||
line_number=$(grep -n -E '^\s*\[plugins.(\"|\x27)io.containerd.grpc.v1.cri(\"|\x27).registry\]' /etc/containerd/config.toml | cut -d':' -f1)
|
||||
|
||||
if [ -n "$line_number" ]; then
|
||||
# 检查下一行是否包含 `config_path`
|
||||
next_line=$((line_number + 1))
|
||||
if grep -q "^\s*config_path\s*=" /etc/containerd/config.toml; then
|
||||
# 若找到 `config_path`,则直接替换为新的值
|
||||
sudo sed -i "${next_line}s|config_path\s*=.*|config_path = '$CONFIG_PATH'|" /etc/containerd/config.toml
|
||||
echo "已修改 config_path 为 $CONFIG_PATH。"
|
||||
else
|
||||
echo "未找到 config_path,未执行任何修改。"
|
||||
fi
|
||||
else
|
||||
echo "未找到 [plugins.'io.containerd.grpc.v1.cri'.registry] 段落,请检查 config.toml 文件格式。"
|
||||
fi
|
||||
|
||||
# 检查配置文件
|
||||
sudo containerd config dump
|
||||
|
||||
# 修改 root 和 state 路径
|
||||
echo "更新 containerd 存储路径配置..."
|
||||
sudo sed -i "s|^\s*root\s*=.*|root = \"$NEW_STORAGE_PATH\"|" /etc/containerd/config.toml
|
||||
@@ -57,6 +80,10 @@ else
|
||||
echo "旧的状态路径 $OLD_STATE_PATH 不存在,无需迁移。"
|
||||
fi
|
||||
|
||||
# 删除所有的旧的镜像
|
||||
sudo nerdctl --namespace k8s.io image prune -a --force
|
||||
sudo nerdctl --namespace default image prune -a --force
|
||||
|
||||
# 获取迁移后的新目录大小
|
||||
initial_size=$(sudo du -sb "$NEW_STORAGE_PATH" | awk '{print $1}')
|
||||
|
||||
@@ -103,6 +130,8 @@ sudo systemctl restart containerd
|
||||
|
||||
# 设置 containerd.sock 的权限
|
||||
echo "设置 containerd.sock 的访问权限..."
|
||||
# sudo mkdir -p /run/containerd
|
||||
# sudo touch /run/containerd/containerd.sock
|
||||
sudo chown root:containerd /run/containerd/containerd.sock
|
||||
sudo chmod 660 /run/containerd/containerd.sock
|
||||
|
||||
|
||||
Reference in New Issue
Block a user