Triton CLI tool
Triton CLI tool
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
Provision and manage networks
Manage your account
In this page, you will learn how to install triton
. You can learn more about CloudAPI methods and resources in our additional reference documentation.
Need a visual reference? Watch the screencast which covers how to install the Triton CLI tool and manage infrastructure in Triton data centers.
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.
NOTE: on some platforms and for some installations of Node.js, you may receive an error when using sudo
. Remove it from the command to install triton
:
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.
On Windows, this step is mandatory.
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
.
If you've installed smartdc
, you must set up SDC_*
environment variables.
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:
You can also configure bash completions with this 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.
In our quick start example, we ran triton instance create -w --name=server-1 ubuntu-14.04 g4-highcpu-1G
. That command has three parameters:
We gave our instance a name using
--name server-1
We used
-w
to wait the instance to be createdWe used
ubuntu-14.04
as our imageWe set
g4-highcpu-1G
as our package
Let's look at each of those in detail to see how you can set the options that will work best for your needs.
Names for instances can be up to 189 characters and include any alphanumeric character plus _
, -
, and .
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.
Note: Want to build a custom application using our infrastructure containers? Learn how to create a custom ifrastructure image.
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.
This screencast covers how to install the Triton CLI tool and use CloudAPI to manage infrastructure in Triton data centers.
If you skipped ahead to the video, you can go back and review the installation process for step-by-step instructions.
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.
Last updated