Triton CLI Advanced Tutorial

Created by Olaf van der Graaf at 06-12-2017 11:05:35 +0100

In this advanced Triton CLI Tutorial we will learn some more in-depth functionalities of the Triton CLI. If you wish to go through the Triton CLI Basic Tutorial first, you can do that here.

Note: every line that has a '~#' at the start is a command that you need to execute in Linux.

Resizing a container

One of the many advantages of containers is that they can do a live package resize. Your memory and disk storage can be upgraded or downgraded whenever you please without rebooting the container. You can learn more concerning packages and their pricing here. To get a list of all packages you can choose, execute the following command:

LIST ALL POSSIBLE IMAGES 
~# triton packages list -o shortid,name,memory,swap,disk,description

Resizing to another package can be done with the following command:

Tip: the '-w' tag tells the command to wait for the completion of the resize. If you do not wish to wait and instead continue doing other tasks, simply remove the '-w' tag.
RESIZING YOUR CONTAINER 
~# triton instance -w resize [CONTAINER NAME] [NEW PACKAGE] 
Resizing instance [CONTAINER] to [PACKAGE] 
Resized instance [CONTAINER] to [PACKAGE]

Renaming
Container names be changed to your liking, but must start with a letter or a number and can only consist of:

  • numbers and letters
  • a dash ( - )
  • an underscore( _ )
  • a dot ( . )

Changing you container name can be done with the following command:

CHANGING CONTAINER NAME 
~# triton instance rename [CURRENT CONTAINER NAME] [NEW CONTAINER NAME] 
Renaming instance [CURRENT CONTAINER NAME] to "[NEW CONTAINER NAME]" 
Renamed instance [CURRENT CONTAINER NAME] to "[NEW CONTAINER NAME]"

Audit

It is possible to view the history of all resizes, reboots, snapshot creations, snapshot deletions, stops and starts of a container by executing the following command:

VIEW HISTORY OF ACTIONS WITH AUDIT
~# triton instance audit [CONTAINER NAME]

...
37f408cb  2018-08-10T13:09:43.711Z  resize             yes
37f408cb  2018-08-10T13:10:14.630Z  reboot             yes
37f408cb  2018-08-10T13:10:38.878Z  stop               yes
...

Snapshots

Snapshots are 'fail-safes' for when a certain container stops working, crashes or has other operational problems. They can be used to rollback a container to the snapshot's state, while preserving the container's state at the time of creation in the storage of the container. This means that the maximum amount of storage a Snapshot can take up is equal to the amount of storage your container had at the time of creating the snapshot. Snapshots should not be used as backups and should be regularly checked and updated. When left unattended, they can take up a large portion of your container's storage. Here follows a list of all the Snapshot functionalities:

- Snapshots creation:

Note: creating a snapshot with a name that already exists on that container will result in the snapshot creation failing.

Tip: 
- remove the -w tag if you do not wish to wait for the completion of the snapshot
- if you do not want to give a custom name, remove the --name tag and a name will be generated for you
CREATING A SNAPSHOT
~# triton instance snapshot create -w --name=[SNAPSHOT NAME] [CONTAINER NAME] 
Creating snapshot "[SNAPSHOT NAME]" of instance [CONTAINER NAME]
Created snapshot "[SNAPSHOT NAME]" in 6s

- Snapshots information can be viewed with the following command:

DELETING A SNAPSHOT
~# triton instance snapshot delete -w [CONTAINER NAME] [SNAPSHOT NAME]
Delete snapshot "[SNAPSHOT NAME]"? [y/n] [TYPE y]
Deleting snapshot "[SNAPSHOT NAME]" of instance "[CONTAINER NAME]"
Deleted snapshot "[SNAPSHOT NAME]" in 10s

- Viewing Snapshot information:

VIEWING INFORMATION OF A SNAPSHOT
~# triton instance snapshot get [CONTAINER NAME] [SNAPSHOT NAME] 
{
    "name": "20180810T142730Z",
    "state": "created",
    "created": "2018-08-10T14:27:34.000Z",
    "updated": "2018-08-10T14:27:34.000Z"
}

- Listing all snapshots of a container:

VIEWING INFORMATION OF A SNAPSHOT
~# triton instance snapshot list [CONTAINER NAME]
NAME   STATE    CREATED
snap1  created  2018-08-10T14:19:52.000Z
snap2  created  2018-08-10T14:19:53.000Z
snap3  created  2018-08-10T14:19:54.000Z
snap4  created  2018-08-10T14:19:55.000Z

Tags

Our GUI on www.cloudcontainers.net has the labels functionality, which can describe your container for ease of use. Triton CLI has tags, which are very similar to labels. Tags are like variables, they have a specific name, and a string as a stored value. Here are the Triton CLI tag functionalities:

- list all tags of a container:

~# triton instance tag list [CONTAINER NAME]

-  set the value of a new/already existing tag:

~# triton instance tag set [CONTAINER NAME] [TAG NAME]=[TAG VALUE]

EXAMPLE:
~# triton instance tag set test_container purpose=testing
{
   "purpose": "testing"
}

- get the value of a tag:

~# triton instance tag get [CONTAINER NAME] [TAG NAME]

- delete a tag:

