Skip to content

fix: Update to Traefik v3, make Let's Encrypt work with Traefik, fixes #6183, for #5940, fixes #4632 - #6317

Merged
rfay merged 59 commits into
ddev:masterfrom
rfay:20240616_traefik_3
Jul 3, 2024
Merged

rfay merged 59 commits into
ddev:masterfrom
rfay:20240616_traefik_3

Conversation

@rfay

@rfay rfay commented Jun 17, 2024 •

Copy link
Copy Markdown
Member

The Issue

How This PR Solves The Issue

  • Update to v3 of traefik
  • Make Let's Encrypt work with Traefik

TODO

  • When use_letsencrypt we have to delete the default certs
  • Generated .gitignore should detect traefik configuration that has had #ddev-generated removed
  • Consider looking at changed Traefik v3 config directives and updating them.
  • Review generated project-level configs for accuracy. Can the routers or services be consolidated?
  • Review how push to volume happens. Do we need to empty some things before push?
  • We should be able to have just the one http service, not http + https
  • Verify DNS challenge docs
  • Add suggested summaries in each section of the traefik doc
  • static_config.yaml either must be off-limits for custom configuration, or entryPoints has to be managed elsewhere and merged into it.
  • Since static_config.yaml can't really safely be edited, certificateResolvers should be in there by default for Let's Encrypt
  • Since static_config.yaml can't really be safely edited, changing it for the Let's Encrypt DNS challenge isn't going to be a win I don't think. Or perhaps it can just have a different name and be included by default.
  • docs need to say that we're using Traefik v2 syntax
  • docs: Consider mentioning that additional files can be added in .ddev/traefik/config; filenames must be unique (base on project name) and stanza names must be unique (base on project name).
  • Support Traefik plugins in static_config.yaml

Followups

  • Try to merge static_config instead of appending. Traefik is unforgiving about this with static config, even though it's not bad with dynamic config.
  • After that is solved, add information back to docs about using the Let's Encrypt staging server

