k8s集群v1.15.xx升级到v1.18.xx编排文件不一样了,可以使用下面命令替换,也可以批量替换
sed -i 's/v1beta1/&\napiVersion: apps\/v1/g' "aaa-deployment.yaml" sed -i 's/ template/ selector:\n&/g' "aaa-deployment.yaml" sed -i 's/ template/ matchLabels:\n&/g' "aaa-deployment.yaml" sed -i "s/ template/ app: $NAME\n&/g" "aaa-deployment.yaml" sed -i '/v1beta1/d' "aaa-deployment.yaml" sed -i '$d' "aaa-deployment.yaml" echo " app: $NAME" >> "aaa-deployment.yaml"
批量替换
for Project in $(cat Project2.log) do cd /opt/test/ if [[ -f "$Project.yaml" ]];then NAME=$(cat $Project.yaml |grep name | head -n 1 | awk -F ' ' '{print $2}') sed -i 's/v1beta1/&\napiVersion: apps\/v1/g' "$Project.yaml" sed -i 's/ template/ selector:\n&/g' "$Project.yaml" sed -i 's/ template/ matchLabels:\n&/g' "$Project.yaml" sed -i "s/ template/ app: $NAME\n&/g" "$Project.yaml" sed -i '/v1beta1/d' "$Project.yaml" sed -i '$d' "$Project.yaml" echo " app: $NAME" >> "$Project.yaml" else echo "$Project nonono" fi done