The Triton command line tool (triton) uses CloudAPI to manage infrastructure in Triton data centers. Many of the tasks that you can perform through the portal are also possible with Triton CLI, including:
Provision compute instances, including infrastructure containers and hardware virtual machines
Manage compute instances, including Docker containers, infrastructure containers and hardware virtual machines
To install Triton CLI and CloudAPI tools, you must first install Node.js. You can find the latest version of Node.js for your operating system and architecture at nodejs.org.
You can install triton using Node Package Manager (npm). In the following example, the npm install command sets a global flag (-g) that makes npm modules accessible to all users. This flag is mandatory when installing triton on Windows.
We recommend setting up environment variables to populate an initial environment-based profile. These environment variables are useful for interacting with CloudAPI as well as other tools such as Packer and Terraform.
Environment variables live in your bash profile, .bash_profile. On macOS, this file should be in your home directory.
From the terminal, edit your bash profile:
Add the following content to your profile, modified to include the correct Triton username and SSH key if not id_rsa.pub:
Previous versions of triton required environment variables that began with SDC_*, i.e. SDC_URL and SDC_ACCOUNT. As of January 2018, the SDC environment variables are still supported by triton.
Triton CLI uses "profiles" to store access information. Profiles contain the data center CloudAPI URL, your login name, and SSH key fingerprint. You can create a profile for each data center or profiles for different users. Profiles make it easy to connect to different data centers, or connect to the same data center as different users.
The triton profile create command prompts you to answer a series of questions to configure your profile. The following example shows the steps for Triton user jill.
Select a CloudAPI endpoint URL from any of our global data centers, or use a Triton-powered data center of your own (remember: it's open source).
To test the installation and configuration, let's use triton info:
The triton info output above shows that myuser's account already has two instances running.
You can view all configured profiles with the triton profiles command:
Next let's make a profile for each data center. To do this we will use triton commands to make a copy of the us-sw-1 profile for each of the data center urls. Copy this snippet below to add the new profiles (in this case, based on a profile named 'env'):
Run triton profiles again to check to see that it worked. We should have a new profile for each data center listed in triton datacenters:
You can change the default profile with the triton profile set command:
With triton installed and configured, we can jump right into provisioning instances. Here's an example of provisioning an infrastructure container running Ubuntu. Think of infrastructure containers like virtual machines, only faster and more efficient.
Let's run triton instance create and we'll talk about the pieces after:
Now that we have an instance, we can run triton ssh to connect to it. This is an awesome addition to our tools because it means that we don't need to copy SSH keys or even lookup the IP address of the instance.
Finding our Ubuntu image is pretty easy. We use triton images to list the images and add name=~ubuntu to do a substring search for Ubuntu. It's sorted by published date so usually we'll pick the most recent. Today we'll choose 14.04 because it has wider support.
There are 4 types of packages available for containers: compute optimized (g4-highcpu-<size>), general purpose (g4-general-<size>), memory optimized (g4-highram-<size>), and storage optimized (g4-fastdisk-<size> and g4-bigdisk-<size>).
The package types for HVMs have a similar name structure: compute optimized (k4-highcpu-<kvm|bhyve>-<size>), general purpose (k4-general-<kvm|bhyve>-<size>), memory optimized (k4-highram-<kvm|bhyve>-<size>), and storage optimized (k4-fastdisk-<kvm|bhyve>-<size> and k4-bigdisk-<kvm|bhyve>-<size>).
We'll use triton package to search for a package with 1 gigabyte of RAM. We'll pick the g4-highcpu-1G.
At this time, there is no way to use triton to fetch the pricing details for the different packages. To find out those costs, you can visit our public pricing page.
Our quick start example didn't include one of the most useful options for automating infrastructure on Triton: specifying a script for containers to run at startup.
The command below sets up a 16GB CentOS infrastructure container, and installs Couchbase. The --script file installs Couchbase, and the triton ssh runs cat /root/couchbase.txt to show the address of the Couchbase dashboard.
Infrastructure management isn't just about creating instances. Triton CLI offers some of its biggest improvements in this space. Below are some examples of triton commands.
By default the triton tool does not wait for tasks to finish. This is great because it means that your commands return control back to you very quickly. However sometimes you'll need to wait for a task to complete before you do the next one. When this happens you can wait by using either the --wait or -w flags, or the triton instance wait command. In the example above we used --wait so that the instance would be ready by the time the triton ssh command ran.
Use triton instance get -j to view your instance's details as a JSON blob. To parse fields out of the blob, I recommend using json although there are many other great tools out there.
Up above you can see that the user-script that we ran is part of the metadata.
You can pull out individual values by piping the output to json KEYNAME. For example you could get the IP address of an instance like this:
Let's wrap up with this container. We'll delete it using the triton instance delete command:
For something a bit more dangerous, you can delete all your instances using this command:
Be careful. Using the triton instance delete command removes all of your instances regardless of whether they running or stopped.
If you are familiar with using docker, note that this is equivalent to using docker rm -f $(docker ps -aq) to force the deletion of all your containers. If you want to remove all of your instances, using triton instance delete might be faster since it deletes the instances in parallel.
In addition to CloudAPI and the Triton CLI tool, you can also create and manage bare metal Docker containers on Triton using the Triton Elastic Docker Host and Triton-Docker CLI tools. The two APIs work in parallel, though the Triton-Docker CLI can only create and manage bare metal Docker containers on Triton. CloudAPI and the Triton CLI tool can manage almost every aspect of Docker containers with the exception of provisioning bare metal Docker containers on Triton.
$ triton profile create
A profile name. A short string to identify a CloudAPI endpoint to the `triton` CLI.
name: us-central-1
The CloudAPI endpoint URL.
url: https://us-central-1.api.mnx.io
Your account login name.
account: myuser
The fingerprint of the SSH key you have registered for your account. You may enter a local path to a public or private key to have the fingerprint calculated for you.
keyId: ~/.ssh/<ssh key name>.id_rsa
Fingerprint: 2e:c9:f9:89:ec:78:04:5d:ff:fd:74:88:f3:a5:18:a5
Saved profile "us-central-1"
$ triton ssh server-1
Welcome to Ubuntu 14.04 (GNU/Linux 3.19.0 x86_64)
* Documentation: https://help.ubuntu.com/
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
__ . .
_| |_ | .-. . . .-. :--. |-
|_ _| ;| || |(.-' | | |
|__| `--' `-' `;-| `-' ' ' `-'
/ ; Instance (Ubuntu 14.04 20151105)
`-' https://docs.joyent.com/images/container-native-linux
root@8367b339-799b-cff5-a662-a211e1927797:~#
$ triton images name=~ubuntu type=lx-dataset
SHORTID NAME VERSION FLAGS OS TYPE PUBDATE
...
c8d68a9e ubuntu-14.04 20150819 P linux lx-dataset 2015-08-19
52be84d0 ubuntu-14.04 20151005 P linux lx-dataset 2015-10-05
ffe82a0a ubuntu-15.04 20151105 P linux lx-dataset 2015-11-05
$ triton packages memory=1024
SHORTID NAME MEMORY SWAP DISK VCPUS
14af2214 g4-highcpu-1G 1G 4G 25G -