Uninstalling k3s

The installer leaves a clean uninstall script that removes k3s and all its data.

When you install k3s, the script also drops an uninstall helper. Which one you get depends on the role of the node.

  • Server node: /usr/local/bin/k3s-uninstall.sh
  • Agent node: /usr/local/bin/k3s-agent-uninstall.sh

These scripts stop the service, remove the binary and symlinks, delete the systemd unit, and clean up /var/lib/rancher/k3s, network interfaces, and iptables rules that k3s created.

Example

Example · bash
# On a server node
sudo /usr/local/bin/k3s-uninstall.sh

# On an agent node
sudo /usr/local/bin/k3s-agent-uninstall.sh

When to use it

  • A developer tears down a temporary k3s cluster after a demo and runs the uninstall script to leave the host completely clean.
  • An operator removes a worker node's k3s agent installation without touching the server using the agent-specific uninstall script.
  • A CI pipeline calls the k3s uninstall script at the end of each job to prevent leftover network interfaces from affecting subsequent runs.

More examples

Uninstall k3s server

Runs the server uninstall script that the installer left behind, removing all k3s components and cluster data.

Example · bash
/usr/local/bin/k3s-uninstall.sh
# Removes binary, systemd service, config, and data

Uninstall k3s agent

Removes the k3s agent installation from a worker node without affecting the server or other agent nodes.

Example · bash
/usr/local/bin/k3s-agent-uninstall.sh
# Safe to run on worker nodes; does not touch the server

Clean up network interfaces

Runs the killall script to stop running containers and clean up CNI network interfaces left by k3s.

Example · bash
/usr/local/bin/k3s-killall.sh
ip link show | grep -E 'flannel|cni|vxlan'
# k3s-killall.sh stops all processes and removes network interfaces

Discussion

  • Be the first to comment on this lesson.