Comment on page
Create and bootstrap a multi-host track
This guide explains how to create and bootstrap a track with multiple hosts.
You can give a learner access to multiple hosts within a single track—such as a Docker container host and a Kubernetes virtual machine host for scenarios where your software is cluster-based or you need load balancing.
The point of interest in a multi-host track is the track setup script execution, as each host has its own setup script. And the Instruqt platform runs the track setup scripts sequentially in order of alphanumerically sorted hostnames. If you want to run setup scripts parallel on all hosts, see the Bootstrap a multi-host track section for orchestrating the setup from the track setup script on the first host and use Secure Shell (SSH) to run a script on another host.
Now let's see how you create a multi-host track.
The easiest way to create a multi-host track is to start with a single host track and add one or more hosts to that track. Here you will start with a
debian
container and then add a g1-small
virtual machine.🌐 Web UI
💻 Instruqt CLI
- 1.
- 2.Click Create track on the Content page. Select Use template from the dropdown. ↳ The Instruqt templates page opens.
- 3.Select the Sandbox container template. ↳ The Track info pop-up opens.
- 4.In the Track title field, enter your title.
- 5.In the Track slug field, modify the slug if you want to.
- 6.Click Create. ↳ Instruqt creates the single host track and shows the Track dashboard page.
- 1.Type the following command to create a track:instruqt track create
- 2.Enter the track title:==> Track title: TRACK_TITLE
- 3.Enter option 2 to select
From a template
:==> Start with an empty track or use a template:[1] From scratchFor full flexibility, start with an empty track[2] From a templateTo get started quickly, start from one of our templatesPlease select your method: 2 - 4.Enter the number of the template you want to use:==> Choose a template:[1] AWS Cloud AccountLearn how to build tracks with an AWS account[2] Sandbox containerGet started quickly with just one container-based sandbox host.[3] Sandbox virtual machineUse a virtual machine (VM) as a sandbox host[4] Helm chartLearn how to install helm charts with Instruqt.[5] KubernetesLearn how to build Kubernetes-based tracks with this template[6] Multi-node Kubernetes clusterSetup a Kubernetes cluster on multiple sandbox hosts[7] VSCode & TypeScriptEdit and test TypeScript applications in VSCodePlease select your template: 2↳ Instruqt CLI creates the single host track.
Now add a
g1-small
virtual machine as the second host.🌐 Web UI
💻 Instruqt CLI
Continuing from the Track dashboard page.
- 1.In the Sandbox section, click Edit.
- 2.Click + Add a host.
- 3.Pick the Virtual machine host type.
- 4.In the Hostname field, enter your name for this virtual machine—for example,
avirtualmachine
. - 5.Pick the Choose your own image type.
- 6.In the GCP compute image field, enter
centos-7
. - 7.In the Machine type list, select
Small (1 vCPUs, 4GB)
. - 8.Click Show optional settings.
- 9.In the Shell field, enter
/bin/bash
as the shell for your container. - 10.Click Save host, followed by Back to track to return to the Track dashboard page.
- 11.Click on a challenge, followed by Tabs.
- 12.Click Add new tab to add a tab for the added host.
- 13.Select the Terminal type.
- 14.In the Tab name field, enter your title for this tab.
- 15.In the Select your host list, select the name of the host you added.
- 16.Click Save, followed by Back to track to return to the Track dashboard page.
- 17.Click Play track to play your multi-host track.
- 18.Click Start when your environment is created. ↳ You have two tabs now, each for a different host, as you can see by their prompts.
- 1.Move over to your code editor and open the
config.yml
file. - 2.Add this section to the
containers
property:virtualmachines:- name: avirtualmachineimage: centos-7shell: /bin/bashmachine_type: g1-small - 3.Save the file and now open the
assignment.md
file from the challenge directory. - 4.Add this section to the
tabs
property:- title: YOUR_SHELL_NAMEtype: terminalhostname: YOUR_HOST_NAME - 5.Save the file and move back to Instruqt CLI.
- 6.Deploy your multi-host track to the Instruqt platform:instruqt track push
- 7.Open your browser and go to play.instruqt.com. ↳ Instruqt now shows the created track in your content.
- 8.Click your multi-host track, followed by Start track.
- 9.Click Start when your environment is created. ↳ You have two tabs now, each for a different host, as you can see by their prompts.
Instruqt sorts the hosts in a track in alphanumeric order and executes the track setup scripts sequentially. So in the track you have made so far, the virtual machine configuration script is executed first because the name,
avirtualmachine
, comes before the name container
.To run track setup scripts parallel on both hosts, you have to create a track setup for the virtual machine that runs a script on the container through SSH:
🌐 Web UI
💻 Instruqt CLI
Continuing from the Track dashboard page.
- 1.In the Sandbox section, click Scripts.
- 2.Click setup under container. ↳ An editor window for the track setup script opens.
- 3.Add the following code into the editor window to enable the container to run SSH scripts:#!/bin/bashcat <<EOF >> "$HOME/.ssh/config"Host *StrictHostKeyChecking noUserKnownHostsFile /dev/nullEOFapt-get update && apt-get install -y openssh-client ncat vimcat >> $HOME/.bashrc <<EOFexport FOO=barexport BAZ=quxEOF
- 4.Click setup under avirtualmachine. ↳ An editor window for the track setup script opens.
- 5.Add the following code into the editor window:#!/bin/bashyum install -y nmap-ncatcat <<EOF >> "$HOME/.ssh/config"Host *StrictHostKeyChecking noUserKnownHostsFile /dev/nullEOFwhile ! ssh container true; doecho "Waiting for container SSH to be available"sleep 1donessh container "echo 'hello from the avirtualmachine track setup' >> /root/from-vm.txt"↳ This code enables SSH, and in line 16, it runs the
echo
command on the other hostcontainer
through SSH. - 6.Click Save all, followed by Back to track.
- 7.Click Play track, followed by Start when Instruqt has created your environment. ↳ Your track play shows two terminals, one for the container and one for the virtual machine. The terminal for the container should be active. If not, click the container tab to activate the container terminal.
- 8.Enter the
ls
command to show the directory content. ↳ The filefrom-vm.txt
is listed. The virtual machine track setup script created this file in the container. This shows that the virtual machine track setup has run theecho
command on the container.
- 1.Head over to Instruqt CLI and enter the following command to create the
track_script
directory:md track_scripts - 2.Move over to your code editor and open a new file. This file will contain the track setup script for the container host.
- 3.Add the following code into the container track setup script file to enable the container to run SSH scripts:#!/bin/bashcat <<EOF >> "$HOME/.ssh/config"Host *StrictHostKeyChecking noUserKnownHostsFile /dev/nullEOFapt-get update && apt-get install -y openssh-client ncat vimcat >> $HOME/.bashrc <<EOFexport FOO=barexport BAZ=quxEOF
- 4.Save the file as
setup-container
in thetrack_scripts
directory. - 5.Open another new file. This file will contain the track setup script for the virtual machine host.
- 6.Add the following code into the virtual machine track setup script file:#!/bin/bashyum install -y nmap-ncatcat <<EOF >> "$HOME/.ssh/config"Host *StrictHostKeyChecking noUserKnownHostsFile /dev/nullEOFwhile ! ssh container true; doecho "Waiting for container SSH to be available"sleep 1donessh container "echo 'hello from the avirtualmachine track setup' >> /root/from-vm.txt"↳ This code enables SSH, and in line 16, it runs the
echo
command on the other hostcontainer
through SSH. - 7.Save the file as
setup-avirtualmachine
in thetrack_scripts
directory. - 8.Move back to Instruqt CLI and deploy your multi-host track to the Instruqt platform:
- 9.instruqt track push
- 10.Open your browser and go to play.instruqt.com. ↳ Instruqt now shows the created track in your content.
- 11.Click your multi-host track, followed by Start track.
- 12.Click Start when Instruqt has created your environment. ↳ Your track play shows two terminals, one for the container and one for the virtual machine. The terminal for the container should be active. If not, click the container tab to activate the container terminal.
- 13.Enter the
ls
command to show the directory content. ↳ The filefrom-vm.txt
is listed. The virtual machine track setup script created this file in the container. This shows that the virtual machine track setup has run theecho
command on the container.
Nice! You have tracks on a string.
Last modified 4mo ago