有没有办法用cli删除以前的部署?
当我成功运行oc import-image $APPLICATION
时,会出现一个带有RC的新部署,经过几次运行后,我点击了RC max,并且必须手动删除以前的部署。
是否有类似oc delete rc $APPLICATION-$(($DEPLOYMENT_NUMBER - 1))
的脚本?
答案 0 :(得分:0)
我最终使用以下代码创建(匆忙)解决方案。
# DEPLOYMENT_COUNT will be the number of deployments
DEPLOYMENT_COUNT=`oc get rc | wc -l`
DEPLOYMENT_COUNT=$((DEPLOYMENT_COUNT - 1))
for ((i=1; i<$DEPLOYMENT_COUNT + 1; i++))
do
#CURR_POD_LINE=`oc get rc | tail -$i | head -n1`
DEPLOYMENT_ID=`oc get rc | tail -$i | head -n1 | awk '{print $1}'`
DESIRED_PODS_COUNT=`oc get rc | tail -$i | head -n1 | awk '{print $5}'`
# IF number of desired pods is 0, then delete the deployment
if [ $DESIRED_PODS_COUNT -eq 0 ]
then
#DELETE
oc delete rc $DEPLOYMENT_ID
fi
echo $DEPLOYMENT_ID
echo $DESIRED_PODS_COUNT
done
答案 1 :(得分:0)
随着时间的推移,您最终可能会遇到很多复制控制器,因此您需要清除它们。您可以使用oc delete rc <rc-num>
甚至更好oc adm prune
来执行此操作。结帐oc adm options
和oc adm prune --help
了解选项。
$ oc adm prune deployments --keep-complete=5 --namespace=myproject --confirm