Create SSH endpoint to connect Docker Swarm running in Azure


This is the continuation of Continuous Deployment of Multi-Container app in Azure using VSTS and Docker. So far we have covered following topics

  • Part 1 – Overview of different tools and technologies we will be using during this series
  • Part 2 – Setup VSTS Continuous Integration (CI) build for DotNet Core 2.1 multi-container app
  • Part 3 – Integrate DockerHub container registry with VSTS CI build to publish Docker images
  • Part 4 – Provision Docker Swarm cluster in Azure using ACS Engine

This short post is about creating a SSH endpoint between the VSTS hosted agent and Master node in Docker Swarm. The SSH endpoint will enable us to execute bash scripts on the Swarm master node.

Create new SSH Endpoint

Login to the VSTS account and select the Docker-CI-CD-Azure build definition we created earlier in part 2. Click on the Services menu. We already have endpoints established to DockerHub and GitHub accounts. Click on the New Service Endpoint as shown below

New Service Endpoint

VSTS can connect to different services like BitBucket, GitHub, Subversion, NuGet etc. Once the endpoints are established they can be reused within different tasks or steps during the build and release pipelines. We have already seen an example of this during the usage of DockerHub tasks in part 3 of this series. Select SSH from the drop down to bring up the dialog box for configuring the connection properties.

SSH endpoint

The properties in the configuration section are self explanatory. We start off by giving a meaningful name SwarmSSH for connection. Hostname is the FQDN of the Swam Master node. This is the same we used during part 4 after the cluster was provisioned. In my case the name is

Port number is very important. By default the SSH port is 22. But ACS Engine exposes 2200 as the port for SSH connectivity. Make sure to update the port number to 2200 instead of 22.

User name is what we specified as the Linux Admin user while provisioning the Swarm cluster. In my case it was swarmadmin.

Password or passphrase is related to the SSH keypair that was generated using the keygen command. Last parameter is the Private Key.

New SSH connection

We need to paste the contents of private key similar to the way we had specified public key during cluster creation. We can either use our favorite editor to copy & paste the contents of id_rsa file in .ssh folder or upload the file. I chose to upload it. If you use the copy & paste method, make sure to paste the complete file contents including -----BEGIN RSA PRIVATE KEY----

id_rsa private key

With all the parameters set we are ready to submit commands to the Master node in Swarm cluster. As part of our release steps we will need to copy files from the VSTS published artifacts to Master node and login to the DockerHub account using command line.

Once successfully connected we will run the deployment script which will instantiate the docker images and start the container services by running the docker stack deploy command.  For all these activities we need the SSH connectivity. In the next post we will see how to use these features. Until next time code with passion and strive for excellence.


No comments:

Post a Comment