How To Create A Windows Containers Cluster

In this blog post, I’ll show you how I create a Windows Containers Cluster with two Container Hosts on Windows Server 2016 Core.

When productize Containers we should think about creating a cluster for HA reasons in case the host goes offline or need to be patched.

Creating a Windows Containers Cluster is not as hard as creating other Clusters like Exchange, SQL, etc, however, you will need to follow the steps below to get it working.

My recommendation is that any host participating in the Cluster should have a static IP address and must run Docker version 1.13.0 or later.

In this lab, I’m using two Windows Server Core 2016 Insider build running as a virtual machine and the latest docker build.

Swarm Mode

In the Docker and Windows Containers, A cluster is called Swarm Mode and it combines features like Clustering, container orchestration capabilities and scheduling of container workloads.

When we group few Container Hosts together we form a “Swarm” cluster that allows us to use the three feature above.

Nodes

A windows Containers cluster consist of two types of nodes:

  • Manager Nodes – This is the main cluster node that all management commands are run from, We can have more than one Manager Node in a Swarm cluster
  • Worker Nodes – Executed tasks that are assigned by the Manager nodes
Firewall Requirements

For Swarm to work the ports below need to be opened and or you can disable the Firewall using the PowerShell cmdlet below.

  • TCP port 2377 for cluster management communications
  • TCP and UDP port 7946 for communication among nodes
  • UDP port 4789 for overlay network traffic

I used the cmdlet below, to disable the Windows Firewall on my two Container Hosts.

Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled false
Create a Swarm Cluster

To create a Swarm Cluster I run the cmdlet below from the host I would like to be the Manager Node.

docker swarm init --advertise-addr=192.168.0.19 --listen-addr 192.168.0.19:2377

As you can see above once the cluster has been created it will return the token key which I will use to add Worker Nodes to the Swarm Cluster.

Add Worker Nodes

Using the token I have received in the previous command, I’ll add a Worker Node using the command below:

docker swarm join --token SWMTKN-1-4xls514s7de3d2jwwqj6nog0mmcs7j7m53zbi1lq44mkipo2zo-5sh77de2iqbb3olbornca2c9u 192.168.0.22:2377

To add another Manager Node I’ll use the command below:

docker swarm join-token manager

To retrieve the token from the Manager Node run the command below:

docker swarm join-token worker -q

To view, all members of the Swarm Cluster and their role run the cmdlet below

Docker node ls

Overlay Network

Once my Swarm Cluster is done, I’ll create a network to support it:

docker network create --driver=overlay swarmnet

Create Service

In Swarm mode, we create containers using a Service, the Service includes a pre-configured image of a web server for example or any other service and the network we created before.

Note: Once we have created the image we should copy it to each of container host.

Below, I’ll create a Swarm Service with a Windows Nano Server 2016 Image (In my case I’ve not used pre-configured the image) and use the Overlay network I created before.

Docker service create -name webapp -endpoint-mode=dnsrr --network=swarmnet microsoft/nanoserver-insider

To view the service run the command below:

Docker service ls

By default, when creating a service, swarm will only deploy one container, If we want and we should to have a few containers across the nodes I’ll create a few containers for my web app.

Docker service scale webapp=4

To view the deployed Containers run the cmdlet below

Docker service ps webapp

To create more than one container with my app I’ll run the cmdlet below

Limitation and conclusion

Docker Swarm can be scaled to 1000+ nodes easily and I don’t think there is a point even finding out the maximum number because of the massive scale of the technology.

Overall, Swarm is an amazing cluster technology that makes the entire HA process easy to scale up and down and achieve high availability.

I strongly recommend using Swarm In any production environment as it will allow a more consistent behaviour and better performance of applications and services hosted in docker.


Posted

in

by