Skip to main content

Install external traefik on K3s cluster

Preface

Recently, I encountered a traefik Issue in my K3s cluster.

The Traefik instance came pre-installed with K3s deployment. Its automatic updates caused accessibility issues in my cluster. To resolve this problem, I decided to remove the built-in Traefik and install an external Traefik instance instead.

+ helm_v3 upgrade --set-string global.systemDefaultRegistry= traefik https://10.43.0.1:443/static/charts/traefik-20.3.1+up20.3.0.tgz --values /config/values-01_HelmChart.y
Error: failed to fetch https://10.43.0.1:443/static/charts/traefik-20.3.1+up20.3.0.tgz : 404 Not Found

Remove the pre-installed traefik ingress controller

Disable pre-installed traefik on K3s Server Node

vim /etc/systemd/system/k3s.service

ExecStart=/usr/local/bin/k3s \
    server \
        '--server' \
        'https://192.168.1.9:6443' \
        '--disable=traefik' \
        '--node-ip=192.168.1.1' \
        '--node-external-ip=xx.xxx.xxx.xxx' \
        '--flannel-backend=wireguard-native' \
        '--flannel-external-ip' \
        '--datastore-endpoint=postgres://postgres:[email protected]:5432/kubernetes?sslmode=disable' \

After editing the k3s.service, it should be restart the daemon and service

systemctl daemon-reload
systemctl restart k3s

Delete the existing pre-installed traefik resource from the K3s cluster

Delete the helmchart

kubectl delete helmchart traefik -n kube-system
kubectl delete helmchart traefik-crd -n kube-system

Delete the deployment

kubectl delete deployment traefik -n kube-system

Delete related traefik crds

kubectl get crd | grep traefik | while read crd _; do
    kubectl delete crd $crd
done

Delete manifests from the server node

rm -f /var/lib/rancher/k3s/server/manifests/traefik*
rm -f /var/lib/rancher/k3s/server/static/charts/traefik*

Install the external traefik by using helm chart

Add traefik repository

helm repo add traefik https://helm.traefik.io/traefik
helm repo update

Install the traefik

helm install traefik traefik/traefik \
  --namespace kube-system \
  --kubeconfig /etc/rancher/k3s/k3s.yaml

Verify the installation

kubectl get pods -n kube-system --kubeconfig ~/.kube/k3s.yaml | grep traefik
svclb-traefik-8c21d035-fp47d              2/2     Running   0            8m53s
svclb-traefik-8c21d035-5wzx6              2/2     Running   0            8m53s
svclb-traefik-8c21d035-9xhsz              2/2     Running   0            8m53s
svclb-traefik-8c21d035-ghztb              2/2     Running   0            8m53s
svclb-traefik-8c21d035-mrb2f              2/2     Running   0            8m53s
traefik-689d6dcdd4-6rth7                  1/1     Running   0            8m53s
traefik-689d6dcdd4-zfgpx                  1/1     Running   0            8m5s

Reference