~# triton instance tag delete [CONTAINER NAME] [TAG NAME]

- replace all tags with a single tag:

~# triton instance tag replace-all [CONTAINER NAME] [TAG NAME]=[TAG VALUE]

Want to protect your container from deletion? Use deletion-protection

Enabling deletion-protection is simple and will prevent you from accidentally deleting a container. It can be done with the following command:

ENABLING DELETION-PROTECTION 
~# triton instance enable-deletion-protection [CONTAINER NAME] 
Enabling deletion protection for instance "[CONTAINER NAME]"

When the command; 'triton instance delete [CONTAINER NAME]' is executed, the following will happen:

DELETING CONTAINER WITH DELETION-PROTECTION 
~# triton instance delete [CONTAINER NAME WITH DELETION-PROTECTION ENABLED] 
error: Instance has "deletion_protection" enabled, preventing deletion 
triton instance delete: error: command failure

Logging in(ssh):

If you want to view information relating to your container, you first have to SSH into your container:

Tip: if the command takes a long time and returns: "ssh: connect to host [IP ADDRESS] port [PORT]: Connection timed out", you may want to check if the container/instance is running
SSH INTO CONTAINER 
~# triton instance ssh root@[CONTAINER NAME] -i ~/.ssh/[PATH TO SSH KEY] 
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.3.0 x86_64)

  * Documentation:  https://help.ubuntu.com 
  * Management:     https://landscape.canonical.com
  * Support:        https://ubuntu.com/advantage
Viewing live information:

Then we will view disk space usage and live system information:

DISK SPACE USAGE 
~# df -h 
Filesystem      Size  Used Avail Use% Mounted on 
/dev/zfsds0     3.5G  496M  3.0G  15% / 
/dev/zfsds0     3.5G  496M  3.0G  15% /checkpoints/indestructible  
devtmpfs        256M   15M  242M   6% /dev 
tmpfs           256M   15M  242M   6% /dev/shm 
tmpfs           256M   15M  242M   6% /run 
tmpfs           5.0M  4.0K  5.0M   1% /run/lock 
tmpfs           256M   15M  242M   6% /sys/fs/cgroup 
cgroup          256M   15M  242M   6% /sys/fs/cgroup/systemd 
/native/usr     433M  374M   59M  87% /native/usr

The 'top' command gives you all sorts of information concerning the CPU, Memory and active tasks:

LIVE SYSTEM INFORMATION: 
~# top 
top - 11:40:05 up  1:03,  1 user,  load average: 0.00, 0.00, 0.00 
Tasks:  14 total,   4 running,  10 sleeping,   0 stopped,   0 zombie 
%Cpu(s):  3.0 us,  5.9 sy,  0.0 ni, 90.9 id,  0.0 wa,  0.2 hi,  0.0 si,  0.0 st 
KiB Mem :   262144 total,   244020 free,    18124 used,        0 buff/cache 
KiB Swap:   262144 total,   262144 free,        0 used.   244020 avail Mem   

 PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND    
   1 root      32   0   40528   5892      0 R  13.3  2.2   0:00.90 systemd 
6962 root      50   0   33212   3616      0 R   4.3  1.4   0:00.25 systemd-journal 
6876 16        29   0    3884   2692      0 S   0.0  1.0   0:00.00 ipmgmtd 
8817 root      21   0    7100   2584      0 S   0.0  1.0   0:00.00 ifup 
8825 root      49   0    7200   2708      0 S   0.0  1.0   0:00.00 upstart 
8821 root      45   0    7064   2536      0 S   0.0  1.0   0:00.00 run-parts 
8820 root      42   0    7200   2572      0 S   0.0  1.0   0:00.00 dash 
8827 root      51   0   26012   3304      0 S   0.0  1.3   0:00.00 systemctl 
8672 root       1   0   40780   3796      0 R   0.0  1.4   0:00.16 top 
8793 root       1   0   49560   3412      0 S   0.0  1.3   0:00.00 su 
8659 root       1   0   23540   4972      0 S   0.0  1.9   0:00.04 bash 
8796 root       1   0   27776   3524      0 R   0.0  1.3   0:00.00 systemctl 
7062 message+   1   0   45796   4136      0 S   0.0  1.6   0:00.02 dbus-daemon 
8650 root       1   0   93388   5940      0 S   0.0  2.3   0:00.03 sshd

to exit the 'top' screen, simply press q.


Getting tired of constantly inserting passwords? Use an ssh-agent

Your SSH keys could require a password when logging into a container, or when retrieving information relating to your triton account. An ssh-agent takes care of using the ssh key and passwords, so you don't have to. With each new session, the commands below have to be repeated, because the  ssh-agent closes when the session ends:

Tip: you can keep adding ssh keys to the ssh agent with the 'ssh-add' command.
 START THE SSH AGENT 
~# eval $(ssh-agent) Agent pin [PIN]   

ADD THE SSH KEY TO THE SSH-AGENT 
~# ssh-add ~/.ssh/[SSH-KEY] 
Enter passphrase for /root/.ssh/[SSH-KEY]: [INSERT KEY PASSPHRASE] 
Identity added: /root/.ssh/[SSH-KEY]: (/root/.ssh/[SSH-KEY])

Comments

Comments are turned off.