I am using Caddy 2 on Windows Server 2019. I love the power of Caddy!
However, I have a question. I am a DevOps guy and using Caddy to load balance an application. In my release process, I essentially want to drain a node from Caddy and the nrelease to the server and restart it.
The caddy API is not granular in that it can remove/add nodes. Is the only way to do this to supply an updated config file? So essentially, I use c# or powershell to modify the config file (remove the node), save it, and then upload that?
You can actually amend the array without having the POST full new config, just PATCH the respective path. Your API request can traverse the config JSON to make amendments or GET specific values. See the doc about PATCH, PUT, and DELETE here:
If you have any long-running connections (like websockets, or long-polling/SSE, or downloads that take a long time) then the reload will hang until these are done (in the case of websockets, I don’t think it’ll ever be “done” so it may hang indefinitely) unless you set the grace_period config option which is a timeout after which Caddy will explicitly cancel any remaining connections to allow the shutdown of the old config to complete.
Currently, yes that’s the only way.
But we’re working on a rewrite of the reverse_proxy module to add support for “dynamic upstream” modules. This might make it possible to implement a module that can provide an admin API endpoint to add/remove nodes. We won’t have plans for such a module to be included in Caddy’s standard distribution yet, but it might come later. A third party plugin is possible.
On the reloading methodology, that is ok. The apps I am using don’t use web sockets, but anything is possible.
I have built a cicd process for my caddy files, so my build server does a validate on them and then they get pushed to my deployment tool and dropped onto a folder. I don’t want to put ip addresses in source control so I may use variable substitution for the ip addresses, and then my deployment tool can put in the hosts. I may go this way with editing the file as opposed to using the API.