How to manage a Docker Swarm with Portainer

[ad_1]

Jack Wallen shows you how easy it is to manage a Docker Swarm deployment with the Portainer web-based GUI.

Programmer smiling at desk.
Image: BalanceFormCreative/Adobe Stock

I’ve said this many times before, and I’ll say it many times in the future: Portainer is my go-to container management platform. With Portainer, I can do any task required to manage and monitor container deployments. I can use Portainer on an isolated docker development machine or a multi-node Swarm Cluster.

Wait. Did I just say multi-node Swarm Cluster? I did.

If your Docker deployments are of a large-scale nature, chances are pretty good you’re dealing with a Docker Swarm. For those who don’t know, Swarm mode is built into the Docker Engine and allows you to manage a cluster of Docker nodes for more scalability, decentralized deployments, desired state reconciliations, multi-host networking, load balancing and rolling updates.

In other words, if your container deployments need to meet higher demands, you’re probably using Docker Swarm. And the good news is you can manage your Swarm right from Portainer.

SEE: Hiring kit: Back-end Developer (TechRepublic Premium)

Now, if you haven’t already deployed Portainer, make sure to check out How to deploy the Portainer container management tool with persistent storage before continuing on. You’ll want to make sure to deploy Portainer on your controlling node and make sure to use the Agent option when creating a new Docker Environment (Figure A).

Figure A

Creating a new Swarm Environment in Portainer.

Once you’ve created your new Environment, it should show up in your Environments listing (Figure B).

Figure B

My Docker Swarm Environment is found in Portainer.

How to manage your Docker Swarm from Portainer

With your Docker Swarm Environment up and running, select it and you should see the Swarm entry in the left sidebar (Figure C).

Figure C

The Swarm entry in Portainer’s left navigation.

Click that entry and you’ll see two sections: Cluster Status and Nodes (Figure D).

Figure D

My Swarm Cluster overview as seen in Portainer.

Let’s take a look at our dockercontroller node. Click that entry to reveal the details (Figure E).

Figure E

The details for my Docker Swarm controller node.

As you can see, there isn’t a great deal of items you can control. What you can do is set the availability of the node (from Active, Pause, Drain) and add labels, which are metadata that describes the node.

As to the availability, here are the descriptions:

  • Active: A node is active and is available for the scheduler to assign tasks.
  • Pause: A node is up but the scheduler cannot assign new tasks to this node although existing tasks will remain running.
  • Drain: A node is up but the scheduler cannot assign new tasks and will shut down all existing tasks, assigning them to other nodes.

The Availability option is a very handy way to manage individual nodes. You might need to replace a node. Instead of just stopping it, you should drain it so all tasks are reassigned. You can then deploy the new node and set it as active.

Use labels as a handy method of organizing your swarm. For example, say node 1 is a Ubuntu server, and node 2 is an AlmaLinux server. Head over to the first node (which, for our example, is hosted on Ubuntu Server) and click + Label. In the resulting window, type os for name and Ubuntu Server for value (Figure F).

Figure F

Adding our first label to a Swarm node in Portainer.

You can add as many labels as you like.

Resolving a confusing error

When I first started working with Docker Swarm and Portainer, I discovered a confusing error that took me some time to resolve. When I’d attempt to make any change to a Swarm Node, I’d receive the error:

rpc error: code = Unknown desc

Even after restarting every node in the Swarm, I wound up with the same error. On a whim, I checked the time on each server, only to discover that node1 and node2 were configured for different time zones. Because of that, the Swarm nodes had trouble communicating with one another. To fix that problem, I logged into the nodes and ran the command:

sudo timedatectl set-timezone ZONE

Where ZONE is the correct timezone for my area which can be found with the command:

cat /etc/timezone

Once you’ve made sure the time zones are correct for each node, that error should go away and you can label your nodes as needed and set their Availability.

Of course, you can also scale your deployments within your Swarm with Portainer. To find out how this is done, check out my tutorial How to scale service deployments with Portainer.

And that’s all there is to managing your Docker Swarm with Portainer. This platform is a remarkable solution for anyone looking to make managing Docker container deployments a much easier and more efficient process.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.

[ad_2]

Source link