I'm looking for the standard way to purge all unused container with a kubernetes on all nodes. Now I'm doing like this.
purge.sh
#!/usr/bin/env bash
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
# Author: Ali Said Omar
# Created: '01/03/2016'
NODES=
function get_nodes(){
# --label-columns=NAME does not filter on NAME column
NODES=`kubectl get nodes --label-columns=NAME --no-headers | awk '{print $1}'`
}
function purge_on_nodes(){
for NODE in $NODES
do
glcoud compute ssh $NODE -A "sudo docker ps -aq | xargs sudo docker rm"
done
}
get_nodes
purge_on_nodes
Use Kubernetes Garbage collector. There are settings (minimum-container-ttl-duration
), which will help you to purge old containers.
There is no standard way to do this, because the system is meant to take care of it for you. Is there a particular reason that you need to do so? Or is the system malfunctioning in some way?