How to Delete and Remove Traefik from K3s Securely
Posted December 9, 2024
An installed K3s comes packaged with Traefik out of the box. It serves purposes like dashboarding and Kubernetes ingress controller. This guide is now created to let you learn to remove and delete Traefik if you have such intentions.
Whether you have K3s already installed or not this guide will walk you through all steps you need to delete Traefik from an existing K3s installation. You will also learn installing and not deleting Traefik with a fresh k3s configuration.
Is There Reasons To Remove and Delete Traefik from K3s
You can’t just remove Traefik as the K3s default ingress controller. There must be valid reasons such as:
- Need for custom K3s Ingress like Nginx.
- The idea is to make K3s even more lightweight by just deleting Traefik.
- Any Traefik security-related concerns,
- A simplification of having your ingress controller to avoid not needed components.
Removing Traefik from an Exisiting K3s Cluster
A correctly installed K3s cluster will have the following pods running (Of course you’ll need to run kubectl get pods -A
):
You might think just deleting these pods will get the Traefik removed. Yes, you are correct however, that is a secure and good practice to do so.
First, ensure you stop K3s:
sudo systemctl stop k3s
Next, open the sudo nano /etc/systemd/system/k3s.service
file. I contain an ExecStart patch for the K3s Server. Locate ExecStart=/usr/local/bin/k3s \
and add --disable=traefik \
as follows:
ExecStart=/usr/local/bin/k3s \
server \
--disable=traefik \
Then, Reload the daemon and start the K3s server:
sudo systemctl daemon-reload
sudo systemctl start k3s
After that, delete Traefik and its resources manually.
kubectl delete -f /var/lib/rancher/k3s/server/manifests/traefik.yaml
Every time K3s starts, it checks the server/manifests
directory for the traefik.yaml
manifest. This will recreate the Traefik resources. Delete this file so K3s won’t automatically apply the manifest:
sudo rm -rf /var/lib/rancher/k3s/server/manifests/traefik.yaml
Finally, restart K3s with sudo systemctl restart k3s
and check the now existing Pods:
Removing Traefik from start
Let’s say it’s your First time installing K3s. In that case, you don’t want Traefik anywhere near you. The is no point in beating yourself to delete Traefik. Just use the --disable=traefik
flag alongside the K3s installation command as follows:
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server --disable=traefik" K3S_KUBECONFIG_MODE="644" sh -s -