Docker Swarm on Hetzner Cloud in 3 Steps
4 Minuten Lesezeit

Docker Swarm on Hetzner Cloud in 3 Steps

Step-by-step guide to creating a Docker Swarm cluster with 3 master and 3 worker nodes on Hetzner Cloud and installing and using Portainer
docker-swarm hetzner

With ayedo, running your apps in Kubernetes is a breeze. With Docker Swarm, we offer a production-ready alternative to Kubernetes for those who are comfortable with Docker’s abstractions but need more availability and scalability. With the ayedo Fleet Custom Edition, you can enjoy Docker Swarm without the operational headaches. Try it out.

Docker Swarm on Hetzner Cloud

We love Kubernetes. It’s just our thing. Nevertheless, many companies still rely on Docker Swarm for orchestrating their container workloads, and rightly so. Docker Swarm is less flexible than Kubernetes in many ways, but definitely less complex—making it the ideal candidate for beginners in the world of distributed container workloads. Docker Swarm extends the syntax and semantics of the already familiar Docker commands with a concept of Services and Stacks to make replicated workloads jointly manageable.

For those who, like us, work a lot with docker-compose, transitioning from Docker Standalone to Docker Swarm’s stacks will be easy—stack files are just compose files with slightly different syntax. This relatively flat learning curve not only facilitates the entry into scalable microservice architectures but also serves as an ideal preparation if you aim to switch to Kubernetes.

Besides the short adaptation phase when transitioning from Docker Standalone to Docker Swarm, operational stability also speaks for Docker Swarm. Especially for stateless workloads, a Docker Swarm cluster is often preferable to a Kubernetes cluster due to the low complexity of the setup and the general stability and maturity of Docker primitives.

Introduction

In today’s technology-driven world, containerizing applications is an important step towards flexibility and scalability. Docker Swarm is a container orchestration platform that allows developers to run and manage Docker containers in a cluster. It enables the management of containers on distributed systems and is a great solution for scalability and high availability when Kubernetes is simply too much.

In this blog post, we will show you how to create a Docker Swarm cluster with 3 master and 3 worker nodes on Hetzner Cloud and then install Portainer to conveniently manage the swarm through a modern web interface.

Step 1: Creating the Virtual Machines (VMs)

  1. If you don’t have one yet, create an account in the Hetzner Cloud.
  2. Log in to Hetzner Cloud and go to the dashboard.
  3. Click on “Projects” and then “Create New Project” to create a new project.
  4. Enter a project name and click “Create Project”.
  5. In the new project, click on “Servers” and then “Create Server”.
  6. Select “Ubuntu 22.04” as the operating system and enter a name for the master node.
  7. Repeat steps 4 and 5 two more times to create two additional master nodes.
  8. Repeat steps 4 to 5 three more times to create the worker nodes.

Step 2: Configuring the VMs and Creating the Swarm Cluster

  1. Open a terminal or command line and connect to one of the master nodes (SSH). You received the credentials for the node via email from Hetzner.
  2. Install Docker on the master node:
apt update
curl -fsSL https://get.docker.com -o get-docker.sh 
sh get-docker.sh
usermod -aG docker $USER
systemctl start docker
systemctl enable docker
  1. Repeat steps 1 and 2 for the other nodes until Docker is installed on all nodes.
  2. Go back to the first master node and initialize the swarm cluster with the following command. Docker will output a command that needs to be executed on the worker nodes to join them to the swarm.
docker swarm init --advertise-addr <IP-address-of-master-node>
  1. Now execute the following command on the first master. This generates another join command to add master nodes to the cluster.
docker swarm join-token manager
  1. Copy the generated command to add master nodes to the cluster and switch to the second master node. Execute the copied command there:
docker swarm join --token <Master-Join-Token> <IP-address-of-master-node>
  1. Repeat step 6 for the remaining master node.
  2. Switch to one of the worker nodes and execute the command to add worker nodes to the cluster that you copied earlier:
docker swarm join --token <Master-Join-Token> <IP-address-of-master-node>
  1. Repeat step 8 for the other two worker nodes.

Step 3: Installing and Setting Up Portainer

  1. Switch to any master node in your swarm cluster.
  2. Install Portainer:
curl -L https://downloads.portainer.io/ce2-18/portainer-agent-stack.yml -o portainer-agent-stack.yml
docker stack deploy -c portainer-agent-stack.yml portainer
  1. Open a web browser and enter the IP address of the master node followed by port 9443 (e.g., https://<IP-address-of-master-node>:9443).
  2. Follow the setup wizard for setting up Docker Swarm and an admin user for Portainer.
  3. Portainer is now ready to manage your Docker containers and services. You can upload container images, start and stop containers, create volumes, and much more.

Conclusion

Creating a Docker Swarm cluster with 3 master and 3 worker nodes on Hetzner Cloud is a powerful way to orchestrate and scale container applications cost-effectively. Using Portainer as a graphical user interface significantly simplifies container management and provides developers with an intuitive way to monitor and control their applications. Use this guide to optimize your development and deployment processes and benefit from the advantages of containerization.

Ähnliche Artikel