asDefault not working how I thought it would?

Trying to use asDefault to shorten my router list.

At the moment I have something akin to the following working:

entryPoints:
  web:
    address: ":80"
    # Redirect all HTTP to HTTPS
    http:
      redirections:
        entryPoint:
          to: websecure
          scheme: https
  websecure:
    address: ":443"

http:
  routers:
    service1:
      rule: "Host(`service1.example.com`)"
      service: "service1"
      entryPoints:
        - "websecure"
    service2:
      rule: "Host(`service2.example.com`)"
      service: "service2"
      entryPoints:
        - "websecure"

I would like to have something like:

entryPoints:
  web:
    address: ":80"
    # Redirect all HTTP to HTTPS
    http:
      redirections:
        entryPoint:
          to: websecure
          scheme: https
  websecure:
    address: ":443"
    asDefault: true

http:
  routers:
    service1:
      rule: "Host(`service1.example.com`)"
      service: "service1"
    service2:
      rule: "Host(`service2.example.com`)"
      service: "service2"

It really is a moot point but when you have 20+ routers it significantly shortens the file.

Is this possible?

Thanks

In Traefik v2 all entrypoints where assigned to routers, unless you specified specific ones for the routers. With Traefik v3 asDefault, only that entrypoint is assigned to a router by default, unless otherwise specified, so you save the part

      entryPoints:
        - "websecure"

Compare to simple Traefik example.

  whoami:
    image: traefik/whoami:v1.8
    networks:
      - proxy
    labels:
      - traefik.enable=true
      - traefik.http.routers.mywhoami.rule=Host(`whoami.example.com`)
      - traefik.http.services.mywhoami.loadbalancer.server.port=80

Note that it seems you are mixing static and dynamic config in your example, those shouldn't be in the same file.

They're not in the same file, I have files: traefik.yaml,routers.yaml, middleware.yaml,services.yaml I only put them in the same snippet for brevity.

I should have included in the OP that when i set websecure as default and remove the entryPoints sections from my routers, the routers do not respect the asDefault. In the web panel you can see they are listening on all available entry points.

Also am not using docker as yet

Works for me (in command:):

--entrypoints.web.address=:80
--entrypoints.web.http.redirections.entrypoint.to=websecure
--entryPoints.web.http.redirections.entrypoint.scheme=https
--entrypoints.websecure.address=:443
--entrypoints.websecure.asDefault=true 
--entrypoints.websecure.http.tls.certresolver=myresolver