When a node is shut down in a Docker Swarm, you can reduce the number of nodes while maintaining the availability of services by following these steps:
Move the running services from the stopped node to another node. Use the command
docker service update --move <service-name>to move the services to another node.
After the services have been moved, remove the stopped node from the Docker Swarm with the command
docker node rm <node-name>.
Start the services again to maintain service availability. Use the command
docker service update --force <service-name>to start the services again.
By following these steps, you can reduce the number of nodes while maintaining the availability of services. However, depending on the state of the services, availability may be temporarily reduced, so be careful. Also, it is recommended to back up before performing the above steps.