Traefik Helm Chart

repository·master·Indexed 23 days ago

https://github.com/traefik/traefik-helm-chart

Deployment configuration tool for Traefik Proxy in Kubernetes environments. Includes guides for installation via standard Helm repositories or OCI registries, manual CRD updates, and provenance verification. Provides advanced configuration examples for DaemonSet deployments, Horizontal Pod Autoscaling (HPA), KEDA integration, Argo Rollouts, and securing the Traefik dashboard. Also includes migration scripts using yq for transitioning values between chart versions (e.g., v40 to v41) and documentation for hub-manager, a self-hosted control plane for Traefik Hub.

Tokens
25K
Snippets
56
Records
105
Agent score
80%

What's inside traefik-helm-chart

  1. What is Hub Manager

    master

    hub-manager is a self-hosted control plane for Traefik Hub. It allows you to replace the Traefik SaaS platform (platform.hub.traefik.io) by running the control plane inside your own Kubernetes cluster.

    hub-manager stores its state in a PostgreSQL database and is accessed by Traefik instances via a Kubernetes Service. To link Traefik to your hub-manager, you must use an offline license token shared by both components.

  2. Design principles for values.yaml

    master

    The values.yaml file is optimized for user experience rather than strict structural mirroring.

    • The structure of values.yaml does not need to match the final templated configuration if a different structure is more user-friendly.
    • Value names do not need to correspond exactly to the fields in the templates if it improves usability.
  3. Formatting templates and values.yaml

    master

    To maintain a clean and valid Helm chart, follow these whitespace and structure rules:

    • Template Whitespace: Avoid extra whitespace in templates by using whitespace chomping in conditionals. Use the {{- syntax to remove trailing/leading whitespace.
    • Values Structure: In the values.yaml file, separate different feature blocks by including an empty commented line between each primary key.
    {{- if .Values }}
    {{- end }}
  4. Configure Structured Local Plugins

    master

    Traefik supports three ways to manage local plugins via the experimental.localPlugins configuration. This allows you to provide plugin source code directly or via mounted volumes.

    1. Inline Plugin (inlinePlugin)

    Best for small to medium plugins (up to 1MB). You embed the source code directly in your values.yaml. This is secure, portable, and version-controlled with your Helm values.

    2. Host Path Plugin (hostPath)

    Uses a directory on the host filesystem. Warning: This is discouraged for security reasons and requires manual management of plugin sources on every node.

    3. Local Path Plugin (localPath)

    An advanced, flexible method that leverages Kubernetes additionalVolumes. This supports PVCs, CSI drivers (like S3/Azure Blob/GCS), and NFS. It is highly scalable and secure as it uses standard Kubernetes volume mechanisms.

    # Example: Inline Plugin
    experimental:
      localPlugins:
        helloworld-plugin:
          moduleName: github.com/example/helloworldplugin
          mountPath: /plugins-local/src/github.com/example/helloworldplugin
          type: inlinePlugin
          source:
            go.mod: |
              module github.com/example/helloworldplugin
              go 1.23
            .traefik.yml: |
              displayName: Hello World Plugin
              type: middleware
              import: github.com/example/helloworldplugin
            main.go: |
              package helloworldplugin
              import (
                "context"
                "net/http"
              )
              // ... implementation ...
  5. Install Traefik on Azure

    master

    When installing on Azure, you can use a static IP from a specific resource group.

    A common pattern is using Traefik's native Let's Encrypt feature with Azure DNS for the ACME DNS challenge. This requires:

    • Enabling persistence for ACME storage.
    • Configuring certificatesResolvers with the azuredns provider.
    • Setting up environment variables for Azure credentials (AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, etc.).
    • Using an initContainer to ensure correct permissions on the ACME JSON file.
    • Providing an extraObjects Secret containing the Azure client secret.
    service:
      spec:
        loadBalancerIP: "1.2.3.4"
      annotations:
        service.beta.kubernetes.io/azure-load-balancer-resource-group: myResourceGroup
  6. Upgrade Traefik and its CRDs

    master

    When upgrading the Traefik chart, you must manually update the Custom Resource Definitions (CRDs) before running helm upgrade, as Helm does not update CRDs automatically.

    Follow this sequence to upgrade safely:

    1. Update the chart repository.
    2. Check your current chart and Traefik versions.
    3. Update Traefik CRDs using kubectl apply with --server-side.
    4. Update Gateway API CRDs if you are using them.
    5. Run the helm upgrade command.
    # Update the chart repository
    helm repo update
    
    # Check current chart & Traefik version
    helm search repo traefik/traefik
    
    # Update Traefik CRDs
    helm show crds traefik/traefik | kubectl apply --server-side --force-conflicts -f -
    
    # Update Gateway API CRDs, if needed
    kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.5.1/standard-install.yaml
    
    # Upgrade Traefik release
    helm upgrade traefik traefik/traefik
    helm upgrade traefik traefik/traefik
  7. Enable ServiceMonitor for AKS (Azure Monitor)

    master

    To allow managed Prometheus on AKS to scrape Traefik metrics, enable the ServiceMonitor option.

    When using Azure Monitor, set disableAPICheck: true to skip the default CRD check, and specify the correct apiVersion (typically azmonitoring.coreos.com/v1) for both the serviceMonitor and prometheusRule.

    metrics:
      prometheus:
        service:
          enabled: true
        # Set to true when using Azure Monitor to skip the CRD check (monitoring.coreos.com/v1)
        disableAPICheck: true
        serviceMonitor:
          enabled: true
          # Defaults to monitoring.coreos.com/v1
          apiVersion: "azmonitoring.coreos.com/v1"
        prometheusRule:
          # Defaults to monitoring.coreos.com/v1
          apiVersion: "azmonitoring.coreos.com/v1"
  8. Install Traefik on GCP

    master

    You can install Traefik on Google Cloud Platform (GCP) using three different methods depending on your networking requirements:

    1. Regional IP with a Service: Use a static regional IP assigned to the LoadBalancer service.
    2. Global IP on Ingress: Use a global static IP via a Kubernetes Ingress resource.
    3. Global IP on a Gateway: Use the Kubernetes Gateway API with a global external managed gateway and continuous HTTPS encryption.

    Note that for the Gateway API approach, you must include extraObjects to define the Gateway, HTTPRoute, and a HealthCheckPolicy to ensure proper connectivity.

    # Example: Regional IP with a Service
    service:
      spec:
        loadBalancerIP: "1.2.3.4"
  9. Configure custom certificates for Traefik Hub webhooks

    master

    To prevent continuous regeneration of mutating webhooks by CD tools, you can provide a custom certificate for Hub admission webhooks using one of three methods:

    Method 1: Direct Base64 strings in values.yaml

    Generate a self-signed certificate and provide the base64 encoded strings directly.

    hub:
      token: traefik-hub-license
      apimanagement:
        enabled: true
        admission:
          customWebhookCertificate:
            tls.crt: <base64_crt>
            tls.key: <base64_key>

    Note: When using --set via CLI, escape the dots: hub.apimanagement.admission.customWebhookCertificate.tls\.crt.

    Method 2: Using cert-manager CA injector

    Use annotations to allow cert-manager to inject the CA from a specific certificate resource.

    hub:
      token: traefik-hub-license
      apimanagement:
        enabled: true
        admission:
          selfManagedCertificate: true
          secretName: admission-tls
          annotations:
            cert-manager.io/inject-ca-from: traefik/admission-tls

    Method 3: Using an existing Kubernetes Secret

    If you have a certificate stored in a managed secret, enable selfManagedCertificate.

    hub:
      apimanagement:
        admission:
          selfManagedCertificate: true
  10. How to load local plugins for development

    master

    To test or develop plugins locally without a public registry, you can load them from your filesystem.

    Warning: The legacy hostPath configuration is deprecated. You should use the structured experimental.localPlugins.<name>.type configuration instead.

    # Legacy Configuration (DEPRECATED)
    experimental:
      localPlugins:
        legacy-demo:
          moduleName: github.com/traefik/legacydemo
          mountPath: /plugins-local/src/github.com/traefik/legacydemo
          hostPath: /path/to/plugin-source  # ⚠️ Deprecated - use type: hostPath instead
  11. Access Traefik dashboard via port-forward

    master

    The dashboard is not exposed by default. To access it locally without exposing it to the internet:

    1. Enable the dashboard IngressRoute in your values:
      ingressRoute:
      dashboard:
       enabled: true
    2. Use `kubectl port-forward` to tunnel the admin port (8080) to your local machine.
    
    NAMESPACE=traefik
    kubectl port-forward $(kubectl get pods --selector "app.kubernetes.io/name=traefik" --output=name -n $NAMESPACE) 8080:8080 -n $NAMESPACE

    Access it at: http://127.0.0.1:8080/dashboard/ (Note: the trailing slash is required).

  12. Configure Local Path Plugins using additionalVolumes

    master

    To use the localPath plugin type, you must first define the volume in deployment.additionalVolumes and then reference it in experimental.localPlugins using the volumeName key.

    deployment:
      additionalVolumes:
        - name: plugin-storage
          persistentVolumeClaim:
            claimName: plugin-storage-pvc
    
    experimental:
      localPlugins:
        s3-plugin:
          moduleName: github.com/example/s3plugin
          mountPath: /plugins-local/src/github.com/example/s3plugin
          type: localPath
          volumeName: plugin-storage
          subPath: plugins/s3plugin