Is there a way to delete previous deployments with cli?
When I successfully run oc import-image $APPLICATION
a new deployment appears with a RC and after a few runs I hit the RC max and will have to manually delete the previous deployments.
Is there a script similar to oc delete rc $APPLICATION-$(($DEPLOYMENT_NUMBER - 1))
?
I ended up using the following code to create a (rushed) solution.
# 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
Over time you can end up with alot of replication controllers, and thus you need to clean them out. You can use oc delete rc <rc-num>
or even better oc adm prune
to do this. Checkout oc adm options
and oc adm prune --help
for options.
$ oc adm prune deployments --keep-complete=5 --namespace=myproject --confirm