Links
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.

Track set up scripts execution order

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.

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.

Step 1: Create a track with a single host

🌐 Web UI
💻 Instruqt CLI
  1. 1.
    Open your browser and go to play.instruqt.com. ↳ Instruqt shows your content.
  2. 2.
    Click Create track on the Content page. Select Use template from the dropdown. ↳ The Instruqt templates page opens.
  3. 3.
    Select the Sandbox container template. ↳ The Track info pop-up opens.
  4. 4.
    In the Track title field, enter your title.
  5. 5.
    In the Track slug field, modify the slug if you want to.
  6. 6.
    Click Create. ↳ Instruqt creates the single host track and shows the Track dashboard page.
  1. 1.
    Type the following command to create a track:
    instruqt track create
  2. 2.
    Enter the track title:
    ==> Track title: TRACK_TITLE
  3. 3.
    Enter option 2 to select From a template:
    ==> Start with an empty track or use a template:
    [1] From scratch
    For full flexibility, start with an empty track
    [2] From a template
    To get started quickly, start from one of our templates
    Please select your method: 2
  4. 4.
    Enter the number of the template you want to use:
    ==> Choose a template:
    [1] AWS Cloud Account
    Learn how to build tracks with an AWS account
    [2] Sandbox container
    Get started quickly with just one container-based sandbox host.
    [3] Sandbox virtual machine
    Use a virtual machine (VM) as a sandbox host
    [4] Helm chart
    Learn how to install helm charts with Instruqt.
    [5] Kubernetes
    Learn how to build Kubernetes-based tracks with this template
    [6] Multi-node Kubernetes cluster
    Setup a Kubernetes cluster on multiple sandbox hosts
    [7] VSCode & TypeScript
    Edit and test TypeScript applications in VSCode
    Please select your template: 2
    ↳ Instruqt CLI creates the single host track.

Step 2: Add a host

Now add a g1-small virtual machine as the second host.
🌐 Web UI
💻 Instruqt CLI
Continuing from the Track dashboard page.
  1. 1.
    In the Sandbox section, click Edit.
  2. 2.
    Click + Add a host.
  3. 3.
    Pick the Virtual machine host type.
  4. 4.
    In the Hostname field, enter your name for this virtual machine—for example, avirtualmachine.
  5. 5.
    Pick the Choose your own image type.
  6. 6.
    In the GCP compute image field, enter centos-7.
  7. 7.
    In the Machine type list, select Small (1 vCPUs, 4GB).
  8. 8.
    Click Show optional settings.
  9. 9.
    In the Shell field, enter /bin/bash as the shell for your container.
  10. 10.
    Click Save host, followed by Back to track to return to the Track dashboard page.
  11. 11.
    Click on a challenge, followed by Tabs.
  12. 12.
    Click Add new tab to add a tab for the added host.
  13. 13.
    Select the Terminal type.
  14. 14.
    In the Tab name field, enter your title for this tab.
  15. 15.
    In the Select your host list, select the name of the host you added.
  16. 16.
    Click Save, followed by Back to track to return to the Track dashboard page.
  17. 17.
    Click Play track to play your multi-host track.
  18. 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. 1.
    Move over to your code editor and open the config.yml file.
  2. 2.
    Add this section to the containers property:
    virtualmachines:
    - name: avirtualmachine
    image: centos-7
    shell: /bin/bash
    machine_type: g1-small
  3. 3.
    Save the file and now open the assignment.md file from the challenge directory.
  4. 4.
    Add this section to the tabs property:
    - title: YOUR_SHELL_NAME
    type: terminal
    hostname: YOUR_HOST_NAME
  5. 5.
    Save the file and move back to Instruqt CLI.
  6. 6.
    Deploy your multi-host track to the Instruqt platform:
    instruqt track push
  7. 7.
    Open your browser and go to play.instruqt.com. ↳ Instruqt now shows the created track in your content.
  8. 8.
    Click your multi-host track, followed by Start track.
  9. 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.

Bootstrap a multi-host track

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. 1.
    In the Sandbox section, click Scripts.
  2. 2.
    Click setup under container. ↳ An editor window for the track setup script opens.
  3. 3.
    Add the following code into the editor window to enable the container to run SSH scripts:
    #!/bin/bash
    cat <<EOF >> "$HOME/.ssh/config"
    Host *
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null
    EOF
    apt-get update && apt-get install -y openssh-client ncat vim
    cat >> $HOME/.bashrc <<EOF
    export FOO=bar
    export BAZ=qux
    EOF
  4. 4.
    Click setup under avirtualmachine. ↳ An editor window for the track setup script opens.
  5. 5.
    Add the following code into the editor window:
    #!/bin/bash
    yum install -y nmap-ncat
    cat <<EOF >> "$HOME/.ssh/config"
    Host *
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null
    EOF
    while ! ssh container true; do
    echo "Waiting for container SSH to be available"
    sleep 1
    done
    ssh 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 host container through SSH.
  6. 6.
    Click Save all, followed by Back to track.
  7. 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. 8.
    Enter the ls command to show the directory content. ↳ The file from-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 the echo command on the container.
  1. 1.
    Head over to Instruqt CLI and enter the following command to create the track_script directory:
    md track_scripts
  2. 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. 3.
    Add the following code into the container track setup script file to enable the container to run SSH scripts:
    #!/bin/bash
    cat <<EOF >> "$HOME/.ssh/config"
    Host *
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null
    EOF
    apt-get update && apt-get install -y openssh-client ncat vim
    cat >> $HOME/.bashrc <<EOF
    export FOO=bar
    export BAZ=qux
    EOF
  4. 4.
    Save the file as setup-container in the track_scripts directory.
  5. 5.
    Open another new file. This file will contain the track setup script for the virtual machine host.
  6. 6.
    Add the following code into the virtual machine track setup script file:
    #!/bin/bash
    yum install -y nmap-ncat
    cat <<EOF >> "$HOME/.ssh/config"
    Host *
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null
    EOF
    while ! ssh container true; do
    echo "Waiting for container SSH to be available"
    sleep 1
    done
    ssh 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 host container through SSH.
  7. 7.
    Save the file as setup-avirtualmachine in the track_scripts directory.
  8. 8.
    Move back to Instruqt CLI and deploy your multi-host track to the Instruqt platform:
  9. 9.
    instruqt track push
  10. 10.
    Open your browser and go to play.instruqt.com. ↳ Instruqt now shows the created track in your content.
  11. 11.
    Click your multi-host track, followed by Start track.
  12. 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. 13.
    Enter the ls command to show the directory content. ↳ The file from-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 the echo command on the container.
Nice! You have tracks on a string.