Manual Testing Instructions

  • Start by pulling latest traefik image: docker pull ddev/ddev-traefik-router:20240616_traefik_3

  • General Usage

    • Try basic use and see if things work
    • Add add-ons and check that all the ports referenced in them work correctly, including http and https ports. For example try ddev get ddev/ddev-solr and see that solr UI works right.
  • Inspect the created configuration files

    • When doing an add-on or whatever above, review the project-generated files in .ddev/traefik/config to see if they make sense.
    • Edit a file to add new behaviors like redirect or adding a header with middleware. ddev restart and verify it works (have to remove #ddev-generated). Don't forget to remove the file then so it will be recreated.
  • Try out casual hosting with this PR

  • Try out dnsChallenge docs with traefik (this worked for me, but may not be useful to pursue. It does require extra capabilities and permissions on the DNS setup)

Traefik configuration docs at https://ddev--6317.org.readthedocs.build/en/6317/users/extend/traefik-router/
Casual hosting docs at https://ddev--6317.org.readthedocs.build/en/6317/users/topics/hosting/

Automated Testing Overview

There isn't currently testing for Casual hosting
I think the existing tests will catch problems with traefik v3. I imagine there will be some

Release/Deployment Notes

  • Customized Traefik rules will likely be affected by this PR and may have to be adjusted.
  • Traefik is updated to v3 but still uses v2 configuration

@github-actions github-actions Bot added bugfix dependencies Pull requests that update a dependency file labels Jun 17, 2024
@github-actions

github-actions Bot commented Jun 17, 2024 •

Copy link
Copy Markdown

@rfay
rfay force-pushed the 20240616_traefik_3 branch from 9637947 to 306d1a8 Compare June 17, 2024 22:09
@rfay
rfay marked this pull request as ready for review June 18, 2024 03:40
@rfay
rfay requested review from a team as code owners June 18, 2024 03:40
@rfay
rfay requested a review from stasadev June 18, 2024 03:41
@rfay
rfay force-pushed the 20240616_traefik_3 branch from 40ec3c8 to 89999bc Compare June 19, 2024 01:25
Comment thread docs/content/users/topics/hosting.md Resolved
Comment thread docs/content/users/topics/hosting.md Resolved
@rfay
rfay force-pushed the 20240616_traefik_3 branch from b3e00b6 to b78eb42 Compare June 19, 2024 11:25
@rfay
rfay force-pushed the 20240616_traefik_3 branch 3 times, most recently from df0a3cb to bcfe8a8 Compare June 21, 2024 20:45
@rfay
rfay requested a review from stasadev June 25, 2024 00:04

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

I think we could mention here that nginx-proxy is deprecated:

DDEV uses Traefik by default unless you configure the traditional router by running `ddev poweroff && ddev config global --router=nginx-proxy`.

@rfay
rfay force-pushed the 20240616_traefik_3 branch from cc06c46 to 20af094 Compare June 27, 2024 19:20
@rfay

rfay commented Jun 27, 2024

Copy link
Copy Markdown
Member Author

Added more of a deprecation notice and rebased.

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!
I tested the casual hosting feature, everything worked as intended.

# Router Customization and Debugging (Traefik)

Traefik is the default router in DDEV v1.22+.
Traefik is the default router in DDEV v1.22+. The older `nginx-proxy` router is deprecated and will be removed in DDEV v1.24.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could have a separate page for such information.
Same as https://goreleaser.com/deprecations/

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only other things I remember us deprecating are

  • disable-http2, which goes away with traefik
  • nginx-proxy

I tried for years to deprecate traditional Windows, but always got significant pushback. And now it works really quite well, amazingly.

Let's do as you say when we get this ready for v1.24.

Traefik provides a dynamic description of its configuration you can visit at `http://localhost:10999`.
When things seem to be going wrong, run [`ddev poweroff`](../usage/commands.md#poweroff) and then start your project again by running [`ddev start`](../usage/commands.md#start). Examine the router’s logs to see what the Traefik daemon is doing (or failing at) by running `docker logs ddev-router` or `docker logs -f ddev-router`.

## Router `docker-compose` Customization

@nickchomey nickchomey Jun 27, 2024 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this section should be moved up higher in this doc - surely before Project Config, and maybe even before Global Config, since it pertains to the construction of the global ddev router?

Also, which file ultimately gets created as a result of this merging of ~/.ddev/router-compose.*.yaml files? ~/.ddev/.router-compose-full.yaml?

And perhaps another example can be provided that does more than just modify environment variables, so as to point out the broader possibilities this might have? I dont have the faintest idea of why I might want to learn about and mess with this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very unusual thing to do. I don't agree that it needs more prominence. Can you think of anything to do with it?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just suggesting this so as to put the sections/headings in a sort of logical order - most fundamental/first to be executed -> last to be executed. But feel free to ignore this.


DDEV uses Traefik by default unless you configure the traditional router by running `ddev poweroff && ddev config global --router=nginx-proxy`.
DDEV uses Traefik by default unless you configure the (deprecated) `nginx-proxy` router by running `ddev poweroff && ddev config global --router=nginx-proxy`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be beneficial to briefly point out up-front what each configuration does.

It should be made clear that ~/.ddev/router-compose.*.yaml files merge to generate ~/.ddev/.router-compose-full.yaml, which is then used by docker compose to create the ddev-router container.

This traefik doc seems more pertinent to our doc than the main traefik docs landing page. https://doc.traefik.io/traefik/getting-started/configuration-overview/

static_config.yaml then gets read once by traefik while starting up to define the global configuration, and requires a full restart if you modify it.

<project>.yaml then defines each project.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have to do with the line you put the comment on, or is it just a general comment?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comment aimed around that introductory part of the doc. I didnt seem able to add a comment below it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to improve the intro to each section.

entrypoints:
- http-{{$s.ExternalPort}}
{{ end }}
{{ end }}{{ end }}

@nickchomey nickchomey Jun 28, 2024 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably put the middleware placeholder here for the 443 and 8026 ports

# middlewares:
      #   - "redirectHttps"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we redirect for 443 or 8026?

@nickchomey nickchomey Jun 28, 2024 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha, i didnt even pay attention to it being redirecthttps. I just noticed that the middleware: heading was missing, as I had to add it for my own middleware plugins

Perhaps just add middleware: without being commented-out (unless it fails when you have a heading without any middleware configured), so that its clear where to add our own

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my assumption is that this is pretty rare, and that somebody who has gotten this far will understand what they might be able to do with middlewares

@nickchomey

nickchomey commented Jun 28, 2024 •

Copy link
Copy Markdown
Collaborator

Everything seems to be working well for me - my traefik middleware plugins work, etc...

HOWEVER, I cant seem to use additional_hostnames or additional_fqdns with this. With both, i get this error in the traefik dashboard

error while adding rule HostRegexp(`new1.ddev.site`, `asdf.ddev.site`): error while adding rule HostRegexp: unexpected number of parameters; got 2, expected one of [1]

image

@rfay

rfay commented Jun 28, 2024

Copy link
Copy Markdown
Member Author

Wow, can't believe we don't have tests for additional_hostnames, etc. Great catch, will take a look @nickchomey

@rfay

rfay commented Jun 28, 2024 •

Copy link
Copy Markdown
Member Author

@nickchomey could you please give more details about how to recreate the failure you saw with additional_hostnames and additional_fqdns?

How was it manifested? Where did you make changes? Was this after a ddev restart? Did the ddev restart fail?

I have this situation:

additional_hostnames:
    - one
    - two
    - three
additional_fqdns:
    - a.example.com
    - b.example.com

and all of the URLs work, I don't see errors in the traefik dashboard... (But if there were errors, they should have broken ddev restart ... ?)

image

Recreate with ddev config --additional-hostnames=one,two-three --additional-fqdns=a.example.com,b.example.com && ddev restart

Please use a trivial project or unmodified project to recreate.

Did you perhaps do this?

additional_hostnames:
    - new1
    - asdf
additional_fqdns:
    - new1.ddev.site
    - asdf.ddev.site

That's certainly not supported, if that's what you did I don't know if it's reasonable to try to error-check it.

@rfay
rfay force-pushed the 20240616_traefik_3 branch from 1276baf to 170186c Compare July 3, 2024 03:38
@rfay

rfay commented Jul 3, 2024

Copy link
Copy Markdown
Member Author

Rebased and pushed updated traefik router. If things are OK in the morning will pull and then we can work Nick's PR to this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants