Triton CLI Advanced Tutorial
Created by Admin at 26-05-2020 10:23:01 +0200In 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
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 package list or with filtering: ~# triton package list [FILTERS]
Resizing to another package can be done with the following command:
RESIZING YOUR CONTAINER: ~# triton instance -w resize [CONTAINER NAME] [NEW PACKAGE] Option -w let's you wait until the command is completed and update you on its status.
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]
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]
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.
CREATING A SNAPSHOT: ~# triton instance snapshot create -w --name=[SNAPSHOT NAME] [CONTAINER NAME] Option -w let's you wait until the command is completed and update you on its status. Tag --name let's you name the snapshot, not passing the --name tage will auto generate a snapshot name.
Snapshot deletion
DELETING A SNAPSHOT: ~# triton instance snapshot delete -w [CONTAINER NAME] [SNAPSHOT NAME] Option -w let's you wait until the command is completed and update you on its status. You'll be asked for confirmation: y
Snapshot information
VIEWING INFORMATION OF A SNAPSHOT: ~# triton instance snapshot get [CONTAINER NAME] [SNAPSHOT NAME]
Listing container's snapshots
VIEWING INFORMATION OF A SNAPSHOT: ~# triton instance snapshot list [CONTAINER NAME]
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 CONTAINER'S TAGS: ~# triton instance tag list [CONTAINER NAME] SET TAG'S VALUE (new/edit): ~# triton instance tag set [CONTAINER NAME] [TAGNAME]=[TAG VALUE] GET TAG'S VALUE: ~# triton instance tag get [CONTAINER NAME] [TAG NAME] DELETE TAG: ~# triton instance tag delete [CONTAINER NAME] [TAG NAME] REPLACE ALL TAGES 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] Triton instance delete ran on a container with deletion protection will result in the following error: 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:
Note: if the command fails because the connection timed out, you may want to check if the container is running.
SSH INTO CONTAINER: ~# triton instance ssh root@[CONTAINER NAME] -i ~/.ssh/[PATH TO SSH KEY]
Viewing live information:
Then we will view disk space usage and live system information:
VIEW DISK SPACE USAGE: ~# df -h Filesystem VIEW CPU-, MEMORY- AND ACTIVE TASKS INFORMATION: ~# top 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]
Comments are turned off.