TRAEFIK v2 (Part 2)

HTTP HTTPS redirect with Traefik v2

Once you have setup Traefik running in your Kubernetes cluster, you might want to configure additional thing like http to https redirect. For more information about the Traefik setup check part 1. More information about routing entryPoints can be found on the Traefik official website: https://docs.traefik.io/routing/entrypoints/#redirection.

If you would like to redirect all http traffic to https you easily do this in the values.yaml file we’ve used in part 1 in the Configure ports section. In this section you see two entrypoints web and websecure. To redirect all traffic from web to websecure simply add redirectTo: websecure in the web section of the values.yaml.

# Configure ports
ports:
  web:
    port: 8000
    expose: true
    exposedPort: 80
    protocol: TCP
    # https://docs.traefik.io/routing/entrypoints/#redirection
    redirectTo: websecure
  websecure:
    port: 4443
    expose: true
    exposedPort: 443
    protocol: TCP

After updating the values.yaml you have to update the helm deployment:

helm upgrade --namespace=traefik --values=values.yaml traefik traefik/traefik

After the update the entryPoint for the IngressRoute needs to be updated, as the old configuration has the entryPoint web defined, instead of websecure. Apply the updated IngressRoute by:

kubectl apply -f ingressroute.yaml

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: ingress-app1
  namespace: app1
spec:
  entryPoints:
    - websecure
  routes:
  - match: Host(`www.cloudt.it`)
    kind: Rule
    services:
    - name: app1-service
      port: 80

After applying the new IngressRoute all http traffic will redirect to https.

1 thought on “TRAEFIK v2 (Part 2)

Leave a Reply

Your email address will not be published.

Scroll Up