Customize Traefik chart on K3s
Overriding values for packaged components on K3s
K3s is a lightweight Kubernetes distribution that packs default components as HELM charts, Traefik for example.
According to the documentation, to allow overriding values for packaged components that are deployed as HelmCharts (such as Traefik), K3s versions starting with v1.19.0+k3s1 support customizing deployments via a HelmChartConfig resources. The HelmChartConfig resource must match the name and namespace of its corresponding HelmChart, and supports providing additional valuesContent, which is passed to the helm command as an additional value file.
Example: Enable Traefik Prometheus metrics on K3s
Create the file /var/lib/rancher/k3s/server/manifests/traefik-config.yaml on K3s host. To make it easier you can take the traefik.yaml file contents as a example and customize it as necessary.
apiVersion: helm.cattle.io/v1
kind: HelmChartConfig
metadata:
name: traefik
namespace: kube-system
spec:
valuesContent: |-
rbac:
enabled: true
ports:
websecure:
tls:
enabled: true
additionalArguments:
- "--metrics.prometheus=true"
podAnnotations:
prometheus.io/port: "8082"
prometheus.io/scrape: "true"
providers:
kubernetesIngress:
publishedService:
enabled: true
priorityClassName: "system-cluster-critical"
image:
name: "rancher/library-traefik"
tolerations:
- key: "CriticalAddonsOnly"
operator: "Exists"
- key: "node-role.kubernetes.io/control-plane"
operator: "Exists"
effect: "NoSchedule"
- key: "node-role.kubernetes.io/master"
operator: "Exists"
effect: "NoSchedule"
In this case we added the additional argument "--metrics.prometheus=true" which will enable the /metrics endpoint on Traefik with prometheus format. You can provide any other values from the Traefik Helm chart .
Once K3s applies it, you can confirm if the changes took place in the Dashboard.


