"So you want to get to know Azure?..."
How to deploy a Docker Swarm Cluster
"So you want to get to know Azure?..."

"So you want to get to know Azure?..." How to deploy a Docker Swarm Cluster

I am writing a new series of articles (1 a week) that will help you to explore the Microsoft Azure platform. The whole series is called "So you want to get to know Azure?...". These articles will cover a wide variety of topics from the most basic to the most advanced aspects of Azure. Feel free to use them to enhance your Azure experience! - Good Luck and may Azure be with you always....

Article #8 week of 3/26/18

======================================================

NOTE: This article assumes that you already have an Azure Subscription that is active and available. If you do not, go here:

https://azure.microsoft.com/en-us/free/

Follow the instructions to create a free account and begin using Azure.

======================================================

Prerequisites

In this article I will be using a Windows 10 machine to accomplish all the steps involved with creating the Swarm Cluster. As a result, I will be running the following three tools in Windows:

1.    Azure CLI

2.    Git for Windows (GitBash)

3.    Docker for Windows

This article requires that you are running the Azure CLI version 2.0.4 or later. Run az --version to find the version. If you need to install or upgrade, see Install Azure CLI 2.0.

You can download and install Git for Windows from here: https://git-scm.com/download/win

 You can download and install Docker from here: https://docs.docker.com/docker-for-windows/install/

Note: If you need some help getting Docker installed and running, check out the first part of my article below on the Azure IoT Edge Device Function. I walk you through how to install Docker:

https://www.dhirubhai.net/pulse/so-you-want-get-know-azure-using-iot-edge-device-function-adam-gordon/

 ===================================================================

Note: Run the following commands from Azure CLI

Connect Azure ClI to Azure portal using the az login command:

Assuming that you have installed Azure CLI into Windows as noted above, you will open a Windows Command Prompt with "Run as Administrator" privileges. When you run the az login command, you will get the following: (DO NOT close the Command Prompt window !!)

Go to the URL listed in the yellow text: https://microsoft.com/devicelogin and enter the alphanumeric code provided:

Once you see the screen above, you may close the browser window and return back to the Command Prompt window, where you should see something similar to the following: (I have two Azure subscriptions, whereas you may only see one).

Create a resource group:

Create a resource group with the az group create command. An Azure resource group is a logical group in which Azure resources are deployed and managed.

The following example creates a resource group named DSC in the westus location.

az group create --name DSC --location westus

Create a Docker Swarm cluster:

Create a Docker Swarm cluster in Azure Container Service with the az acs create command.

The following example creates a cluster named DSwarmCluster with one Linux master node and three Linux agent nodes.

az acs create --name DSwarmCluster --orchestrator-type Swarm --resource-group DSC --generate-ssh-keys

Note: In some cases, such as with a limited trial, an Azure subscription has limited access to Azure resources. If the deployment fails due to limited available cpu cores, reduce the default agent count by adding --agent-count 1 to the az acs create command.

After several minutes, the command completes and returns json formatted information about the cluster.

Connect to the cluster:

Throughout the remainder of this article, you need the IP address of both the Docker Swarm Master and the Docker Agent Pool. Run the following command to return both IP addresses:

az network public-ip list --resource-group DSC --query "[*].{Name:name,IPAddress:ipAddress}" -o table

Note: Run the following commands from the Git for Windows (GitBash) shell

Create an SSH tunnel to the Swarm Master. Replace IPAddress with the IP address of the Swarm Master.

ssh -p 2200 -fNL 2375:localhost:2375 azureuser@IPAddress

Set the DOCKER_HOST environment variable. This allows you to run Docker commands against the Docker Swarm without having to specify the name of the host.

export DOCKER_HOST=:2375

 You are now ready to run Docker services on the Docker Swarm Cluster.

 Run the application:

Create a file named docker-compose.yaml and copy the following content into it. You can create the file using any text editor. I created the file in Notepad and saved it to the Documents folder in Windows.

yaml Copy 
version: '3'
services:
  azure-vote-back:
    image: redis
    container_name: azure-vote-back
    ports:
        - "6379:6379"
 
  azure-vote-front:
    image: microsoft/azure-vote-front:v1
    container_name: azure-vote-front
    environment:
      REDIS: azure-vote-back
    ports:
        - "80:80"


Run the following command to create the Azure Vote service. Make sure that you change to the directory where you saved the dcoker-compose.yaml file BEFORE you run the command.

docker-compose up -d

Test the application:

Browse to the IP address of the Swarm Agent Pool to test out the Azure Vote application.

If you want to see what you have created in the Azure portal, log in and go to the DSC resource group and you will see the following:

Delete the Swarm Cluster:

When the cluster is no longer needed, you can use the az group delete command to remove the resource group, container service, and all related resources.

az group delete --name DSC --yes --no-wait

Good Luck...

You can follow me on Twitter: @Adam_ITProTV

要查看或添加评论,请登录

Adam Gordon的更多文章

社区洞察

其他会员也浏览了