How do I create a route that is specific for a subdomain? I'm looking to create a "subdomain" path to my custom controller running on a Drupal 8 site, with routing and hopefully without the need for an additional module.

The idea is to for example have a route like account.example.com or dev.example.com point to a custom controller I've made in my module. Or a path like api.example.com for external REST queries.

All the documentation describe just the traditional example.com/path methods, and googling resulted to nothing, but the domain module, which seems excessive and maybe for a different purpose even.

What I wish to achieve is not a separate installation sharing the content, but just a path to my controller that is domain-specific, like the i18n module is able to provide the language parameter as subdomain or path prefix.
If you want to set a controller for subdomain you just create a subdomain and handle it by DNS and web server, then set your subdomain path as root path for the subdomain on your web server, I mean both main domain and subdomain will be the same. As you said, you can create a route/controller for them (because the code and modules are the same, so routes will be available on both).

If you don't want the subdomains available on your main domain, on your handler check the domain name; if a request comes from the main domain, don't return the result for it. (Redirecting it to the homepage could be an idea.)

But the power of Symfony shows itself to us: Instead of manually handling the domain and subdomain filtering on the route, use host in the route definition.    

   host: "dev.example.com"


Take a look at How to Match a Route Based on the Host for further help about using that directive.