Files
CmiiDeploy/998-常用脚本/更新脚本/配合dltu的镜像更新脚本.sh
2026-05-19 14:28:44 +08:00

48 lines
1.5 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 1. 定义命名空间
NAMESPACE="bj-sh-uas-260511"
IMAGE_NAME_PREFIX="192.168.3.31:8088/cmii"
# 检查输入文件是否存在
if [ ! -f "$1" ]; then
echo "使用方法: $0 <镜像列表文件>"
exit 1
fi
echo "开始更新命名空间 ${NAMESPACE} 下的 Deployment..."
# 2. 逐行读取文件内容
while IFS= read -r line || [ -n "$line" ]; do
# 忽略空行
[ -z "$line" ] && continue
# 以 = 为分隔符提取:
# 第3项为 Deployment 名称
# 第4项为 镜像 Tag
DEPLOY_NAME=$(echo "$line" | cut -d'=' -f3)
IMAGE_TAG=$(echo "$line" | cut -d'=' -f4 | sed 's/.tar.gz//')
# 假设容器名称Container Name与 Deployment 名称一致
# 这是 Kubernetes 部署中的常见规范。如果不一致,请修改 --image 后面的第一个参数。
IMAGE_NAME="${IMAGE_NAME_PREFIX}/${DEPLOY_NAME}:${IMAGE_TAG}"
echo "------------------------------------------------"
echo "正在更新: ${DEPLOY_NAME}"
echo "目标版本: ${IMAGE_TAG}"
# 3. 使用 kubectl 执行更新
# 格式kubectl set image deployment/<name> <container_name>=<new_image> -n <ns>
kubectl set image deployment/"${DEPLOY_NAME}" "${DEPLOY_NAME}"="${IMAGE_NAME}" -n "${NAMESPACE}"
if [ $? -eq 0 ]; then
echo "✅ 提交成功"
else
echo "❌ 提交失败,请检查 Deployment 名称是否正确"
fi
done < "$1"
echo "------------------------------------------------"
echo "所有更新指令已发送完毕。"