After remove a host from rancher, how to clean agent containers and iptable rules?

It seems that rancher server will not stop/remove agent containers and rules on the host which I deleted from rancher.
So is there some guide to clean them?
I can manually remove agent containers but there seems too much NAT rules remains.

I use two small scripts, but it remove all iptables rules.

iptables -F

iptables -t nat -F

iptables -P INPUT ACCEPT

iptables -P FORWARD ACCEPT

iptables -P OUTPUT ACCEPT

For Docker, to clean it i use this script :

docker rm -f $(docker ps -a -q)
docker rmi -f $(docker images -q)
service docker stop
rm -rf /var/lib/docker
rm -rf /var/lib/rancher/state
service docker start

2 Likes

A reboot of the host cleans up the iptables rules.

I usually reuse the same host for multiple rancher installations during my testing. Here are the steps that I use personally:

docker rm -f $(docker ps -qa)
reboot
rm -rf /var/lib/rancher/state

Then I can use this host for joining a different cluster.

2 Likes

yes reboot is the way to clean iptables rules, may remove hosts from UI can do this staff feels better.

why not?
docker system prune -a

I cannot thank you enough. I had to use this host for a different cluster and I tried everything but forgot about /var/lib/rancher/state. It is my third day triaging this issue and you saved me a lot of headache. You are not the hero we (DevOps noobs) deserve but the hero we need. You are a silent guardian. A watchful protector. A Dark Knight.

.

Charly’s response worked for me:

docker rm -f $(docker ps -a -q)
docker rmi -f $(docker images -q)
service docker stop
rm -rf /var/lib/docker
rm -rf /var/lib/rancher/state
service docker start

In the official documentation, you can see something similar (when you reuse another VM clone): FAQS about Rancher Agents/Hosts